wuwenchi commented on code in PR #7834:
URL: https://github.com/apache/hudi/pull/7834#discussion_r1157483229


##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/execution/bulkinsert/RDDSimpleBucketPartitioner.java:
##########
@@ -0,0 +1,106 @@
+/*
+ * 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.execution.bulkinsert;
+
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieRecordLocation;
+import org.apache.hudi.common.model.HoodieRecordPayload;
+import org.apache.hudi.common.util.ValidationUtils;
+import org.apache.hudi.index.bucket.BucketIdentifier;
+import org.apache.hudi.index.bucket.HoodieSimpleBucketIndex;
+import org.apache.hudi.table.HoodieTable;
+import org.apache.spark.Partitioner;
+import org.apache.spark.api.java.JavaRDD;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class RDDSimpleBucketPartitioner<T extends HoodieRecordPayload> extends 
RDDBucketIndexPartitioner<T> {
+
+  public RDDSimpleBucketPartitioner(HoodieTable table) {
+    super(table, null, false);
+    ValidationUtils.checkArgument(table.getIndex() instanceof 
HoodieSimpleBucketIndex);
+  }
+
+  @Override
+  public JavaRDD<HoodieRecord<T>> repartitionRecords(JavaRDD<HoodieRecord<T>> 
records, int outputPartitions) {
+    HoodieSimpleBucketIndex index = (HoodieSimpleBucketIndex) table.getIndex();
+    HashMap<String, Integer> fileIdToIdx = new HashMap<>();
+
+    // Map <partition, <bucketNo, fileID>>
+    Map<String, HashMap<Integer, String>> partitionMapper = 
getPartitionMapper(records, fileIdToIdx);
+
+    return doPartition(records, new Partitioner() {
+      @Override
+      public int numPartitions() {
+        return index.getNumBuckets() * partitionMapper.size();
+      }
+
+      @Override
+      public int getPartition(Object key) {
+        HoodieKey hoodieKey = (HoodieKey) key;
+        String partitionPath = hoodieKey.getPartitionPath();
+        int bucketID = index.getBucketID(hoodieKey);
+        String fileID = partitionMapper.get(partitionPath).get(bucketID);
+        return fileIdToIdx.get(fileID);
+      }
+    });
+  }
+
+  Map<String, HashMap<Integer, String>> 
getPartitionMapper(JavaRDD<HoodieRecord<T>> records,
+                                                           HashMap<String, 
Integer> fileIdToIdx) {
+
+    HoodieSimpleBucketIndex index = (HoodieSimpleBucketIndex) table.getIndex();
+    int numBuckets = index.getNumBuckets();
+    return records
+        .map(HoodieRecord::getPartitionPath)
+        .distinct().collect().stream()
+        .collect(Collectors.toMap(p -> p, p -> {
+          Map<Integer, HoodieRecordLocation> locationMap = 
index.loadPartitionBucketIdFileIdMapping(table, p);
+          HashMap<Integer, String> fileIdMap = new HashMap<>();

Review Comment:
   done



##########
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/execution/bulkinsert/RDDSimpleBucketPartitioner.java:
##########
@@ -0,0 +1,106 @@
+/*
+ * 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.execution.bulkinsert;
+
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.model.HoodieRecord;
+import org.apache.hudi.common.model.HoodieRecordLocation;
+import org.apache.hudi.common.model.HoodieRecordPayload;
+import org.apache.hudi.common.util.ValidationUtils;
+import org.apache.hudi.index.bucket.BucketIdentifier;
+import org.apache.hudi.index.bucket.HoodieSimpleBucketIndex;
+import org.apache.hudi.table.HoodieTable;
+import org.apache.spark.Partitioner;
+import org.apache.spark.api.java.JavaRDD;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+public class RDDSimpleBucketPartitioner<T extends HoodieRecordPayload> extends 
RDDBucketIndexPartitioner<T> {
+
+  public RDDSimpleBucketPartitioner(HoodieTable table) {
+    super(table, null, false);
+    ValidationUtils.checkArgument(table.getIndex() instanceof 
HoodieSimpleBucketIndex);
+  }
+
+  @Override
+  public JavaRDD<HoodieRecord<T>> repartitionRecords(JavaRDD<HoodieRecord<T>> 
records, int outputPartitions) {
+    HoodieSimpleBucketIndex index = (HoodieSimpleBucketIndex) table.getIndex();
+    HashMap<String, Integer> fileIdToIdx = new HashMap<>();
+
+    // Map <partition, <bucketNo, fileID>>
+    Map<String, HashMap<Integer, String>> partitionMapper = 
getPartitionMapper(records, fileIdToIdx);
+
+    return doPartition(records, new Partitioner() {
+      @Override
+      public int numPartitions() {
+        return index.getNumBuckets() * partitionMapper.size();
+      }
+
+      @Override
+      public int getPartition(Object key) {
+        HoodieKey hoodieKey = (HoodieKey) key;
+        String partitionPath = hoodieKey.getPartitionPath();
+        int bucketID = index.getBucketID(hoodieKey);
+        String fileID = partitionMapper.get(partitionPath).get(bucketID);
+        return fileIdToIdx.get(fileID);
+      }
+    });
+  }
+
+  Map<String, HashMap<Integer, String>> 
getPartitionMapper(JavaRDD<HoodieRecord<T>> records,
+                                                           HashMap<String, 
Integer> fileIdToIdx) {

Review Comment:
   done



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