Skip to content

Commit 14b3e67

Browse files
committed
ARROW-6210: [Java] remove equals API from ValueVector
1 parent cafb00f commit 14b3e67

File tree

12 files changed

+66
-138
lines changed

12 files changed

+66
-138
lines changed

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

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

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

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

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

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

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

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

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

java/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.

java/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();

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

Lines changed: 57 additions & 29 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,9 +38,9 @@
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;
4344

4445
/**
4546
* Constructs a new instance.
@@ -49,29 +50,56 @@ public RangeEqualsVisitor(ValueVector right, int leftStart, int rightStart, int
4950
this.rightStart = rightStart;
5051
this.right = right;
5152
this.length = length;
53+
Preconditions.checkArgument(length >= 0, "length must be non negative");
54+
}
55+
56+
/**
57+
* Reset start indices and length for reuse purpose.
58+
*/
59+
public void reset(int leftStart, int rightStart, int length) {
60+
this.leftStart = leftStart;
61+
this.rightStart = rightStart;
62+
this.length = length;
63+
}
64+
65+
private void validateIndices(ValueVector left) {
66+
Preconditions.checkArgument(leftStart >= 0 && leftStart < left.getValueCount(),
67+
"leftStart %s out of range[0, %s]:", 0, left.getValueCount());
68+
Preconditions.checkArgument((leftStart + length) <= left.getValueCount(),
69+
"(leftStart + length) %s out of range[0, %s]:", 0, left.getValueCount());
70+
Preconditions.checkArgument(rightStart >= 0 && rightStart < right.getValueCount(),
71+
"rightStart %s out of range[0, %s]:", 0, right.getValueCount());
72+
Preconditions.checkArgument((rightStart + length) <= right.getValueCount(),
73+
"(rightStart + length) %s out of range[0, %s]:", 0, right.getValueCount());
5274
}
5375

5476
public boolean visit(BaseFixedWidthVector left) {
77+
validateIndices(left);
5578
return compareBaseFixedWidthVectors(left);
5679
}
5780

5881
public boolean visit(BaseVariableWidthVector left) {
82+
validateIndices(left);
5983
return compareBaseVariableWidthVectors(left);
6084
}
6185

6286
public boolean visit(ListVector left) {
87+
validateIndices(left);
6388
return compareListVectors(left);
6489
}
6590

6691
public boolean visit(FixedSizeListVector left) {
92+
validateIndices(left);
6793
return compareFixedSizeListVectors(left);
6894
}
6995

7096
public boolean visit(NonNullableStructVector left) {
97+
validateIndices(left);
7198
return compareStructVectors(left);
7299
}
73100

74101
public boolean visit(UnionVector left) {
102+
validateIndices(left);
75103
return compareUnionVectors(left);
76104
}
77105

