From cbd4f7aed65e0057e23256a7478570efcb8127df Mon Sep 17 00:00:00 2001 From: Vibhatha Lakmal Abeykoon <vibhatha@gmail.com> Date: Mon, 2 Sep 2024 10:07:35 +0530 Subject: [PATCH] fix: adding hashcode usage changes in vectors --- .../org/apache/arrow/memory/util/ByteFunctionHelpers.java | 6 +++--- .../java/org/apache/arrow/vector/BaseFixedWidthVector.java | 2 +- .../apache/arrow/vector/BaseLargeVariableWidthVector.java | 2 +- .../org/apache/arrow/vector/BaseVariableWidthVector.java | 2 +- .../apache/arrow/vector/BaseVariableWidthViewVector.java | 4 ++-- .../apache/arrow/vector/complex/FixedSizeListVector.java | 4 +++- .../org/apache/arrow/vector/complex/LargeListVector.java | 3 ++- .../apache/arrow/vector/complex/LargeListViewVector.java | 3 ++- .../java/org/apache/arrow/vector/complex/ListVector.java | 2 +- .../org/apache/arrow/vector/complex/ListViewVector.java | 2 +- .../arrow/vector/complex/NonNullableStructVector.java | 2 +- 11 files changed, 18 insertions(+), 14 deletions(-) diff --git a/java/memory/memory-core/src/main/java/org/apache/arrow/memory/util/ByteFunctionHelpers.java b/java/memory/memory-core/src/main/java/org/apache/arrow/memory/util/ByteFunctionHelpers.java index a91b55cb4552e..1e5f3a6f732b5 100644 --- a/java/memory/memory-core/src/main/java/org/apache/arrow/memory/util/ByteFunctionHelpers.java +++ b/java/memory/memory-core/src/main/java/org/apache/arrow/memory/util/ByteFunctionHelpers.java @@ -295,7 +295,7 @@ private static int memcmp( } /** Compute hashCode with the given {@link ArrowBuf} and start/end index. */ - public static int hash(final ArrowBuf buf, long start, long end) { + public static long hash(final ArrowBuf buf, long start, long end) { return hash(SimpleHasher.INSTANCE, buf, start, end); } @@ -303,7 +303,7 @@ public static int hash(final ArrowBuf buf, long start, long end) { /** * Compute hashCode with the given {@link ArrowBufHasher}, {@link ArrowBuf} and start/end index. */ - public static final int hash(ArrowBufHasher hasher, final ArrowBuf buf, long start, long end) { + public static final long hash(ArrowBufHasher hasher, final ArrowBuf buf, long start, long end) { if (hasher == null) { hasher = SimpleHasher.INSTANCE; @@ -313,7 +313,7 @@ public static final int hash(ArrowBufHasher hasher, final ArrowBuf buf, long sta } /** Generate a new hashCode with the given current hashCode and new hashCode. */ - public static int combineHash(int currentHash, int newHash) { + public static long combineHash(long currentHash, long newHash) { return currentHash * 31 + newHash; } } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java index 4be55396b7492..1855c0f0f3f02 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BaseFixedWidthVector.java @@ -950,7 +950,7 @@ public int hashCode(int index, ArrowBufHasher hasher) { } long start = (long) typeWidth * index; long end = (long) typeWidth * (index + 1); - return ByteFunctionHelpers.hash(hasher, this.getDataBuffer(), start, end); + return (int) ByteFunctionHelpers.hash(hasher, this.getDataBuffer(), start, end); } @Override diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BaseLargeVariableWidthVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BaseLargeVariableWidthVector.java index 552a896ea8c36..6c28a94928865 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BaseLargeVariableWidthVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BaseLargeVariableWidthVector.java @@ -1436,7 +1436,7 @@ public int hashCode(int index, ArrowBufHasher hasher) { } final long start = getStartOffset(index); final long end = getEndOffset(index); - return ByteFunctionHelpers.hash(hasher, this.getDataBuffer(), start, end); + return (int) ByteFunctionHelpers.hash(hasher, this.getDataBuffer(), start, end); } @Override diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthVector.java index aaccec602f292..20f9995db706a 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthVector.java @@ -1485,7 +1485,7 @@ public int hashCode(int index, ArrowBufHasher hasher) { } final int start = getStartOffset(index); final int end = getEndOffset(index); - return ByteFunctionHelpers.hash(hasher, this.getDataBuffer(), start, end); + return (int) ByteFunctionHelpers.hash(hasher, this.getDataBuffer(), start, end); } @Override diff --git a/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java b/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java index aee5233f9d466..253eddc8d6fbf 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/BaseVariableWidthViewVector.java @@ -1600,7 +1600,7 @@ public int hashCode(int index, ArrowBufHasher hasher) { final int length = getValueLength(index); if (length < INLINE_SIZE) { int start = index * ELEMENT_SIZE + LENGTH_WIDTH; - return ByteFunctionHelpers.hash(hasher, this.getDataBuffer(), start, start + length); + return (int) ByteFunctionHelpers.hash(hasher, this.getDataBuffer(), start, start + length); } else { final int bufIndex = viewBuffer.getInt(((long) index * ELEMENT_SIZE) + LENGTH_WIDTH + PREFIX_WIDTH); @@ -1608,7 +1608,7 @@ public int hashCode(int index, ArrowBufHasher hasher) { viewBuffer.getInt( ((long) index * ELEMENT_SIZE) + LENGTH_WIDTH + PREFIX_WIDTH + BUF_INDEX_WIDTH); ArrowBuf dataBuf = dataBuffers.get(bufIndex); - return ByteFunctionHelpers.hash(hasher, dataBuf, dataOffset, dataOffset + length); + return (int) ByteFunctionHelpers.hash(hasher, dataBuf, dataOffset, dataOffset + length); } } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java index c762eb51725ca..a4c24d5f92dbd 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/FixedSizeListVector.java @@ -578,7 +578,9 @@ public int hashCode(int index, ArrowBufHasher hasher) { } int hash = 0; for (int i = 0; i < listSize; i++) { - hash = ByteFunctionHelpers.combineHash(hash, vector.hashCode(index * listSize + i, hasher)); + hash = + (int) + ByteFunctionHelpers.combineHash(hash, vector.hashCode(index * listSize + i, hasher)); } return hash; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/LargeListVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/LargeListVector.java index ed075352c931c..04539be359498 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/LargeListVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/LargeListVector.java @@ -588,7 +588,8 @@ public int hashCode(int index, ArrowBufHasher hasher) { final long start = offsetBuffer.getLong((long) index * OFFSET_WIDTH); final long end = offsetBuffer.getLong(((long) index + 1L) * OFFSET_WIDTH); for (long i = start; i < end; i++) { - hash = ByteFunctionHelpers.combineHash(hash, vector.hashCode(checkedCastToInt(i), hasher)); + hash = + (int) ByteFunctionHelpers.combineHash(hash, vector.hashCode(checkedCastToInt(i), hasher)); } return hash; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/LargeListViewVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/LargeListViewVector.java index 84c6f03edb25d..50a782c775c8d 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/LargeListViewVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/LargeListViewVector.java @@ -442,7 +442,8 @@ public int hashCode(int index, ArrowBufHasher hasher) { final int start = offsetBuffer.getInt((long) index * OFFSET_WIDTH); final int end = sizeBuffer.getInt((long) index * OFFSET_WIDTH); for (int i = start; i < end; i++) { - hash = ByteFunctionHelpers.combineHash(hash, vector.hashCode(checkedCastToInt(i), hasher)); + hash = + (int) ByteFunctionHelpers.combineHash(hash, vector.hashCode(checkedCastToInt(i), hasher)); } return hash; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java index 76682c28fe65d..b197852c62d3c 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/ListVector.java @@ -488,7 +488,7 @@ public int hashCode(int index, ArrowBufHasher hasher) { final int start = offsetBuffer.getInt(index * OFFSET_WIDTH); final int end = offsetBuffer.getInt((index + 1) * OFFSET_WIDTH); for (int i = start; i < end; i++) { - hash = ByteFunctionHelpers.combineHash(hash, vector.hashCode(i, hasher)); + hash = (int) ByteFunctionHelpers.combineHash(hash, vector.hashCode(i, hasher)); } return hash; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/ListViewVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/ListViewVector.java index 9b4e6b4c0cd4a..71944910fb2aa 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/ListViewVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/ListViewVector.java @@ -449,7 +449,7 @@ public int hashCode(int index, ArrowBufHasher hasher) { final int start = offsetBuffer.getInt(index * OFFSET_WIDTH); final int end = sizeBuffer.getInt(index * OFFSET_WIDTH); for (int i = start; i < end; i++) { - hash = ByteFunctionHelpers.combineHash(hash, vector.hashCode(i, hasher)); + hash = (int) ByteFunctionHelpers.combineHash(hash, vector.hashCode(i, hasher)); } return hash; } diff --git a/java/vector/src/main/java/org/apache/arrow/vector/complex/NonNullableStructVector.java b/java/vector/src/main/java/org/apache/arrow/vector/complex/NonNullableStructVector.java index 5a215608ef64b..bbd4bb695228e 100644 --- a/java/vector/src/main/java/org/apache/arrow/vector/complex/NonNullableStructVector.java +++ b/java/vector/src/main/java/org/apache/arrow/vector/complex/NonNullableStructVector.java @@ -401,7 +401,7 @@ public int hashCode(int index, ArrowBufHasher hasher) { int hash = 0; for (FieldVector v : getChildren()) { if (index < v.getValueCount()) { - hash = ByteFunctionHelpers.combineHash(hash, v.hashCode(index, hasher)); + hash = (int) ByteFunctionHelpers.combineHash(hash, v.hashCode(index, hasher)); } } return hash;