Skip to content

Commit 7f6f010

Browse files
tianchen92emkornfield
authored andcommitted
ARROW-6234: [Java] ListVector hashCode() is not correct
Related to [ARROW-6234](https://issues.apache.org/jira/browse/ARROW-6234). Current implement is not correct: for (int i = start; i < end; i++) { hash = 31 * vector.hashCode(i); } Should be something like: hash = 31 * hash + vector.hashCode(i); Closes apache#5082 from tianchen92/ARROW-6234 and squashes the following commits: 9ad7a7e <tianchen92> Merge branch 'master' into ARROW-6234 ff2b01f <tianchen92> Merge branch 'master' into ARROW-6234 0bb79e2 <tianchen> ARROW-6234: ListVector hashCode() is not correct Lead-authored-by: tianchen <niki.lj@alibaba-inc.com> Co-authored-by: tianchen92 <niki.lj@alibaba-inc.com> Signed-off-by: Micah Kornfield <emkornfield@gmail.com>
1 parent e0e915c commit 7f6f010

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
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.memory.util.ByteFunctionHelpers;
3132
import org.apache.arrow.util.Preconditions;
3233
import org.apache.arrow.vector.AddOrGetResult;
3334
import org.apache.arrow.vector.BitVectorHelper;
@@ -425,7 +426,7 @@ public int hashCode(int index) {
425426
final int start = offsetBuffer.getInt(index * OFFSET_WIDTH);
426427
final int end = offsetBuffer.getInt((index + 1) * OFFSET_WIDTH);
427428
for (int i = start; i < end; i++) {
428-
hash = 31 * vector.hashCode(i);
429+
hash = ByteFunctionHelpers.comebineHash(hash, vector.hashCode(i));
429430
}
430431
return hash;
431432
}

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

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

2828
import org.apache.arrow.memory.BufferAllocator;
29+
import org.apache.arrow.memory.util.ByteFunctionHelpers;
2930
import org.apache.arrow.util.Preconditions;
3031
import org.apache.arrow.vector.DensityAwareVector;
3132
import org.apache.arrow.vector.FieldVector;
@@ -301,7 +302,7 @@ public int hashCode(int index) {
301302
for (String child : getChildFieldNames()) {
302303
ValueVector v = getChild(child);
303304
if (v != null && index < v.getValueCount()) {
304-
hash += 31 * hash + v.hashCode(index);
305+
hash = ByteFunctionHelpers.comebineHash(hash, v.hashCode(index));
305306
}
306307
}
307308
return hash;

0 commit comments

Comments
 (0)