stream2000 commented on code in PR #9199: URL: https://github.com/apache/hudi/pull/9199#discussion_r1273148438
########## hudi-client/hudi-spark-client/src/main/java/org/apache/hudi/execution/bulkinsert/ConsistentBucketIndexBulkInsertPartitionerWithRows.java: ########## @@ -0,0 +1,154 @@ +/* + * 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.ConsistentHashingNode; +import org.apache.hudi.common.model.HoodieConsistentHashingMetadata; +import org.apache.hudi.common.model.HoodieTableType; +import org.apache.hudi.common.util.Option; +import org.apache.hudi.common.util.ValidationUtils; +import org.apache.hudi.index.bucket.ConsistentBucketIdentifier; +import org.apache.hudi.index.bucket.ConsistentBucketIndexUtils; +import org.apache.hudi.index.bucket.HoodieSparkConsistentBucketIndex; +import org.apache.hudi.keygen.BuiltinKeyGenerator; +import org.apache.hudi.keygen.factory.HoodieSparkKeyGeneratorFactory; +import org.apache.hudi.table.BulkInsertPartitioner; +import org.apache.hudi.table.ConsistentHashingBucketInsertPartitioner; +import org.apache.hudi.table.HoodieTable; + +import org.apache.spark.Partitioner; +import org.apache.spark.api.java.JavaRDD; +import org.apache.spark.sql.Dataset; +import org.apache.spark.sql.Row; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import scala.Tuple2; + +/** + * Bulk_insert partitioner of Spark row using consistent hashing bucket index. + */ +public class ConsistentBucketIndexBulkInsertPartitionerWithRows + implements BulkInsertPartitioner<Dataset<Row>>, ConsistentHashingBucketInsertPartitioner { + + private final HoodieTable table; + + private final String indexKeyFields; + + private final List<String> fileIdPfxList = new ArrayList<>(); + private final Map<String, List<ConsistentHashingNode>> hashingChildrenNodes; + + private Map<String, ConsistentBucketIdentifier> partitionToIdentifier; + + private final Option<BuiltinKeyGenerator> keyGeneratorOpt; + + private Map<String, Map<String, Integer>> partitionToFileIdPfxIdxMap; + + private final RowRecordKeyExtractor extractor; + + public ConsistentBucketIndexBulkInsertPartitionerWithRows(HoodieTable table, boolean populateMetaFields) { + this.indexKeyFields = table.getConfig().getBucketIndexHashField(); + this.table = table; + this.hashingChildrenNodes = new HashMap<>(); + if (!populateMetaFields) { + this.keyGeneratorOpt = HoodieSparkKeyGeneratorFactory.getKeyGenerator(table.getConfig().getProps()); + } else { + this.keyGeneratorOpt = Option.empty(); + } + this.extractor = RowRecordKeyExtractor.getRowRecordKeyExtractor(populateMetaFields, keyGeneratorOpt); + ValidationUtils.checkArgument(table.getMetaClient().getTableType().equals(HoodieTableType.MERGE_ON_READ), Review Comment: Yes, we do dual write during consistent hashing bucket index resizing but CoW table do not support writing logs. And It's a little bit hard to move it to parent class since the closest parent class for these two ConsistentHashingPartitioner is `BulkInsertPartitioner` -- 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]
