Skip to content

Commit bfe5b2d

Browse files
authored
ESQL: Fix invariant test in TOP(bytes) (elastic#117049) (elastic#117166)
Fixes a self-test in the code for `TOP(bytes)`, specifically around the merging used for grouping by ordinals.
1 parent bb33952 commit bfe5b2d

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/sort/BytesRefBucketedSort.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public void merge(int bucket, BytesRefBucketedSort other, int otherBucket) {
147147
// The value was never collected.
148148
return;
149149
}
150-
other.checkInvariant(bucket);
150+
other.checkInvariant(otherBucket);
151151
long otherStart = other.startIndex(otherBucket, otherRootIndex);
152152
long otherEnd = other.common.endIndex(otherRootIndex);
153153
// TODO: This can be improved for heapified buckets by making use of the heap structures

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/data/sort/BucketedSortTestCase.java

+46
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,52 @@ public final void testMergeEmptyToEmpty() {
363363
}
364364
}
365365

366+
public final void testMergeOtherBigger() {
367+
try (T sort = build(SortOrder.ASC, 3)) {
368+
var values = threeSortedValues();
369+
370+
collect(sort, values.get(0), 0);
371+
collect(sort, values.get(1), 0);
372+
collect(sort, values.get(2), 0);
373+
374+
try (T other = build(SortOrder.ASC, 3)) {
375+
collect(other, values.get(0), 0);
376+
collect(other, values.get(1), 1);
377+
collect(other, values.get(2), 2);
378+
379+
merge(sort, 0, other, 0);
380+
merge(sort, 0, other, 1);
381+
merge(sort, 0, other, 2);
382+
}
383+
384+
assertBlock(sort, 0, List.of(values.get(0), values.get(0), values.get(1)));
385+
}
386+
}
387+
388+
public final void testMergeThisBigger() {
389+
try (T sort = build(SortOrder.ASC, 3)) {
390+
var values = threeSortedValues();
391+
392+
collect(sort, values.get(0), 0);
393+
collect(sort, values.get(1), 1);
394+
collect(sort, values.get(2), 2);
395+
396+
try (T other = build(SortOrder.ASC, 3)) {
397+
collect(other, values.get(0), 0);
398+
collect(other, values.get(1), 0);
399+
collect(other, values.get(2), 0);
400+
401+
merge(sort, 0, other, 0);
402+
merge(sort, 1, other, 0);
403+
merge(sort, 2, other, 0);
404+
}
405+
406+
assertBlock(sort, 0, List.of(values.get(0), values.get(0), values.get(1)));
407+
assertBlock(sort, 1, List.of(values.get(0), values.get(1), values.get(1)));
408+
assertBlock(sort, 2, values);
409+
}
410+
}
411+
366412
protected void assertBlock(T sort, int groupId, List<V> values) {
367413
var blockFactory = TestBlockFactory.getNonBreakingInstance();
368414

0 commit comments

Comments
 (0)