From abd883a7ab4c896b02712936a981f7c50eb979d1 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Fri, 10 Oct 2025 22:46:36 -0700 Subject: [PATCH] Fix getBytesRef in ConstantBytesRefVector --- .../compute/data/ConstantBytesRefVector.java | 7 +++++-- .../elasticsearch/compute/data/X-ConstantVector.java.st | 8 ++++++-- .../org/elasticsearch/compute/data/BasicBlockTests.java | 6 ++++++ 3 files changed, 17 insertions(+), 4 deletions(-) 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 4cd838d921c34..545a7ad0f9684 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 bac513d0b3b4d..fa714560f1617 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 e0a18c79307c5..27759402efd9d 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 @@ -818,6 +818,12 @@ public void testConstantBytesRefBlock() { assertInsertNulls(block); assertDeepCopy(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)); } }