Skip to content

Commit 83565ac

Browse files
authored
ESQL: Fix rounding error in BlockBenchmark (#104041)
Round doubles before summing to avoid errors due to wrong checksum.
1 parent c4c2ce8 commit 83565ac

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

benchmarks/src/main/java/org/elasticsearch/benchmark/compute/operator/BlockBenchmark.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ private static long computeBytesRefCheckSum(BytesRefBlock block, int[] traversal
720720
}
721721

722722
private static long computeDoubleCheckSum(DoubleBlock block, int[] traversalOrder) {
723-
double sum = 0;
723+
long sum = 0;
724724

725725
for (int position : traversalOrder) {
726726
if (block.isNull(position)) {
@@ -729,11 +729,12 @@ private static long computeDoubleCheckSum(DoubleBlock block, int[] traversalOrde
729729
int start = block.getFirstValueIndex(position);
730730
int end = start + block.getValueCount(position);
731731
for (int i = start; i < end; i++) {
732-
sum += block.getDouble(i);
732+
// Use an operation that is not affected by rounding errors. Otherwise, the result may depend on the traversalOrder.
733+
sum += (long) block.getDouble(i);
733734
}
734735
}
735736

736-
return (long) sum;
737+
return sum;
737738
}
738739

739740
private static long computeIntCheckSum(IntBlock block, int[] traversalOrder) {

0 commit comments

Comments
 (0)