-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move test, add tests for currency aggregates null values
- Loading branch information
Showing
3 changed files
with
70 additions
and
2 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...raphsense/account/eth/TokenDecoding.scala → ...raphsense/account/TokenDecodingTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/test/scala/org/graphsense/common/TransformationHelpersTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package org.graphsense.common | ||
import org.graphsense.TestBase | ||
import org.graphsense.TransformHelpers | ||
import org.graphsense.account.models.Currency | ||
import org.apache.spark.sql.types.DecimalType | ||
import org.apache.spark.sql.functions.expr | ||
|
||
case class blub(name: String, value: Currency) | ||
|
||
class TransfromHelpersTest extends TestBase { | ||
|
||
test("zeroValueIfNull helper tests") { | ||
import spark.implicits._ | ||
val data = Seq( | ||
("Java", Currency(1, Seq(1, 2))), | ||
("Java", Currency(1, null)), | ||
("Java", Currency(null, null)), | ||
( | ||
"Java", | ||
Currency(null, Seq(1, 2)) | ||
) | ||
// ( | ||
// "Java", | ||
// Currency(null, Seq(1, null)) | ||
// ) | ||
) | ||
val rdd = spark.sparkContext.parallelize(data) | ||
val df = rdd.toDF("name", "value") | ||
|
||
df.transform( | ||
TransformHelpers.zeroCurrencyValueIfNull( | ||
"value", | ||
2, | ||
castValueTo = DecimalType(38, 0) | ||
) | ||
) | ||
|
||
assert( | ||
df.filter( | ||
$"value.value".isNull || $"value.fiatValues".isNull || expr( | ||
"exists(value.fiatValues, x -> x is null)" | ||
) | ||
).count() == 3 | ||
) | ||
|
||
val dfnew = df | ||
.transform( | ||
TransformHelpers.zeroCurrencyValueIfNullSafe( | ||
"value", | ||
2, | ||
castValueTo = DecimalType(38, 0) | ||
) | ||
) | ||
.as[blub] | ||
|
||
assert( | ||
dfnew | ||
.filter( | ||
$"value.value".isNull || $"value.fiatValues".isNull || expr( | ||
"exists(value.fiatValues, x -> x is null)" | ||
) | ||
) | ||
.count() == 0 | ||
) | ||
|
||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...org/graphsense/account/eth/TxIdTest.scala → ...cala/org/graphsense/common/TxIdTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters