Skip to content

Commit

Permalink
move test, add tests for currency aggregates null values
Browse files Browse the repository at this point in the history
  • Loading branch information
soad003 committed Jan 31, 2024
1 parent 18c098f commit 4b0a33a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.graphsense.account.eth
package org.graphsense.account

import org.graphsense.account.contract.tokens.Erc20Decoder
import org.graphsense.account.Implicits._
Expand Down
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
)

}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.graphsense.account.eth
package org.graphsense.common
import org.graphsense.TestBase
import org.graphsense.Util._
import org.apache.spark.SparkException
Expand Down

0 comments on commit 4b0a33a

Please sign in to comment.