Skip to content

Commit 186a15b

Browse files
authored
Don't use a BytesStreamOutput to copy keys in BytesRefBlockHash (#114819) (#115288)
Removes he size limit on BytesStreamOutput when copying keys.
1 parent 2203e4c commit 186a15b

File tree

3 files changed

+16
-32
lines changed

3 files changed

+16
-32
lines changed

docs/changelog/114819.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 114819
2+
summary: Don't use a `BytesStreamOutput` to copy keys in `BytesRefBlockHash`
3+
area: EQL
4+
type: bug
5+
issues:
6+
- 114599

x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/aggregation/blockhash/BytesRefBlockHash.java

Lines changed: 5 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/aggregation/blockhash/X-BlockHash.java.st

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,10 @@ package org.elasticsearch.compute.aggregation.blockhash;
99

1010
$if(BytesRef)$
1111
import org.apache.lucene.util.BytesRef;
12-
import org.elasticsearch.common.io.stream.BytesStreamOutput;
13-
import org.elasticsearch.common.io.stream.StreamInput;
1412
$endif$
1513
import org.elasticsearch.common.unit.ByteSizeValue;
1614
import org.elasticsearch.common.util.BigArrays;
1715
import org.elasticsearch.common.util.BitArray;
18-
$if(BytesRef)$
19-
import org.elasticsearch.common.util.BytesRefArray;
20-
$endif$
2116
import org.elasticsearch.common.util.$Hash$;
2217
import org.elasticsearch.compute.aggregation.GroupingAggregatorFunction;
2318
import org.elasticsearch.compute.aggregation.SeenGroupIds;
@@ -58,8 +53,6 @@ $endif$
5853
import org.elasticsearch.core.ReleasableIterator;
5954

6055
$if(BytesRef)$
61-
import java.io.IOException;
62-
6356
$else$
6457
import java.util.BitSet;
6558

@@ -250,26 +243,21 @@ $if(BytesRef)$
250243
* without and still read from the block.
251244
*/
252245
// TODO replace with takeBytesRefsOwnership ?!
246+
final BytesRef spare = new BytesRef();
253247
if (seenNull) {
254248
try (var builder = blockFactory.newBytesRefBlockBuilder(Math.toIntExact(hash.size() + 1))) {
255249
builder.appendNull();
256-
BytesRef spare = new BytesRef();
257250
for (long i = 0; i < hash.size(); i++) {
258251
builder.appendBytesRef(hash.get(i, spare));
259252
}
260253
return new BytesRefBlock[] { builder.build() };
261254
}
262255
}
263-
264-
final int size = Math.toIntExact(hash.size());
265-
try (BytesStreamOutput out = new BytesStreamOutput()) {
266-
hash.getBytesRefs().writeTo(out);
267-
try (StreamInput in = out.bytes().streamInput()) {
268-
return new BytesRefBlock[] {
269-
blockFactory.newBytesRefArrayVector(new BytesRefArray(in, BigArrays.NON_RECYCLING_INSTANCE), size).asBlock() };
256+
try (var builder = blockFactory.newBytesRefBlockBuilder(Math.toIntExact(hash.size()))) {
257+
for (long i = 0; i < hash.size(); i++) {
258+
builder.appendBytesRef(hash.get(i, spare));
270259
}
271-
} catch (IOException e) {
272-
throw new IllegalStateException(e);
260+
return new BytesRefBlock[] { builder.build() };
273261
}
274262
$else$
275263
if (seenNull) {

0 commit comments

Comments
 (0)