Skip to content

Commit

Permalink
GH-35528:[Java] Fix RangeEqualsVisitor comparing BitVector with diffe…
Browse files Browse the repository at this point in the history
…rent begin index (#35525)

### Rationale for this change

bugfix: RangeEqualsVisitor compare BitVector false when compared vectors have different begin index. 

In origin code, when compared vectors have different begin index, it will compare vectors value with same index, which is error logic. this pr is to fix it.

### What changes are included in this PR?

only changes RangeEqualsVisitor.compareBaseFixedWidthVectors method, and add test

### Are these changes tested?
yes.

### Are there any user-facing changes?
no.

* Closes: #35528

Authored-by: wenxianglan.233 <[email protected]>
Signed-off-by: David Li <[email protected]>
  • Loading branch information
wenxlan authored May 12, 2023
1 parent cdefbb8 commit 1624d5a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ protected boolean compareBaseFixedWidthVectors(Range range) {
return false;
}
} else {
boolean ret = ((BitVector) leftVector).get(leftIndex) == ((BitVector) rightVector).get(leftIndex);
boolean ret = ((BitVector) leftVector).get(leftIndex) == ((BitVector) rightVector).get(rightIndex);
if (!ret) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.arrow.memory.BufferAllocator;
import org.apache.arrow.memory.RootAllocator;
import org.apache.arrow.vector.BigIntVector;
import org.apache.arrow.vector.BitVector;
import org.apache.arrow.vector.Float4Vector;
import org.apache.arrow.vector.Float8Vector;
import org.apache.arrow.vector.IntVector;
Expand Down Expand Up @@ -181,6 +182,28 @@ public void testListVectorRangeEquals() {
}
}

@Test
public void testBitVectorRangeEquals() {
try (final BitVector vector1 = new BitVector("v1", allocator);
final BitVector vector2 = new BitVector("v2", allocator);) {

boolean[] v1 = new boolean[]{true, false, true, true, true};
boolean[] v2 = new boolean[]{false, true, true, true, false};
vector1.setValueCount(5);
for (int i = 0; i < 5; i ++) {
vector1.set(i, v1[i] ? 1 : 0);
}
vector2.setValueCount(5);
for (int i = 0; i < 5; i ++) {
vector2.set(i, v2[i] ? 1 : 0);
}

RangeEqualsVisitor visitor = new RangeEqualsVisitor(vector1, vector2);
assertTrue(visitor.compareBaseFixedWidthVectors(new Range(1, 0, 4)));
assertFalse(visitor.compareBaseFixedWidthVectors(new Range(0, 0, 5)));
}
}

@Test
public void testFixedSizeListVectorRangeEquals() {
try (final FixedSizeListVector vector1 = FixedSizeListVector.empty("list", 2, allocator);
Expand Down

0 comments on commit 1624d5a

Please sign in to comment.