From fbf4f0325679f331f1c7b9265990b8b84e8fdac1 Mon Sep 17 00:00:00 2001 From: Minh Vu Date: Sun, 2 Aug 2026 01:56:23 +0200 Subject: [PATCH] MINOR: Respect ByteBuffer offset in Binary equality --- .../org/apache/parquet/io/api/Binary.java | 2 +- .../org/apache/parquet/io/api/TestBinary.java | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/parquet-column/src/main/java/org/apache/parquet/io/api/Binary.java b/parquet-column/src/main/java/org/apache/parquet/io/api/Binary.java index 3160f091e7..ba01bd2a43 100644 --- a/parquet-column/src/main/java/org/apache/parquet/io/api/Binary.java +++ b/parquet-column/src/main/java/org/apache/parquet/io/api/Binary.java @@ -538,7 +538,7 @@ boolean equals(byte[] other, int otherOffset, int otherLength) { @Override boolean equals(ByteBuffer otherBytes, int otherOffset, int otherLength) { - return Binary.equals(value, 0, length, otherBytes, otherOffset, otherLength); + return Binary.equals(value, offset, length, otherBytes, otherOffset, otherLength); } @Override diff --git a/parquet-column/src/test/java/org/apache/parquet/io/api/TestBinary.java b/parquet-column/src/test/java/org/apache/parquet/io/api/TestBinary.java index cda54becd9..39ed6e2a25 100644 --- a/parquet-column/src/test/java/org/apache/parquet/io/api/TestBinary.java +++ b/parquet-column/src/test/java/org/apache/parquet/io/api/TestBinary.java @@ -244,6 +244,29 @@ public void testEqualityMethods() throws Exception { assertThat(bin2).isEqualTo(bin1); } + @Test + public void testDirectByteBufferEqualityWithOffset() { + ByteBuffer slicedBuffer = ByteBuffer.allocateDirect(3); + slicedBuffer.put(new byte[] {9, 1, 2}); + slicedBuffer.position(1); + Binary sliced = Binary.fromConstantByteBuffer(slicedBuffer); + + ByteBuffer equalBuffer = ByteBuffer.allocateDirect(2); + equalBuffer.put(new byte[] {1, 2}); + equalBuffer.flip(); + Binary equal = Binary.fromConstantByteBuffer(equalBuffer); + + ByteBuffer differentBuffer = ByteBuffer.allocateDirect(2); + differentBuffer.put(new byte[] {9, 1}); + differentBuffer.flip(); + Binary different = Binary.fromConstantByteBuffer(differentBuffer); + + assertThat(sliced).isEqualTo(equal); + assertThat(equal).isEqualTo(sliced); + assertThat(sliced.hashCode()).isEqualTo(equal.hashCode()); + assertThat(different).isNotEqualTo(sliced); + } + @Test public void testWriteAllTo() throws Exception { byte[] orig = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};