Skip to content

Commit 5facc2a

Browse files
committed
resolve comments
1 parent 175192a commit 5facc2a

File tree

6 files changed

+29
-18
lines changed

6 files changed

+29
-18
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,17 @@ public interface ValueVector extends Closeable, Iterable<ValueVector> {
238238
*/
239239
boolean isNull(int index);
240240

241-
//TODO remove default and implement in subclasses
241+
/**
242+
* Returns hashCode of element in index.
243+
*/
242244
int hashCode(int index);
243245

244-
//TODO remove default and implement in subclasses
245-
boolean equals(int index, ValueVector to, int toIndex);
246+
/**
247+
* Check whether the element in index equals to the element in targetIndex from the target vector.
248+
* @param index index to compare in this vector
249+
* @param target target vector
250+
* @param targetIndex index to compare in target vector
251+
* @return true if equals, otherwise false.
252+
*/
253+
boolean equals(int index, ValueVector target, int targetIndex);
246254
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.apache.arrow.vector.types.pojo.DictionaryEncoding;
4646
import org.apache.arrow.vector.types.pojo.Field;
4747
import org.apache.arrow.vector.types.pojo.FieldType;
48+
import org.apache.arrow.vector.util.ByteFunctionHelpers;
4849
import org.apache.arrow.vector.util.CallBack;
4950
import org.apache.arrow.vector.util.JsonStringArrayList;
5051
import org.apache.arrow.vector.util.OversizedAllocationException;
@@ -503,7 +504,7 @@ public int hashCode(int index) {
503504
}
504505
int hash = 0;
505506
for (int i = 0; i < listSize; i++) {
506-
hash = 31 * vector.hashCode(index * listSize + i);
507+
hash = ByteFunctionHelpers.comebineHash(hash, vector.hashCode(index * listSize + i));
507508
}
508509
return hash;
509510
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public static ValueVector encode(ValueVector vector, Dictionary dictionary) {
4545
validateType(vector.getMinorType());
4646
// load dictionary indices into a hashmap for lookup
4747

48-
DictionaryHashTable hashTable = new DictionaryHashTable(dictionary.getVector(), vector);
48+
DictionaryHashTable hashTable = new DictionaryHashTable(dictionary.getVector());
4949
for (int i = 0; i < dictionary.getVector().getValueCount(); i++) {
5050
hashTable.put(i);
5151
}
@@ -71,7 +71,7 @@ public static ValueVector encode(ValueVector vector, Dictionary dictionary) {
7171
if (!vector.isNull(i)) { // if it's null leave it null
7272
// note: this may fail if value was not included in the dictionary
7373
//int encoded = lookUps.get(value);
74-
int encoded = hashTable.getIndex(i);
74+
int encoded = hashTable.getIndex(i, vector);
7575
if (encoded == -1) {
7676
throw new IllegalArgumentException("Dictionary encoding not defined for value:" + vector.getObject(i));
7777
}

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,10 @@ public class DictionaryHashTable {
7474

7575
private final ValueVector dictionary;
7676

77-
private final ValueVector toEncode;
78-
7977
/**
8078
* Constructs an empty map with the specified initial capacity and load factor.
8179
*/
82-
public DictionaryHashTable(int initialCapacity, ValueVector dictionary, ValueVector toEncode) {
80+
public DictionaryHashTable(int initialCapacity, ValueVector dictionary) {
8381
if (initialCapacity < 0) {
8482
throw new IllegalArgumentException("Illegal initial capacity: " +
8583
initialCapacity);
@@ -91,11 +89,10 @@ public DictionaryHashTable(int initialCapacity, ValueVector dictionary, ValueVec
9189
this.threshold = initialCapacity;
9290

9391
this.dictionary = dictionary;
94-
this.toEncode = toEncode;
9592
}
9693

97-
public DictionaryHashTable(ValueVector dictionary, ValueVector toEncode) {
98-
this(DEFAULT_INITIAL_CAPACITY, dictionary, toEncode);
94+
public DictionaryHashTable(ValueVector dictionary) {
95+
this(DEFAULT_INITIAL_CAPACITY, dictionary);
9996
}
10097

10198
/**
@@ -132,7 +129,7 @@ static final int roundUpToPowerOf2(int size) {
132129
* @param indexInArray index in vector.
133130
* @return dictionary vector index or -1 if no value equals.
134131
*/
135-
public int getIndex(int indexInArray) {
132+
public int getIndex(int indexInArray, ValueVector toEncode) {
136133
int hash = toEncode.hashCode(indexInArray);
137134
int index = indexFor(hash, table.length);
138135
for (DictionaryHashTable.Entry e = table[index]; e != null ; e = e.next) {

java/vector/src/main/java/org/apache/arrow/vector/util/ByteFunctionHelpers.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,10 @@ public static final int hash(final ArrowBuf buf, int start, int end) {
8484
return hash;
8585
}
8686

87-
private static int comebineHash(int currentHash, int newHash) {
87+
/**
88+
* Generate a new hashCode with the given current hashCode and new hashCode.
89+
*/
90+
public static int comebineHash(int currentHash, int newHash) {
8891
return currentHash * 31 + newHash;
8992
}
9093

java/vector/src/test/java/org/apache/arrow/vector/types/pojo/TestExtensionType.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,14 @@ public UUID getObject(int index) {
205205
return new UUID(bb.getLong(), bb.getLong());
206206
}
207207

208-
@Override public int hashCode(int index) {
209-
return 0;
208+
@Override
209+
public int hashCode(int index) {
210+
return getUnderlyingVector().hashCode(index);
210211
}
211212

212-
@Override public boolean equals(int index, ValueVector to, int toIndex) {
213-
return false;
213+
@Override
214+
public boolean equals(int index, ValueVector to, int toIndex) {
215+
return getUnderlyingVector().equals(index, to, toIndex);
214216
}
215217

216218
public void set(int index, UUID uuid) {

0 commit comments

Comments
 (0)