Skip to content

Commit 0594990

Browse files
committed
fix last test
1 parent 5c4d965 commit 0594990

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/expression/function/scalar/convert/ToAggregateMetricDouble.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ private Block evalBlock(Block block) {
139139
AggregateMetricDoubleBlockBuilder result = context.blockFactory()
140140
.newAggregateMetricDoubleBlockBuilder(positionCount)
141141
) {
142-
CompensatedSum sum = new CompensatedSum();
142+
CompensatedSum compensatedSum = new CompensatedSum();
143143
for (int p = 0; p < positionCount; p++) {
144144
int valueCount = doubleBlock.getValueCount(p);
145145
int start = doubleBlock.getFirstValueIndex(p);
@@ -148,19 +148,21 @@ private Block evalBlock(Block block) {
148148
result.appendNull();
149149
continue;
150150
}
151-
double min = Double.POSITIVE_INFINITY;
152-
double max = Double.NEGATIVE_INFINITY;
153-
for (int i = start; i < end; i++) {
154-
double current = doubleBlock.getDouble(i);
151+
// First iteration of the loop is manual to support having -0.0 as an input consistently
152+
double current = doubleBlock.getDouble(start);
153+
double min = current;
154+
double max = current;
155+
compensatedSum.reset(current, 0);
156+
for (int i = start + 1; i < end; i++) {
157+
current = doubleBlock.getDouble(i);
155158
min = Math.min(min, current);
156159
max = Math.max(max, current);
157-
sum.add(current);
160+
compensatedSum.add(current);
158161
}
159162
result.min().appendDouble(min);
160163
result.max().appendDouble(max);
161-
result.sum().appendDouble(sum.value());
164+
result.sum().appendDouble(compensatedSum.value());
162165
result.count().appendInt(valueCount);
163-
sum.reset(0, 0);
164166
}
165167
return result.build();
166168
}

0 commit comments

Comments
 (0)