Skip to content

Commit

Permalink
fix max, min agregator
Browse files Browse the repository at this point in the history
Signed-off-by: Sandesh Kumar <[email protected]>
  • Loading branch information
sandeshkr419 committed Jan 24, 2025
1 parent e6667f1 commit 0227c40
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -271,20 +271,12 @@ public StarTreeBucketCollector getStarTreeBucketCollector(
MetricStat.MAX.getTypeName(),
valuesSource,
parentCollector,
(bucket) -> maxes = context.bigArrays().grow(maxes, bucket + 1),
// (bucket, metricValue) -> maxes.set(bucket, Math.max(maxes.get(bucket), ))
(bucket, metricValue) -> {
// Retrieve the current bucket value (it could be NaN initially)
double currentMax = maxes.get(bucket);

// Check if the currentMax is NaN or not set, and initialize it with the first metric value
if (Double.isNaN(currentMax)) {
maxes.set(bucket, NumericUtils.sortableLongToDouble(metricValue)); // Set the first value if the bucket was
// uninitialized
} else {
maxes.set(bucket, Math.max(currentMax, NumericUtils.sortableLongToDouble(metricValue))); // Perform the max comparison
}
}
(bucket) -> {
long from = maxes.size();
maxes = context.bigArrays().grow(maxes, bucket + 1);
maxes.fill(from, maxes.size(), Double.NEGATIVE_INFINITY);
},
(bucket, metricValue) -> maxes.set(bucket, Math.max(maxes.get(bucket), (NumericUtils.sortableLongToDouble(metricValue))))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,12 @@ public StarTreeBucketCollector getStarTreeBucketCollector(
MetricStat.MIN.getTypeName(),
valuesSource,
parentCollector,
(bucket) -> mins = context.bigArrays().grow(mins, bucket + 1),
(bucket, metricValue) -> mins.set(bucket, Math.max(mins.get(bucket), NumericUtils.sortableLongToDouble(metricValue)))
(bucket) -> {
long from = mins.size();
mins = context.bigArrays().grow(mins, bucket + 1);
mins.fill(from, mins.size(), Double.POSITIVE_INFINITY);
},
(bucket, metricValue) -> mins.set(bucket, Math.min(mins.get(bucket), NumericUtils.sortableLongToDouble(metricValue)))
);
}
}

0 comments on commit 0227c40

Please sign in to comment.