Skip to content

Commit bcd0a23

Browse files
committed
Restore the fix for AvgDoubleGroupByFunction
1 parent 162b29d commit bcd0a23

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

core/src/main/java/io/questdb/griffin/engine/functions/groupby/AvgDoubleGroupByFunction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void computeBatch(MapValue mapValue, long ptr, int count, long startRowId
5252
final double batchSum = Vect.sumDoubleAcc(ptr, count, countPtr);
5353
if (!Numbers.isNull(batchSum)) {
5454
final double prevSum = mapValue.getDouble(valueIndex);
55-
if (Numbers.isFinite(prevSum)) {
55+
if (!Double.isNaN(prevSum)) {
5656
mapValue.putDouble(valueIndex, prevSum + batchSum);
5757
} else {
5858
mapValue.putDouble(valueIndex, batchSum);

core/src/test/java/io/questdb/test/griffin/engine/functions/groupby/DoubleGroupByFunctionBatchTest.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ public void tearDown() {
5858
}
5959

6060
// Verify that computeBatch is consistent with computeNext: when the running sum
61-
// overflows to +Infinity, the next finite batch overwrites it (resets the accumulator).
61+
// overflows to +Infinity, it is preserved. AvgDouble's computeNext uses addDouble
62+
// with no inner guard, so Infinity + finite = Infinity naturally.
6263
@Test
63-
public void testAvgDoubleBatchAccumulatedInfinityIsOverwritten() {
64+
public void testAvgDoubleBatchAccumulatedInfinityIsPreserved() {
6465
AvgDoubleGroupByFunction function = new AvgDoubleGroupByFunction(DoubleColumn.newInstance(COLUMN_INDEX));
6566
try (SimpleMapValue value = prepare(function)) {
6667
// Batch 1: running sum = MAX_VALUE (finite)
@@ -71,12 +72,12 @@ public void testAvgDoubleBatchAccumulatedInfinityIsOverwritten() {
7172
ptr = allocateDoubles(Double.MAX_VALUE);
7273
function.computeBatch(value, ptr, 1, 0);
7374

74-
// Batch 3: Infinity is not finite, so the accumulator resets to 1.0
75+
// Batch 3: Infinity is preserved, not overwritten
7576
ptr = allocateDoubles(1.0);
7677
function.computeBatch(value, ptr, 1, 0);
7778

78-
// avg = 1.0 / 3 (count is still 3)
79-
Assert.assertEquals(1.0 / 3.0, function.getDouble(value), 1e-15);
79+
// avg = Infinity / 3 = Infinity
80+
Assert.assertTrue(Double.isInfinite(function.getDouble(value)));
8081
}
8182
}
8283

0 commit comments

Comments
 (0)