Skip to content
Merged
Changes from 5 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
17 changes: 15 additions & 2 deletions online/src/main/scala/ai/chronon/online/stats/PivotUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object PivotUtils {
while (seriesIndex < seriesLength) {
val list = lists(seriesIndex)
val value: T = if (list == null) {
null.asInstanceOf[T]
Constants.magicNullDouble.asInstanceOf[T]
} else {
val v = list.get(pctIndex)
if (v == null || (v.isInstanceOf[Double] && v.asInstanceOf[Double].isNaN)) {
Expand Down Expand Up @@ -104,6 +104,19 @@ object PivotUtils {

def iterator[T](func: TileSummary => T): Iterator[T] = summaries.iterator.map(func)

def filterPercentiles[T <: AnyRef](lists: Array[JList[T]]): Array[JList[T]] = {
if (lists == null || lists.isEmpty) return null
lists.map { list =>
if (list == null) null
else {
val filtered = new JArrayList[T]()
// Assuming 21 percentiles (0,5,10,...,95,100), indices 1,10,19 correspond to 5%,50%,95%
Seq(1, 10, 19).foreach(i => filtered.add(list.get(i)))
filtered
}
}
}

def longIterator(isSetFunc: TileSummary => Boolean, extract: TileSummary => Long): Iterator[JLong] = {
summaries.iterator.map { summary =>
if (isSetFunc(summary)) {
Expand All @@ -115,7 +128,7 @@ object PivotUtils {
}

new TileSummarySeries()
.setPercentiles(iterator(_.getPercentiles).toArray |> transpose)
.setPercentiles(iterator(_.getPercentiles).toArray |> filterPercentiles |> transpose)
.setHistogram(iterator(_.getHistogram).toArray |> merge)
.setCount(longIterator(_.isSetCount, _.getCount) |> collect)
.setNullCount(longIterator(_.isSetNullCount, _.getNullCount) |> collect)
Expand Down
Loading