kbendick commented on code in PR #5513:
URL: https://github.com/apache/iceberg/pull/5513#discussion_r945207053


##########
api/src/main/java/org/apache/iceberg/util/BucketUtil.java:
##########
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iceberg.util;
+
+import java.math.BigDecimal;
+import java.nio.ByteBuffer;
+import java.nio.charset.StandardCharsets;
+import java.util.UUID;
+import org.apache.iceberg.relocated.com.google.common.hash.HashFunction;
+import org.apache.iceberg.relocated.com.google.common.hash.Hashing;
+
+/**
+ * Contains the logic for hashing various types for use with the {@code 
bucket} partition
+ * transformations
+ */
+public class BucketUtil {
+
+  private static final HashFunction MURMUR3 = Hashing.murmur3_32_fixed();
+
+  private BucketUtil() {}
+
+  public static int hashInteger(Integer value) {
+    return MURMUR3.hashLong(value.longValue()).asInt();
+  }
+
+  public static int hashLong(Long value) {
+    return MURMUR3.hashLong(value).asInt();
+  }
+
+  public static int hashFloat(Float value) {
+    return MURMUR3.hashLong(Double.doubleToLongBits((double) value)).asInt();
+  }
+
+  public static int hashDouble(Double value) {
+    return MURMUR3.hashLong(Double.doubleToLongBits(value)).asInt();
+  }
+
+  public static int hashCharSequence(CharSequence value) {
+    return MURMUR3.hashString(value, StandardCharsets.UTF_8).asInt();
+  }
+
+  public static int hashByteBuffer(ByteBuffer value) {
+    if (value.hasArray()) {
+      return MURMUR3
+          .hashBytes(
+              value.array(),
+              value.arrayOffset() + value.position(),
+              value.arrayOffset() + value.remaining())

Review Comment:
   Yeah absolutely I'll add this test this evening.
   
   I was potentially going to use a different hash function for the byte[] that 
Spark passes (or investigate it at least), but I'll make this change this 
evening!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to