Skip to content

Commit 0bf192d

Browse files
tianchen92kou
authored andcommitted
ARROW-6210: [Java] remove equals API from ValueVector
Related to [ARROW-6210](https://issues.apache.org/jira/browse/ARROW-6210). This is a follow-up from apache#4933 The callers should be fixed to use the RangeEquals API instead. Closes apache#5065 from tianchen92/ARROW-6210 and squashes the following commits: cae440a <tianchen> resolve comments ad2277b <tianchen> resolve comments and port tests fb1510e <tianchen> add ValueMatcher 14b3e67 <tianchen> ARROW-6210: remove equals API from ValueVector Authored-by: tianchen <niki.lj@alibaba-inc.com> Signed-off-by: Bryan Cutler <cutlerb@gmail.com>
1 parent eda58d9 commit 0bf192d

File tree

14 files changed

+354
-169
lines changed

14 files changed

+354
-169
lines changed

vector/src/main/codegen/templates/UnionVector.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -677,20 +677,6 @@ public int hashCode(int index) {
677677
return getVector(index).hashCode(index);
678678
}
679679

680-
@Override
681-
public boolean equals(int index, ValueVector to, int toIndex) {
682-
if (to == null) {
683-
return false;
684-
}
685-
Preconditions.checkArgument(index >= 0 && index < valueCount,
686-
"index %s out of range[0, %s]:", index, valueCount - 1);
687-
Preconditions.checkArgument(toIndex >= 0 && toIndex < to.getValueCount(),
688-
"index %s out of range[0, %s]:", index, to.getValueCount() - 1);
689-
690-
RangeEqualsVisitor visitor = new RangeEqualsVisitor(to, index, toIndex, 1);
691-
return this.accept(visitor);
692-
}
693-
694680
@Override
695681
public boolean accept(RangeEqualsVisitor visitor) {
696682
return visitor.visit(this);

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -884,21 +884,6 @@ public int hashCode(int index) {
884884
return ByteFunctionHelpers.hash(this.getDataBuffer(), start, end);
885885
}
886886

887-
@Override
888-
public boolean equals(int index, ValueVector to, int toIndex) {
889-
if (to == null) {
890-
return false;
891-
}
892-
893-
Preconditions.checkArgument(index >= 0 && index < valueCount,
894-
"index %s out of range[0, %s]:", index, valueCount - 1);
895-
Preconditions.checkArgument(toIndex >= 0 && toIndex < to.getValueCount(),
896-
"index %s out of range[0, %s]:", index, to.getValueCount() - 1);
897-
898-
RangeEqualsVisitor visitor = new RangeEqualsVisitor(to, index, toIndex, 1);
899-
return this.accept(visitor);
900-
}
901-
902887
@Override
903888
public boolean accept(RangeEqualsVisitor visitor) {
904889
return visitor.visit(this);

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1367,20 +1367,6 @@ public int hashCode(int index) {
13671367
return ByteFunctionHelpers.hash(this.getDataBuffer(), start, end);
13681368
}
13691369

1370-
@Override
1371-
public boolean equals(int index, ValueVector to, int toIndex) {
1372-
if (to == null) {
1373-
return false;
1374-
}
1375-
Preconditions.checkArgument(index >= 0 && index < valueCount,
1376-
"index %s out of range[0, %s]:", index, valueCount - 1);
1377-
Preconditions.checkArgument(toIndex >= 0 && toIndex < to.getValueCount(),
1378-
"index %s out of range[0, %s]:", index, to.getValueCount() - 1);
1379-
1380-
RangeEqualsVisitor visitor = new RangeEqualsVisitor(to, index, toIndex, 1);
1381-
return this.accept(visitor);
1382-
}
1383-
13841370
@Override
13851371
public boolean accept(RangeEqualsVisitor visitor) {
13861372
return visitor.visit(this);

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,6 @@ public interface ValueVector extends Closeable, Iterable<ValueVector> {
244244
*/
245245
int hashCode(int index);
246246

247-
/**
248-
* Check whether the element in index equals to the element in targetIndex from the target vector.
249-
* @param index index to compare in this vector
250-
* @param target target vector
251-
* @param targetIndex index to compare in target vector
252-
* @return true if equals, otherwise false.
253-
*/
254-
boolean equals(int index, ValueVector target, int targetIndex);
255-
256247
/**
257248
* Copy a cell value from a particular index in source vector to a particular
258249
* position in this vector.

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,6 @@ public int hashCode(int index) {
251251
return 0;
252252
}
253253

254-
@Override
255-
public boolean equals(int index, ValueVector to, int toIndex) {
256-
return false;
257-
}
258-
259254
@Override
260255
public void copyFrom(int fromIndex, int thisIndex, ValueVector from) {
261256
throw new UnsupportedOperationException();

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

Lines changed: 73 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.List;
2121

2222
import org.apache.arrow.memory.util.ByteFunctionHelpers;
23+
import org.apache.arrow.util.Preconditions;
2324
import org.apache.arrow.vector.BaseFixedWidthVector;
2425
import org.apache.arrow.vector.BaseVariableWidthVector;
2526
import org.apache.arrow.vector.FieldVector;
@@ -37,62 +38,93 @@
3738
public class RangeEqualsVisitor {
3839

3940
protected final ValueVector right;
40-
protected final int leftStart;
41-
protected final int rightStart;
42-
protected final int length;
41+
protected int leftStart;
42+
protected int rightStart;
43+
protected int length;
44+
45+
protected boolean typeCheckNeeded = true;
4346

4447
/**
4548
* Constructs a new instance.
4649
*/
47-
public RangeEqualsVisitor(ValueVector right, int leftStart, int rightStart, int length) {
50+
public RangeEqualsVisitor(ValueVector right, int rightStart, int leftStart, int length, boolean typeCheckNeeded) {
4851
this.leftStart = leftStart;
4952
this.rightStart = rightStart;
5053
this.right = right;
5154
this.length = length;
55+
this.typeCheckNeeded = typeCheckNeeded;
56+
Preconditions.checkArgument(length >= 0, "length must be non negative");
57+
}
58+
59+
/**
60+
* Constructs a new instance.
61+
*/
62+
public RangeEqualsVisitor(ValueVector right, int leftStart, int rightStart, int length) {
63+
this(right, rightStart, leftStart, length, true);
64+
}
65+
66+
/**
67+
* Do some validation work, like type check and indices check.
68+
*/
69+
private boolean validate(ValueVector left) {
70+
71+
if (!compareValueVector(left, right)) {
72+
return false;
73+
}
74+
75+
Preconditions.checkArgument(leftStart >= 0,
76+
"leftStart %s must be non negative.", leftStart);
77+
Preconditions.checkArgument((leftStart + length) <= left.getValueCount(),
78+
"(leftStart + length) %s out of range[0, %s].", 0, left.getValueCount());
79+
Preconditions.checkArgument(rightStart >= 0,
80+
"rightStart %s must be non negative.", rightStart);
81+
Preconditions.checkArgument((rightStart + length) <= right.getValueCount(),
82+
"(rightStart + length) %s out of range[0, %s].", 0, right.getValueCount());
83+
84+
return true;
5285
}
5386

5487
public boolean visit(BaseFixedWidthVector left) {
55-
return compareBaseFixedWidthVectors(left);
88+
return validate(left) && compareBaseFixedWidthVectors(left);
5689
}
5790

5891
public boolean visit(BaseVariableWidthVector left) {
59-
return compareBaseVariableWidthVectors(left);
92+
return validate(left) && compareBaseVariableWidthVectors(left);
6093
}
6194

6295
public boolean visit(ListVector left) {
63-
return compareListVectors(left);
96+
return validate(left) && compareListVectors(left);
6497
}
6598

6699
public boolean visit(FixedSizeListVector left) {
67-
return compareFixedSizeListVectors(left);
100+
return validate(left) && compareFixedSizeListVectors(left);
68101
}
69102

70103
public boolean visit(NonNullableStructVector left) {
71-
return compareStructVectors(left);
104+
return validate(left) && compareStructVectors(left);
72105
}
73106

74107
public boolean visit(UnionVector left) {
75-
return compareUnionVectors(left);
108+
return validate(left) && compareUnionVectors(left);
76109
}
77110

78111
public boolean visit(ZeroVector left) {
79-
return compareValueVector(left, right);
112+
return validate(left);
80113
}
81114

82115
public boolean visit(ValueVector left) {
83116
throw new UnsupportedOperationException();
84117
}
85118

86119
protected boolean compareValueVector(ValueVector left, ValueVector right) {
120+
if (!typeCheckNeeded) {
121+
return true;
122+
}
87123
return left.getField().getType().equals(right.getField().getType());
88124
}
89125

90126
protected boolean compareUnionVectors(UnionVector left) {
91127

92-
if (!compareValueVector(left, right)) {
93-
return false;
94-
}
95-
96128
UnionVector rightVector = (UnionVector) right;
97129

98130
List<FieldVector> leftChildren = left.getChildrenFromFields();
@@ -113,9 +145,6 @@ protected boolean compareUnionVectors(UnionVector left) {
113145
}
114146

115147
protected boolean compareStructVectors(NonNullableStructVector left) {
116-
if (!compareValueVector(left, right)) {
117-
return false;
118-
}
119148

120149
NonNullableStructVector rightVector = (NonNullableStructVector) right;
121150

@@ -136,10 +165,6 @@ protected boolean compareStructVectors(NonNullableStructVector left) {
136165

137166
protected boolean compareBaseFixedWidthVectors(BaseFixedWidthVector left) {
138167

139-
if (!compareValueVector(left, right)) {
140-
return false;
141-
}
142-
143168
for (int i = 0; i < length; i++) {
144169
int leftIndex = leftStart + i;
145170
int rightIndex = rightStart + i;
@@ -152,14 +177,14 @@ protected boolean compareBaseFixedWidthVectors(BaseFixedWidthVector left) {
152177

153178
int typeWidth = left.getTypeWidth();
154179
if (!isNull) {
155-
int startByteLeft = typeWidth * leftIndex;
156-
int endByteLeft = typeWidth * (leftIndex + 1);
180+
int startIndexLeft = typeWidth * leftIndex;
181+
int endIndexLeft = typeWidth * (leftIndex + 1);
157182

158-
int startByteRight = typeWidth * rightIndex;
159-
int endByteRight = typeWidth * (rightIndex + 1);
183+
int startIndexRight = typeWidth * rightIndex;
184+
int endIndexRight = typeWidth * (rightIndex + 1);
160185

161-
int ret = ByteFunctionHelpers.equal(left.getDataBuffer(), startByteLeft, endByteLeft,
162-
right.getDataBuffer(), startByteRight, endByteRight);
186+
int ret = ByteFunctionHelpers.equal(left.getDataBuffer(), startIndexLeft, endIndexLeft,
187+
right.getDataBuffer(), startIndexRight, endIndexRight);
163188

164189
if (ret == 0) {
165190
return false;
@@ -170,9 +195,6 @@ protected boolean compareBaseFixedWidthVectors(BaseFixedWidthVector left) {
170195
}
171196

172197
protected boolean compareBaseVariableWidthVectors(BaseVariableWidthVector left) {
173-
if (!compareValueVector(left, right)) {
174-
return false;
175-
}
176198

177199
for (int i = 0; i < length; i++) {
178200
int leftIndex = leftStart + i;
@@ -186,14 +208,14 @@ protected boolean compareBaseVariableWidthVectors(BaseVariableWidthVector left)
186208
int offsetWidth = BaseVariableWidthVector.OFFSET_WIDTH;
187209

188210
if (!isNull) {
189-
final int startByteLeft = left.getOffsetBuffer().getInt(leftIndex * offsetWidth);
190-
final int endByteLeft = left.getOffsetBuffer().getInt((leftIndex + 1) * offsetWidth);
211+
final int startIndexLeft = left.getOffsetBuffer().getInt(leftIndex * offsetWidth);
212+
final int endIndexLeft = left.getOffsetBuffer().getInt((leftIndex + 1) * offsetWidth);
191213

192-
final int startByteRight = right.getOffsetBuffer().getInt(rightIndex * offsetWidth);
193-
final int endByteRight = right.getOffsetBuffer().getInt((rightIndex + 1) * offsetWidth);
214+
final int startIndexRight = right.getOffsetBuffer().getInt(rightIndex * offsetWidth);
215+
final int endIndexRight = right.getOffsetBuffer().getInt((rightIndex + 1) * offsetWidth);
194216

195-
int ret = ByteFunctionHelpers.equal(left.getDataBuffer(), startByteLeft, endByteLeft,
196-
right.getDataBuffer(), startByteRight, endByteRight);
217+
int ret = ByteFunctionHelpers.equal(left.getDataBuffer(), startIndexLeft, endIndexLeft,
218+
right.getDataBuffer(), startIndexRight, endIndexRight);
197219

198220
if (ret == 0) {
199221
return false;
@@ -204,9 +226,6 @@ protected boolean compareBaseVariableWidthVectors(BaseVariableWidthVector left)
204226
}
205227

206228
protected boolean compareListVectors(ListVector left) {
207-
if (!compareValueVector(left, right)) {
208-
return false;
209-
}
210229

211230
for (int i = 0; i < length; i++) {
212231
int leftIndex = leftStart + i;
@@ -220,21 +239,21 @@ protected boolean compareListVectors(ListVector left) {
220239
int offsetWidth = BaseRepeatedValueVector.OFFSET_WIDTH;
221240

222241
if (!isNull) {
223-
final int startByteLeft = left.getOffsetBuffer().getInt(leftIndex * offsetWidth);
224-
final int endByteLeft = left.getOffsetBuffer().getInt((leftIndex + 1) * offsetWidth);
242+
final int startIndexLeft = left.getOffsetBuffer().getInt(leftIndex * offsetWidth);
243+
final int endIndexLeft = left.getOffsetBuffer().getInt((leftIndex + 1) * offsetWidth);
225244

226-
final int startByteRight = right.getOffsetBuffer().getInt(rightIndex * offsetWidth);
227-
final int endByteRight = right.getOffsetBuffer().getInt((rightIndex + 1) * offsetWidth);
245+
final int startIndexRight = right.getOffsetBuffer().getInt(rightIndex * offsetWidth);
246+
final int endIndexRight = right.getOffsetBuffer().getInt((rightIndex + 1) * offsetWidth);
228247

229-
if ((endByteLeft - startByteLeft) != (endByteRight - startByteRight)) {
248+
if ((endIndexLeft - startIndexLeft) != (endIndexRight - startIndexRight)) {
230249
return false;
231250
}
232251

233252
ValueVector leftDataVector = left.getDataVector();
234253
ValueVector rightDataVector = ((ListVector)right).getDataVector();
235254

236-
if (!leftDataVector.accept(new RangeEqualsVisitor(rightDataVector, startByteLeft,
237-
startByteRight, (endByteLeft - startByteLeft)))) {
255+
if (!leftDataVector.accept(new RangeEqualsVisitor(rightDataVector, startIndexLeft,
256+
startIndexRight, (endIndexLeft - startIndexLeft)))) {
238257
return false;
239258
}
240259
}
@@ -243,9 +262,6 @@ protected boolean compareListVectors(ListVector left) {
243262
}
244263

245264
protected boolean compareFixedSizeListVectors(FixedSizeListVector left) {
246-
if (!compareValueVector(left, right)) {
247-
return false;
248-
}
249265

250266
if (left.getListSize() != ((FixedSizeListVector)right).getListSize()) {
251267
return false;
@@ -263,26 +279,25 @@ protected boolean compareFixedSizeListVectors(FixedSizeListVector left) {
263279
int listSize = left.getListSize();
264280

265281
if (!isNull) {
266-
final int startByteLeft = leftIndex * listSize;
267-
final int endByteLeft = (leftIndex + 1) * listSize;
282+
final int startIndexLeft = leftIndex * listSize;
283+
final int endIndexLeft = (leftIndex + 1) * listSize;
268284

269-
final int startByteRight = rightIndex * listSize;
270-
final int endByteRight = (rightIndex + 1) * listSize;
285+
final int startIndexRight = rightIndex * listSize;
286+
final int endIndexRight = (rightIndex + 1) * listSize;
271287

272-
if ((endByteLeft - startByteLeft) != (endByteRight - startByteRight)) {
288+
if ((endIndexLeft - startIndexLeft) != (endIndexRight - startIndexRight)) {
273289
return false;
274290
}
275291

276292
ValueVector leftDataVector = left.getDataVector();
277293
ValueVector rightDataVector = ((FixedSizeListVector)right).getDataVector();
278294

279-
if (!leftDataVector.accept(new RangeEqualsVisitor(rightDataVector, startByteLeft, startByteRight,
280-
(endByteLeft - startByteLeft)))) {
295+
if (!leftDataVector.accept(new RangeEqualsVisitor(rightDataVector, startIndexLeft, startIndexRight,
296+
(endIndexLeft - startIndexLeft)))) {
281297
return false;
282298
}
283299
}
284300
}
285301
return true;
286302
}
287-
288303
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626
public class VectorEqualsVisitor extends RangeEqualsVisitor {
2727

2828
public VectorEqualsVisitor(ValueVector right) {
29-
super(Preconditions.checkNotNull(right), 0, 0, right.getValueCount());
29+
this(right, true);
30+
}
31+
32+
public VectorEqualsVisitor(ValueVector right, boolean typeCheckNeeded) {
33+
super(Preconditions.checkNotNull(right), 0, 0, right.getValueCount(), typeCheckNeeded);
3034
}
3135

3236
@Override

vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -538,20 +538,6 @@ public int hashCode(int index) {
538538
return hash;
539539
}
540540

541-
@Override
542-
public boolean equals(int index, ValueVector to, int toIndex) {
543-
if (to == null) {
544-
return false;
545-
}
546-
Preconditions.checkArgument(index >= 0 && index < valueCount,
547-
"index %s out of range[0, %s]:", index, valueCount - 1);
548-
Preconditions.checkArgument(toIndex >= 0 && toIndex < to.getValueCount(),
549-
"index %s out of range[0, %s]:", index, to.getValueCount() - 1);
550-
551-
RangeEqualsVisitor visitor = new RangeEqualsVisitor(to, index, toIndex, 1);
552-
return this.accept(visitor);
553-
}
554-
555541
@Override
556542
public boolean accept(RangeEqualsVisitor visitor) {
557543
return visitor.visit(this);

0 commit comments

Comments
 (0)