Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion online/src/main/scala/ai/chronon/online/stats/PivotUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,16 @@ object PivotUtils {
var seriesIndex = 0
while (seriesIndex < seriesLength) {
val list = lists(seriesIndex)
val value: T = if (list == null) null.asInstanceOf[T] else list.get(pctIndex)
val value: T = if (list == null) {
null.asInstanceOf[T]
} else {
val v = list.get(pctIndex)
if (v == null || (v.isInstanceOf[Double] && v.asInstanceOf[Double].isNaN)) {
Constants.magicNullDouble.asInstanceOf[T]
} else {
v
}
}
row.add(value)
seriesIndex += 1
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,29 @@ class PivotUtilsTest extends AnyFlatSpec with Matchers {
expectedStringLengthPercentiles.asScala.map(_.asScala.toList)
}

it should "handle null values in percentiles lists" in {
val ts1 = new TileSummary()
ts1.setPercentiles(List[java.lang.Double](1.0, null, 3.0).map(d => if (d == null) null else Double.box(d)).asJava)

val ts2 = new TileSummary()
ts2.setPercentiles(List[java.lang.Double](4.0, 5.0, null).map(d => if (d == null) null else Double.box(d)).asJava)

val result = pivot(Array(
(ts1, 1000L),
(ts2, 2000L)
))

// After pivot, we expect nulls to be replaced with magicNullDouble
val expected = List(
List(1.0, 4.0).asJava,
List(Constants.magicNullDouble, 5.0).asJava,
List(3.0, Constants.magicNullDouble).asJava
).asJava

result.getPercentiles.asScala.map(_.asScala.toList) shouldEqual
expected.asScala.map(_.asScala.toList)
}

"pivot_drift" should "handle empty input" in {
val result = pivot(Array.empty[(TileDrift, Long)])
result.getPercentileDriftSeries shouldBe null
Expand Down