Skip to content

Commit 1a3eab5

Browse files
committed
ARROW-6215: [Java] Fix case when ZeroVector is compared against other vector types
This fixes a bug that when a ZeroVector is compared with a vector of any other type, it always returns true. Instead of hard-coding a return value of `true` in `ZeroVector.accept`, the `RangeEqualsVisitor` is used to compare the vector types. Closes #5070 from BryanCutler/java-RangeEqualsVisitor-fix-ZeroVector-ARROW-6215 and squashes the following commits: 7ad41be <Bryan Cutler> Fix case when ZeroVector is compared against other vector types Authored-by: Bryan Cutler <cutlerb@gmail.com> Signed-off-by: Bryan Cutler <cutlerb@gmail.com>
1 parent 71ae74b commit 1a3eab5

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

java/vector/src/main/java/org/apache/arrow/vector/ZeroVector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,6 @@ public void copyFromSafe(int fromIndex, int thisIndex, ValueVector from) {
268268

269269
@Override
270270
public boolean accept(RangeEqualsVisitor visitor) {
271-
return true;
271+
return visitor.visit(this);
272272
}
273273
}

java/vector/src/main/java/org/apache/arrow/vector/compare/RangeEqualsVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public boolean visit(UnionVector left) {
7676
}
7777

7878
public boolean visit(ZeroVector left) {
79-
return true;
79+
return compareValueVector(left, right);
8080
}
8181

8282
public boolean visit(ValueVector left) {

java/vector/src/test/java/org/apache/arrow/vector/TestValueVector.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,19 @@ public void testZeroVectorEquals() {
22652265
}
22662266
}
22672267

2268+
@Test
2269+
public void testZeroVectorNotEquals() {
2270+
try (final IntVector intVector = new IntVector("int", allocator);
2271+
final ZeroVector zeroVector = new ZeroVector()) {
2272+
2273+
VectorEqualsVisitor zeroVisitor = new VectorEqualsVisitor(zeroVector);
2274+
assertFalse(intVector.accept(zeroVisitor));
2275+
2276+
VectorEqualsVisitor intVisitor = new VectorEqualsVisitor(intVector);
2277+
assertFalse(zeroVector.accept(intVisitor));
2278+
}
2279+
}
2280+
22682281
@Test
22692282
public void testIntVectorEqualsWithNull() {
22702283
try (final IntVector vector1 = new IntVector("int", allocator);

0 commit comments

Comments
 (0)