diff --git a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/ConstantBytesRefVector.java b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/ConstantBytesRefVector.java index 5b4ccfdb12bf4..55a46ddb50c8c 100644 --- a/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/ConstantBytesRefVector.java +++ b/x-pack/plugin/esql/compute/src/main/generated-src/org/elasticsearch/compute/data/ConstantBytesRefVector.java @@ -32,8 +32,11 @@ final class ConstantBytesRefVector extends AbstractVector implements BytesRefVec } @Override - public BytesRef getBytesRef(int position, BytesRef ignore) { - return value; + public BytesRef getBytesRef(int position, BytesRef scratch) { + scratch.bytes = value.bytes; + scratch.offset = value.offset; + scratch.length = value.length; + return scratch; } @Override diff --git a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/X-ConstantVector.java.st b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/X-ConstantVector.java.st index 37cd9e4a82b14..2b52c7234f04b 100644 --- a/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/X-ConstantVector.java.st +++ b/x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/data/X-ConstantVector.java.st @@ -40,11 +40,15 @@ $endif$ @Override $if(BytesRef)$ - public BytesRef getBytesRef(int position, BytesRef ignore) { + public BytesRef getBytesRef(int position, BytesRef scratch) { + scratch.bytes = value.bytes; + scratch.offset = value.offset; + scratch.length = value.length; + return scratch; $else$ public $type$ get$Type$(int position) { -$endif$ return value; +$endif$ } @Override diff --git a/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/data/BasicBlockTests.java b/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/data/BasicBlockTests.java index 7192146939ec5..f5586ebb0828f 100644 --- a/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/data/BasicBlockTests.java +++ b/x-pack/plugin/esql/compute/src/test/java/org/elasticsearch/compute/data/BasicBlockTests.java @@ -786,6 +786,12 @@ public void testConstantBytesRefBlock() { assertEmptyLookup(blockFactory, block); assertInsertNulls(block); releaseAndAssertBreaker(block); + // modify the offset + var v0 = block.getBytesRef(randomInt(positionCount), new BytesRef()); + var v1 = block.getBytesRef(randomInt(positionCount), new BytesRef()); + v1.length = 0; + var v2 = block.getBytesRef(randomInt(positionCount), new BytesRef()); + assertThat(v2, equalTo(v0)); } }