KnightChess commented on code in PR #11578:
URL: https://github.com/apache/hudi/pull/11578#discussion_r1667596159


##########
hudi-common/src/main/java/org/apache/hudi/common/util/hash/BucketIndexUtil.java:
##########
@@ -0,0 +1,45 @@
+/*
+ * 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.common.util.hash;
+
+import org.apache.hudi.common.util.Functions;
+
+/**
+ * Utility class for bucket index.
+ */
+public class BucketIndexUtil {
+
+  /**
+   * This method is used to get the partition index calculation function of a 
bucket.
+   * "partition.hashCode() / (parallelism / bucketNum) * bucketNum" divides 
the parallelism into
+   * sub-intervals of length bucket_num, different partitions will be mapped 
to different sub-interval,
+   * ensure that the data across multiple partitions is evenly distributed.
+   *
+   * @param bucketNum   Bucket number per partition
+   * @param parallelism Parallelism of the task
+   * @return The partition index of this bucket.
+   */
+  public static Functions.Function2<String, Integer, Integer> 
getPartitionIndexFunc(int bucketNum, int parallelism) {
+    return (partition, curBucket) -> {
+      int partitionIndex = (partition.hashCode() & Integer.MAX_VALUE) % 
parallelism * bucketNum;
+      int globalIndex = partitionIndex + curBucket;

Review Comment:
   this test result from ut:
   - avg: total bucket file / parallelism, in this case, total bucket number is 
9 * bucketNumber
   - parallelism: task can max running parallelism
   - bucketNumber:
   - inlimit: match algorithm condition, fluctuate in the avg
   - outOflimit: 
   - real run parallelism size: the `partitionIndexFunc` value, which mean work 
index, and why it will bigger than parallelism in flink old logical, because it 
can be negative.
   
   use flink old logical, only the parallelism is twice bigger than 
bucketNumber work will.
   
   
   - avg : 18
   parallelism : 6
   bucketNumber : 12
   inlimit : [18]
   outOfLimit : [10, 8, 10, 8, 10, 8, 10, 8, 10, 8]
   real run parallelism size : 11
   ==================================
   avg : 21
   parallelism : 5
   bucketNumber : 12
   inlimit : [18]
   outOfLimit : [8, 12, 14, 12, 14, 8, 11, 11]
   real run parallelism size : 9
   ==================================
   avg : 4
   parallelism : 24
   bucketNumber : 12
   inlimit : [4, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 
2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
   outOfLimit : []
   real run parallelism size : 47
   ==================================
   avg : 4
   parallelism : 23
   bucketNumber : 12
   inlimit : [5, 4, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 
2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 2, 3, 3, 3, 2, 3, 2, 3, 2]
   outOfLimit : []
   real run parallelism size : 45
   ==================================
   avg : 0
   parallelism : 100
   bucketNumber : 5
   inlimit : []
   outOfLimit : [4, 4, 4, 4, 4, 5, 5, 5, 5, 5]
   real run parallelism size : 10
   ==================================
   
   after use fix logical in this pr:
   
   - avg : 18
   parallelism : 6
   bucketNumber : 12
   inlimit : [18, 18, 18, 18, 18, 18]
   outOfLimit : []
   real run parallelism size : 6
   ==================================
   avg : 21
   parallelism : 5
   bucketNumber : 12
   inlimit : [21, 21, 22, 22, 22]
   outOfLimit : []
   real run parallelism size : 5
   ==================================
   avg : 4
   parallelism : 24
   bucketNumber : 12
   inlimit : [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4]
   outOfLimit : []
   real run parallelism size : 24
   ==================================
   avg : 4
   parallelism : 23
   bucketNumber : 12
   inlimit : [4, 5, 5, 5, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 
4]
   outOfLimit : []
   real run parallelism size : 23
   ==================================
   avg : 0
   parallelism : 100
   bucketNumber : 5
   inlimit : [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
   outOfLimit : []
   real run parallelism size : 45
   ==================================



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

Reply via email to