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

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

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



##########
File path: 
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/index/bucket/SparkBucketIndex.java
##########
@@ -0,0 +1,179 @@
+/*
+ * 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.index.bucket;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hudi.table.WorkloadProfile;
+import org.apache.hudi.table.action.commit.Partitioner;
+import org.apache.hudi.table.action.commit.SparkBucketIndexPartitioner;
+import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hudi.client.WriteStatus;
+import org.apache.hudi.common.engine.HoodieEngineContext;
+import org.apache.hudi.common.model.HoodieBaseFile;
+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.Option;
+import org.apache.hudi.common.util.collection.Triple;
+import org.apache.hudi.config.HoodieIndexConfig;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.exception.HoodieIndexException;
+import org.apache.hudi.index.HoodieIndexUtils;
+import org.apache.hudi.index.SparkHoodieIndex;
+import org.apache.hudi.table.HoodieTable;
+import org.apache.hudi.utils.BucketUtils;
+import org.apache.spark.api.java.JavaRDD;
+
+public class SparkBucketIndex<T extends HoodieRecordPayload> extends 
SparkHoodieIndex<T> {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(SparkBucketIndex.class);
+
+  private final int numBuckets;
+
+  public SparkBucketIndex(HoodieWriteConfig config) {
+    super(config);
+    String indexNumBucket = config.getProps()
+        .getProperty(HoodieIndexConfig.BUCKET_INDEX_BUCKET_NUM.key());
+    if (indexNumBucket == null) {
+      throw new IllegalArgumentException(
+          "Please set hoodie.index.hive.bucket.num or 
hoodie.table.numbuckets(deprecated) to a positive integer.");
+    }
+    this.numBuckets = Integer.parseInt(indexNumBucket);
+    LOG.info("use bucket index, numBuckets={}", numBuckets);
+  }
+
+  @Override
+  public JavaRDD<WriteStatus> updateLocation(JavaRDD<WriteStatus> 
writeStatusRDD,
+      HoodieEngineContext context,
+      HoodieTable<T, JavaRDD<HoodieRecord<T>>, JavaRDD<HoodieKey>, 
JavaRDD<WriteStatus>> hoodieTable)
+      throws HoodieIndexException {
+    return writeStatusRDD;
+  }
+
+  @Override
+  public JavaRDD<HoodieRecord<T>> tagLocation(JavaRDD<HoodieRecord<T>> records,
+      HoodieEngineContext context,
+      HoodieTable<T, JavaRDD<HoodieRecord<T>>, JavaRDD<HoodieKey>, 
JavaRDD<WriteStatus>> hoodieTable)
+      throws HoodieIndexException {
+    List<String> partitions = records.map(HoodieRecord::getPartitionPath)
+        .distinct().collect();
+    Map<String, Map<Integer, List<Triple<String, String, String>>>> 
partitionPathFileIDList =
+        loadPartitionBucketIdFileIdMapping(
+            context, hoodieTable, partitions);
+
+    if (partitionPathFileIDList.isEmpty()) {
+      // first write
+      return records;
+    }
+
+    JavaRDD<HoodieRecord<T>> taggedRecordRDD = records.map(record -> {
+      int bucketId = BucketUtils.bucketId(record.getKey().getIndexKey(), 
numBuckets);
+      String partitionPath = record.getPartitionPath();
+      if (partitionPathFileIDList.containsKey(partitionPath)) {
+        if (partitionPathFileIDList.get(partitionPath).containsKey(bucketId)) {
+          Triple<String, String, String> triple = partitionPathFileIDList
+              .get(partitionPath)
+              .get(bucketId).get(0);
+          String fileId = triple.getMiddle();
+          String instanceTime = triple.getRight();
+          HoodieRecordLocation loc = new HoodieRecordLocation(instanceTime, 
fileId);
+          return HoodieIndexUtils.getTaggedRecord(record, Option.of(loc));
+        }
+      }
+      return record;
+    });
+
+    return taggedRecordRDD;
+  }
+
+  @NotNull
+  private Map<String, Map<Integer, List<Triple<String, String, String>>>> 
loadPartitionBucketIdFileIdMapping(

Review comment:
       Please add a method comment explaining what the return value means

##########
File path: 
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/index/bucket/SparkBucketIndex.java
##########
@@ -0,0 +1,179 @@
+/*
+ * 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.index.bucket;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hudi.table.WorkloadProfile;
+import org.apache.hudi.table.action.commit.Partitioner;
+import org.apache.hudi.table.action.commit.SparkBucketIndexPartitioner;
+import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hudi.client.WriteStatus;
+import org.apache.hudi.common.engine.HoodieEngineContext;
+import org.apache.hudi.common.model.HoodieBaseFile;
+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.Option;
+import org.apache.hudi.common.util.collection.Triple;
+import org.apache.hudi.config.HoodieIndexConfig;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.exception.HoodieIndexException;
+import org.apache.hudi.index.HoodieIndexUtils;
+import org.apache.hudi.index.SparkHoodieIndex;
+import org.apache.hudi.table.HoodieTable;
+import org.apache.hudi.utils.BucketUtils;
+import org.apache.spark.api.java.JavaRDD;
+
+public class SparkBucketIndex<T extends HoodieRecordPayload> extends 
SparkHoodieIndex<T> {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(SparkBucketIndex.class);
+
+  private final int numBuckets;
+
+  public SparkBucketIndex(HoodieWriteConfig config) {
+    super(config);
+    String indexNumBucket = config.getProps()
+        .getProperty(HoodieIndexConfig.BUCKET_INDEX_BUCKET_NUM.key());
+    if (indexNumBucket == null) {
+      throw new IllegalArgumentException(
+          "Please set hoodie.index.hive.bucket.num or 
hoodie.table.numbuckets(deprecated) to a positive integer.");
+    }
+    this.numBuckets = Integer.parseInt(indexNumBucket);
+    LOG.info("use bucket index, numBuckets={}", numBuckets);
+  }
+
+  @Override
+  public JavaRDD<WriteStatus> updateLocation(JavaRDD<WriteStatus> 
writeStatusRDD,
+      HoodieEngineContext context,
+      HoodieTable<T, JavaRDD<HoodieRecord<T>>, JavaRDD<HoodieKey>, 
JavaRDD<WriteStatus>> hoodieTable)
+      throws HoodieIndexException {
+    return writeStatusRDD;
+  }
+
+  @Override
+  public JavaRDD<HoodieRecord<T>> tagLocation(JavaRDD<HoodieRecord<T>> records,
+      HoodieEngineContext context,
+      HoodieTable<T, JavaRDD<HoodieRecord<T>>, JavaRDD<HoodieKey>, 
JavaRDD<WriteStatus>> hoodieTable)
+      throws HoodieIndexException {
+    List<String> partitions = records.map(HoodieRecord::getPartitionPath)
+        .distinct().collect();
+    Map<String, Map<Integer, List<Triple<String, String, String>>>> 
partitionPathFileIDList =
+        loadPartitionBucketIdFileIdMapping(
+            context, hoodieTable, partitions);
+
+    if (partitionPathFileIDList.isEmpty()) {
+      // first write
+      return records;
+    }
+
+    JavaRDD<HoodieRecord<T>> taggedRecordRDD = records.map(record -> {

Review comment:
       Local variable 'taggedRecordRDD' is redundant.

##########
File path: 
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/table/action/commit/SparkBucketIndexPartitioner.java
##########
@@ -0,0 +1,126 @@
+/*
+ * 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 int totalPartitionPaths;
+  private final List<String> partitionPaths;
+  private final Map<String, Integer> partitionPathOffset;
+  private Map<String, Set<String>> partitionPathFileIds;

Review comment:
       Is it more appropriate to change this field's name to 
`updatePartitionPathFileIds`

##########
File path: 
hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/index/bucket/SparkBucketIndex.java
##########
@@ -0,0 +1,179 @@
+/*
+ * 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.index.bucket;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hudi.table.WorkloadProfile;
+import org.apache.hudi.table.action.commit.Partitioner;
+import org.apache.hudi.table.action.commit.SparkBucketIndexPartitioner;
+import org.jetbrains.annotations.NotNull;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.hudi.client.WriteStatus;
+import org.apache.hudi.common.engine.HoodieEngineContext;
+import org.apache.hudi.common.model.HoodieBaseFile;
+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.Option;
+import org.apache.hudi.common.util.collection.Triple;
+import org.apache.hudi.config.HoodieIndexConfig;
+import org.apache.hudi.config.HoodieWriteConfig;
+import org.apache.hudi.exception.HoodieIndexException;
+import org.apache.hudi.index.HoodieIndexUtils;
+import org.apache.hudi.index.SparkHoodieIndex;
+import org.apache.hudi.table.HoodieTable;
+import org.apache.hudi.utils.BucketUtils;
+import org.apache.spark.api.java.JavaRDD;
+
+public class SparkBucketIndex<T extends HoodieRecordPayload> extends 
SparkHoodieIndex<T> {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(SparkBucketIndex.class);
+
+  private final int numBuckets;
+
+  public SparkBucketIndex(HoodieWriteConfig config) {
+    super(config);
+    String indexNumBucket = config.getProps()
+        .getProperty(HoodieIndexConfig.BUCKET_INDEX_BUCKET_NUM.key());
+    if (indexNumBucket == null) {
+      throw new IllegalArgumentException(
+          "Please set hoodie.index.hive.bucket.num or 
hoodie.table.numbuckets(deprecated) to a positive integer.");
+    }
+    this.numBuckets = Integer.parseInt(indexNumBucket);
+    LOG.info("use bucket index, numBuckets={}", numBuckets);
+  }
+
+  @Override
+  public JavaRDD<WriteStatus> updateLocation(JavaRDD<WriteStatus> 
writeStatusRDD,
+      HoodieEngineContext context,
+      HoodieTable<T, JavaRDD<HoodieRecord<T>>, JavaRDD<HoodieKey>, 
JavaRDD<WriteStatus>> hoodieTable)
+      throws HoodieIndexException {
+    return writeStatusRDD;
+  }
+
+  @Override
+  public JavaRDD<HoodieRecord<T>> tagLocation(JavaRDD<HoodieRecord<T>> records,
+      HoodieEngineContext context,
+      HoodieTable<T, JavaRDD<HoodieRecord<T>>, JavaRDD<HoodieKey>, 
JavaRDD<WriteStatus>> hoodieTable)
+      throws HoodieIndexException {
+    List<String> partitions = records.map(HoodieRecord::getPartitionPath)
+        .distinct().collect();
+    Map<String, Map<Integer, List<Triple<String, String, String>>>> 
partitionPathFileIDList =
+        loadPartitionBucketIdFileIdMapping(
+            context, hoodieTable, partitions);
+
+    if (partitionPathFileIDList.isEmpty()) {
+      // first write
+      return records;
+    }
+
+    JavaRDD<HoodieRecord<T>> taggedRecordRDD = records.map(record -> {
+      int bucketId = BucketUtils.bucketId(record.getKey().getIndexKey(), 
numBuckets);
+      String partitionPath = record.getPartitionPath();
+      if (partitionPathFileIDList.containsKey(partitionPath)) {
+        if (partitionPathFileIDList.get(partitionPath).containsKey(bucketId)) {
+          Triple<String, String, String> triple = partitionPathFileIDList
+              .get(partitionPath)
+              .get(bucketId).get(0);
+          String fileId = triple.getMiddle();
+          String instanceTime = triple.getRight();
+          HoodieRecordLocation loc = new HoodieRecordLocation(instanceTime, 
fileId);
+          return HoodieIndexUtils.getTaggedRecord(record, Option.of(loc));
+        }
+      }
+      return record;
+    });
+
+    return taggedRecordRDD;
+  }
+
+  @NotNull
+  private Map<String, Map<Integer, List<Triple<String, String, String>>>> 
loadPartitionBucketIdFileIdMapping(

Review comment:
       It looks like the return type of this method should be `Map<String, 
Map<Integer, Pair<String, String>>>`

##########
File path: 
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/keygen/ComplexAvroKeyGenerator.java
##########
@@ -47,4 +52,9 @@ public String getRecordKey(GenericRecord record) {
   public String getPartitionPath(GenericRecord record) {
     return KeyGenUtils.getRecordPartitionPath(record, 
getPartitionPathFields(), hiveStylePartitioning, encodePartitionPath);
   }
+
+  @Override
+  public List<Object> getIndexKey(GenericRecord record) {
+    return KeyGenUtils.getIndexKey(record, getIndexKeyFields());

Review comment:
       Can we try to move this part into the parent class as the default 
implementation




-- 
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: commits-unsubscr...@hudi.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> 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