[ 
https://issues.apache.org/jira/browse/HUDI-1951?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17378125#comment-17378125
 ] 

ASF GitHub Bot commented on HUDI-1951:
--------------------------------------

leesf commented on a change in pull request #3173:
URL: https://github.com/apache/hudi/pull/3173#discussion_r667023267



##########
File path: 
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/utils/HiveBucketUtils.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.hudi.utils;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.regex.Pattern;
+
+import org.apache.hudi.common.fs.FSUtils;
+
+public class HiveBucketUtils {
+  private static final Pattern SPARK_BUCKET_NAME = 
Pattern.compile(".*_(\\d+)(?:\\..*)?$");
+
+  public static int mod(int x, int y) {
+    int r = x % y;
+    if (r < 0) {
+      return (r + y) % y;
+    } else {
+      return r;
+    }
+  }
+
+  public static int bucketId(String key, int numBuckets) {
+    return bucketId(Collections.singletonList(key), numBuckets);
+  }
+
+  // copied from spark HiveHashFunction class
+  // see 
https://code.byted.org/bytedance/spark/blob/branch-3.0-bd/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/hash.scala
+  public static int bucketId(List<Object> values, int numBuckets) {
+    int hash = 0;
+    for (Object value : values) {
+      hash = 31 * hash;
+      if (value == null) {
+        hash += 0;
+      } else if (value instanceof Boolean) {
+        hash += HiveHasher.hashInt(value.equals(Boolean.TRUE) ? 1 : 0);
+      } else if (value instanceof Integer) {
+        hash += HiveHasher.hashInt((Integer) value);
+      } else if (value instanceof Long) {
+        hash += HiveHasher.hashLong((Long) value);
+      } else if (value instanceof Float) {
+        hash += HiveHasher.hashInt(Float.floatToIntBits((Float) value));
+      } else if (value instanceof Double) {
+        hash += HiveHasher.hashLong(Double.doubleToLongBits((Double) value));
+      } else if (value instanceof String) {
+        byte[] a = value.toString().getBytes();
+        hash += HiveHasher.hashUnsafeBytes(a, 
HiveHasher.Platform.BYTE_ARRAY_OFFSET, a.length);
+      } else {
+        throw new RuntimeException("Unsupported type " + 
value.getClass().getName());
+      }
+    }
+    return mod(hash & Integer.MAX_VALUE, numBuckets);
+  }
+
+  // uuid 00499982-0f0d-473e-965d-e8a7476ec429

Review comment:
       remove this line?




-- 
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]


> Hash Index for HUDI
> -------------------
>
>                 Key: HUDI-1951
>                 URL: https://issues.apache.org/jira/browse/HUDI-1951
>             Project: Apache Hudi
>          Issue Type: New Feature
>            Reporter: XiaoyuGeng
>            Assignee: XiaoyuGeng
>            Priority: Major
>              Labels: pull-request-available
>
> https://cwiki.apache.org/confluence/display/HUDI/RFC+-+29%3A+Hash+Index



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to