Skip to content

Commit

Permalink
Don't use a BytesStreamOutput to copy keys in BytesRefBlockHash (elas…
Browse files Browse the repository at this point in the history
…tic#114819)

Removes he size limit on BytesStreamOutput when copying keys.
  • Loading branch information
iverase committed Oct 22, 2024
1 parent b69d23d commit 512f3fc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 32 deletions.
6 changes: 6 additions & 0 deletions docs/changelog/114819.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 114819
summary: Don't use a `BytesStreamOutput` to copy keys in `BytesRefBlockHash`
area: EQL
type: bug
issues:
- 114599

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ package org.elasticsearch.compute.aggregation.blockhash;

$if(BytesRef)$
import org.apache.lucene.util.BytesRef;
import org.elasticsearch.common.io.stream.BytesStreamOutput;
import org.elasticsearch.common.io.stream.StreamInput;
$endif$
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.util.BitArray;
$if(BytesRef)$
import org.elasticsearch.common.util.BytesRefArray;
$endif$
import org.elasticsearch.common.util.$Hash$;
import org.elasticsearch.compute.aggregation.GroupingAggregatorFunction;
import org.elasticsearch.compute.aggregation.SeenGroupIds;
Expand Down Expand Up @@ -58,8 +53,6 @@ $endif$
import org.elasticsearch.core.ReleasableIterator;

$if(BytesRef)$
import java.io.IOException;

$else$
import java.util.BitSet;

Expand Down Expand Up @@ -250,26 +243,21 @@ $if(BytesRef)$
* without and still read from the block.
*/
// TODO replace with takeBytesRefsOwnership ?!
final BytesRef spare = new BytesRef();
if (seenNull) {
try (var builder = blockFactory.newBytesRefBlockBuilder(Math.toIntExact(hash.size() + 1))) {
builder.appendNull();
BytesRef spare = new BytesRef();
for (long i = 0; i < hash.size(); i++) {
builder.appendBytesRef(hash.get(i, spare));
}
return new BytesRefBlock[] { builder.build() };
}
}

final int size = Math.toIntExact(hash.size());
try (BytesStreamOutput out = new BytesStreamOutput()) {
hash.getBytesRefs().writeTo(out);
try (StreamInput in = out.bytes().streamInput()) {
return new BytesRefBlock[] {
blockFactory.newBytesRefArrayVector(new BytesRefArray(in, BigArrays.NON_RECYCLING_INSTANCE), size).asBlock() };
try (var builder = blockFactory.newBytesRefBlockBuilder(Math.toIntExact(hash.size()))) {
for (long i = 0; i < hash.size(); i++) {
builder.appendBytesRef(hash.get(i, spare));
}
} catch (IOException e) {
throw new IllegalStateException(e);
return new BytesRefBlock[] { builder.build() };
}
$else$
if (seenNull) {
Expand Down

0 comments on commit 512f3fc

Please sign in to comment.