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



##########
File path: 
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/table/action/commit/SparkBucketIndexPartitioner.java
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.table.action.commit;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import scala.Tuple2;
+
+import org.apache.hudi.common.engine.HoodieEngineContext;
+import org.apache.hudi.common.model.HoodieKey;
+import org.apache.hudi.common.model.HoodieRecordLocation;
+import org.apache.hudi.common.model.HoodieRecordPayload;
+import org.apache.hudi.common.util.Option;
+import org.apache.hudi.common.util.collection.Pair;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.exception.HoodieException;
+import org.apache.hudi.index.bucket.SparkBucketIndex;
+import org.apache.hudi.table.HoodieTable;
+import org.apache.hudi.table.WorkloadProfile;
+import org.apache.hudi.table.WorkloadStat;
+import org.apache.hudi.utils.BucketUtils;
+
+/**
+ * TODO: pruning empty task partitions.
+ *
+ * @param <T>
+ */
+public class SparkBucketIndexPartitioner<T extends HoodieRecordPayload<T>> 
extends
+    SparkHoodiePartitioner<T> {
+
+  private final int numBuckets;
+  private final String hashFunction;
+  private final int totalPartitionPaths;
+  private final List<String> partitionPaths;
+  private final Map<String, Integer> partitionPathOffset;
+  private Map<String, Set<String>> updatePartitionPathFileIds;
+
+  public SparkBucketIndexPartitioner(WorkloadProfile profile,
+                                     HoodieEngineContext context,
+                                     HoodieTable table,
+                                     HoodieWriteConfig config) {
+    super(profile, table);
+    if (!(table.getIndex() instanceof SparkBucketIndex)) {
+      throw new HoodieException(
+          " Bucket index partitioner should only be used by BucketIndex other 
than "
+              + table.getIndex().getClass().getSimpleName());
+    }
+    this.numBuckets = ((SparkBucketIndex<T>) table.getIndex()).getNumBuckets();
+    this.hashFunction = config.getBucketIndexHashFunction();
+    this.totalPartitionPaths = profile.getPartitionPaths().size();
+    partitionPaths = new ArrayList<>(profile.getPartitionPaths());
+    partitionPathOffset = new HashMap<>();
+    int i = 0;
+    for (Object partitionPath : profile.getPartitionPaths()) {
+      partitionPathOffset.put(partitionPath.toString(), i);
+      i += numBuckets;
+    }
+    assignUpdates(profile);
+  }
+
+  private void assignUpdates(WorkloadProfile profile) {
+    updatePartitionPathFileIds = new HashMap<>();
+    // each update location gets a partition
+    Set<Entry<String, WorkloadStat>> partitionStatEntries = 
profile.getPartitionPathStatMap()
+        .entrySet();
+    for (Entry<String, WorkloadStat> partitionStat : partitionStatEntries) {
+      if (!updatePartitionPathFileIds.containsKey(partitionStat.getKey())) {
+        updatePartitionPathFileIds.put(partitionStat.getKey(), new 
HashSet<>());
+      }
+      for (Entry<String, Pair<String, Long>> updateLocEntry :
+          partitionStat.getValue().getUpdateLocationToCount().entrySet()) {
+        
updatePartitionPathFileIds.get(partitionStat.getKey()).add(updateLocEntry.getKey());
+      }
+    }
+  }
+
+  @Override
+  public BucketInfo getBucketInfo(int bucketNumber) {

Review comment:
       just so we are on same page or to confirm my understanding. This 
getBucketInfo(bucketNum) should be called only once per bucket for a 
non-existant bucket when doing partitioning for a write. If not, 
   ```
   BucketInfo(BucketType.INSERT, BucketUtils.newBucketFileIdPrefix(bucketId), 
partitionPath);
   ```
   this line, could create diff fileId for N number of calls for same bucket. 
since we prefix some random value to fileId apart from bucket Id, this is not 
idempotent for a given bucket. 
   Just wanted to call this out. 
   
   Let me know if my statement is not clear. I can give more context. 
   
   




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