@@ -152,14 +180,14 @@ protected boolean compareBaseFixedWidthVectors(BaseFixedWidthVector left) {
152180

153181
int typeWidth = left.getTypeWidth();
154182
if (!isNull) {
155-
int startByteLeft = typeWidth * leftIndex;
156-
int endByteLeft = typeWidth * (leftIndex + 1);
183+
int startIndexLeft = typeWidth * leftIndex;
184+
int endIndexLeft = typeWidth * (leftIndex + 1);
157185

158-
int startByteRight = typeWidth * rightIndex;
159-
int endByteRight = typeWidth * (rightIndex + 1);
186+
int startIndexRight = typeWidth * rightIndex;
187+
int endIndexRight = typeWidth * (rightIndex + 1);
160188

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

164192
if (ret == 0) {
165193
return false;
@@ -186,14 +214,14 @@ protected boolean compareBaseVariableWidthVectors(BaseVariableWidthVector left)
186214
int offsetWidth = BaseVariableWidthVector.OFFSET_WIDTH;
187215

188216
if (!isNull) {
189-
final int startByteLeft = left.getOffsetBuffer().getInt(leftIndex * offsetWidth);
190-
final int endByteLeft = left.getOffsetBuffer().getInt((leftIndex + 1) * offsetWidth);
217+
final int startIndexLeft = left.getOffsetBuffer().getInt(leftIndex * offsetWidth);
218+
final int endIndexLeft = left.getOffsetBuffer().getInt((leftIndex + 1) * offsetWidth);
191219

192-
final int startByteRight = right.getOffsetBuffer().getInt(rightIndex * offsetWidth);
193-
final int endByteRight = right.getOffsetBuffer().getInt((rightIndex + 1) * offsetWidth);
220+
final int startIndexRight = right.getOffsetBuffer().getInt(rightIndex * offsetWidth);
221+
final int endIndexRight = right.getOffsetBuffer().getInt((rightIndex + 1) * offsetWidth);
194222

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

198226
if (ret == 0) {
199227
return false;
@@ -220,21 +248,21 @@ protected boolean compareListVectors(ListVector left) {
220248
int offsetWidth = BaseRepeatedValueVector.OFFSET_WIDTH;
221249

222250
if (!isNull) {
223-
final int startByteLeft = left.getOffsetBuffer().getInt(leftIndex * offsetWidth);
224-
final int endByteLeft = left.getOffsetBuffer().getInt((leftIndex + 1) * offsetWidth);
251+
final int startIndexLeft = left.getOffsetBuffer().getInt(leftIndex * offsetWidth);
252+
final int endIndexLeft = left.getOffsetBuffer().getInt((leftIndex + 1) * offsetWidth);
225253

226-
final int startByteRight = right.getOffsetBuffer().getInt(rightIndex * offsetWidth);
227-
final int endByteRight = right.getOffsetBuffer().getInt((rightIndex + 1) * offsetWidth);
254+
final int startIndexRight = right.getOffsetBuffer().getInt(rightIndex * offsetWidth);
255+
final int endIndexRight = right.getOffsetBuffer().getInt((rightIndex + 1) * offsetWidth);
228256

229-
if ((endByteLeft - startByteLeft) != (endByteRight - startByteRight)) {
257+
if ((endIndexLeft - startIndexLeft) != (endIndexRight - startIndexRight)) {
230258
return false;
231259
}
232260

233261
ValueVector leftDataVector = left.getDataVector();
234262
ValueVector rightDataVector = ((ListVector)right).getDataVector();
235263

236-
if (!leftDataVector.accept(new RangeEqualsVisitor(rightDataVector, startByteLeft,
237-
startByteRight, (endByteLeft - startByteLeft)))) {
264+
if (!leftDataVector.accept(new RangeEqualsVisitor(rightDataVector, startIndexLeft,
265+
startIndexRight, (endIndexLeft - startIndexLeft)))) {
238266
return false;
239267
}
240268
}
@@ -263,21 +291,21 @@ protected boolean compareFixedSizeListVectors(FixedSizeListVector left) {
263291
int listSize = left.getListSize();
264292

265293
if (!isNull) {
266-
final int startByteLeft = leftIndex * listSize;
267-
final int endByteLeft = (leftIndex + 1) * listSize;
294+
final int startIndexLeft = leftIndex * listSize;
295+
final int endIndexLeft = (leftIndex + 1) * listSize;
268296

269-
final int startByteRight = rightIndex * listSize;
270-
final int endByteRight = (rightIndex + 1) * listSize;
297+
final int startIndexRight = rightIndex * listSize;
298+
final int endIndexRight = (rightIndex + 1) * listSize;
271299

272-
if ((endByteLeft - startByteLeft) != (endByteRight - startByteRight)) {
300+
if ((endIndexLeft - startIndexLeft) != (endIndexRight - startIndexRight)) {
273301
return false;
274302
}
275303

276304
ValueVector leftDataVector = left.getDataVector();
277305
ValueVector rightDataVector = ((FixedSizeListVector)right).getDataVector();
278306

279-
if (!leftDataVector.accept(new RangeEqualsVisitor(rightDataVector, startByteLeft, startByteRight,
280-
(endByteLeft - startByteLeft)))) {
307+
if (!leftDataVector.accept(new RangeEqualsVisitor(rightDataVector, startIndexLeft, startIndexRight,
308+
(endIndexLeft - startIndexLeft)))) {
281309
return false;
282310
}
283311
}

java/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
@@ -535,20 +535,6 @@ public int hashCode(int index) {
535535
return hash;
536536
}
537537

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

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import org.apache.arrow.memory.BaseAllocator;
2929
import org.apache.arrow.memory.BufferAllocator;
3030
import org.apache.arrow.memory.OutOfMemoryException;
31-
import org.apache.arrow.util.Preconditions;
3231
import org.apache.arrow.vector.AddOrGetResult;
3332
import org.apache.arrow.vector.BitVectorHelper;
3433
import org.apache.arrow.vector.BufferBacked;
@@ -427,20 +426,6 @@ public int hashCode(int index) {
427426
return hash;
428427
}
429428

430-
@Override
431-
public boolean equals(int index, ValueVector to, int toIndex) {
432-
if (to == null) {
433-
return false;
434-
}
435-
Preconditions.checkArgument(index >= 0 && index < valueCount,
436-
"index %s out of range[0, %s]:", index, valueCount - 1);
437-
Preconditions.checkArgument(toIndex >= 0 && toIndex < to.getValueCount(),
438-
"index %s out of range[0, %s]:", index, to.getValueCount() - 1);
439-
440-
RangeEqualsVisitor visitor = new RangeEqualsVisitor(to, index, toIndex, 1);
441-
return this.accept(visitor);
442-
}
443-
444429
private class TransferImpl implements TransferPair {
445430

446431
ListVector to;

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.Map;
2727

2828
import org.apache.arrow.memory.BufferAllocator;
29-
import org.apache.arrow.util.Preconditions;
3029
import org.apache.arrow.vector.DensityAwareVector;
3130
import org.apache.arrow.vector.FieldVector;
3231
import org.apache.arrow.vector.ValueVector;
@@ -305,20 +304,6 @@ public boolean accept(RangeEqualsVisitor visitor) {
305304
return visitor.visit(this);
306305
}
307306

308-
@Override
309-
public boolean equals(int index, ValueVector to, int toIndex) {
310-
if (to == null) {
311-
return false;
312-
}
313-
Preconditions.checkArgument(index >= 0 && index < valueCount,
314-
"index %s out of range[0, %s]:", index, valueCount - 1);
315-
Preconditions.checkArgument(toIndex >= 0 && toIndex < to.getValueCount(),
316-
"index %s out of range[0, %s]:", index, to.getValueCount() - 1);
317-
318-
RangeEqualsVisitor visitor = new RangeEqualsVisitor(to, index, toIndex, 1);
319-
return this.accept(visitor);
320-
}
321-
322307
@Override
323308
public boolean isNull(int index) {
324309
return false;

java/vector/src/main/java/org/apache/arrow/vector/dictionary/DictionaryHashTable.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.Objects;
2121

2222
import org.apache.arrow.vector.ValueVector;
23+
import org.apache.arrow.vector.compare.RangeEqualsVisitor;
2324

2425
/**
2526
* HashTable used for Dictionary encoding. It holds two vectors (the vector to encode and dictionary vector)
@@ -74,6 +75,8 @@ public class DictionaryHashTable {
7475

7576
private final ValueVector dictionary;
7677

78+
private final RangeEqualsVisitor visitor;
79+
7780
/**
7881
* Constructs an empty map with the specified initial capacity and load factor.
7982
*/
@@ -94,6 +97,7 @@ public DictionaryHashTable(int initialCapacity, ValueVector dictionary) {
9497
for (int i = 0; i < this.dictionary.getValueCount(); i++) {
9598
put(i);
9699
}
100+
this.visitor = new RangeEqualsVisitor(dictionary, 0, 0, 1);
97101
}
98102

99103
public DictionaryHashTable(ValueVector dictionary) {
@@ -140,7 +144,8 @@ public int getIndex(int indexInArray, ValueVector toEncode) {
140144
for (DictionaryHashTable.Entry e = table[index]; e != null ; e = e.next) {
141145
if ((e.hash == hash)) {
142146
int dictIndex = e.index;
143-
if (dictionary.equals(dictIndex, toEncode, indexInArray)) {
147+
visitor.reset(indexInArray, dictIndex, 1);
148+
if (toEncode.accept(visitor)) {
144149
return dictIndex;
145150
}
146151
}

0 commit comments

Comments
 (0)