Skip to content

Commit 855fb8f

Browse files
authored
[ESQL] Make sure we built consistent OrdinalBytesRefBlock in BlockHashRandomizedTests (#115081) (#115269)
1 parent 1d09ec2 commit 855fb8f

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/aggregation/blockhash/BlockHashRandomizedTests.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -475,17 +475,14 @@ public ElementType elementType() {
475475

476476
@Override
477477
public BasicBlockTests.RandomBlock randomBlock(int positionCount, int maxValuesPerPosition, int dups) {
478-
List<Map.Entry<String, Integer>> dictionary = new ArrayList<>();
478+
Map<String, Integer> dictionary = new HashMap<>();
479+
Set<String> keys = dictionary(maxValuesPerPosition);
479480
List<List<Object>> values = new ArrayList<>(positionCount);
480481
try (
481482
IntBlock.Builder ordinals = TestBlockFactory.getNonBreakingInstance()
482483
.newIntBlockBuilder(positionCount * maxValuesPerPosition);
483484
BytesRefVector.Builder bytes = TestBlockFactory.getNonBreakingInstance().newBytesRefVectorBuilder(maxValuesPerPosition);
484485
) {
485-
for (String value : dictionary(maxValuesPerPosition)) {
486-
bytes.appendBytesRef(new BytesRef(value));
487-
dictionary.add(Map.entry(value, dictionary.size()));
488-
}
489486
for (int p = 0; p < positionCount; p++) {
490487
int valueCount = between(1, maxValuesPerPosition);
491488
int dupCount = between(0, dups);
@@ -497,10 +494,14 @@ public BasicBlockTests.RandomBlock randomBlock(int positionCount, int maxValuesP
497494
ordinals.beginPositionEntry();
498495
}
499496
for (int v = 0; v < valueCount; v++) {
500-
Map.Entry<String, Integer> value = randomFrom(dictionary);
501-
valuesAtPosition.add(new BytesRef(value.getKey()));
502-
ordinals.appendInt(value.getValue());
503-
ordsAtPosition.add(value.getValue());
497+
String key = randomFrom(keys);
498+
int ordinal = dictionary.computeIfAbsent(key, k -> {
499+
bytes.appendBytesRef(new BytesRef(k));
500+
return dictionary.size();
501+
});
502+
valuesAtPosition.add(new BytesRef(key));
503+
ordinals.appendInt(ordinal);
504+
ordsAtPosition.add(ordinal);
504505
}
505506
for (int v = 0; v < dupCount; v++) {
506507
ordinals.appendInt(randomFrom(ordsAtPosition));

0 commit comments

Comments
 (0)