zhangyue19921010 commented on code in PR #13017:
URL: https://github.com/apache/hudi/pull/13017#discussion_r2011358555
##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/sink/partitioner/BucketIndexPartitioner.java:
##########
@@ -33,22 +38,36 @@
*/
public class BucketIndexPartitioner<T extends HoodieKey> implements
Partitioner<T> {
- private final int bucketNum;
+ private final Configuration conf;
private final String indexKeyFields;
+ private final String hashingInstantToLoad;
+ private StorageConfiguration<org.apache.hadoop.conf.Configuration>
storageConf;
- private Functions.Function2<String, Integer, Integer> partitionIndexFunc;
+ private Functions.Function3<Integer, String, Integer, Integer>
partitionIndexFunc;
- public BucketIndexPartitioner(int bucketNum, String indexKeyFields) {
- this.bucketNum = bucketNum;
+ public BucketIndexPartitioner(Configuration conf, String indexKeyFields,
+
StorageConfiguration<org.apache.hadoop.conf.Configuration> storageConf) {
+ this.conf = conf;
this.indexKeyFields = indexKeyFields;
+ this.hashingInstantToLoad =
conf.get(FlinkOptions.BUCKET_INDEX_PARTITION_LOAD_INSTANT);
+ this.storageConf = storageConf;
}
@Override
public int partition(HoodieKey key, int numPartitions) {
if (this.partitionIndexFunc == null) {
- this.partitionIndexFunc =
BucketIndexUtil.getPartitionIndexFunc(bucketNum, numPartitions);
+ this.partitionIndexFunc =
BucketIndexUtil.getPartitionIndexFunc(numPartitions);
+ }
+
+ int bucketNum;
+ if (!StringUtils.isNullOrEmpty(hashingInstantToLoad)) {
+ org.apache.hadoop.conf.Configuration hadoopConf =
storageConf.unwrapAs(org.apache.hadoop.conf.Configuration.class);
+ PartitionBucketIndexCalculator calc =
PartitionBucketIndexCalculator.getInstance(hashingInstantToLoad, hadoopConf,
conf.get(FlinkOptions.PATH));
+ bucketNum = calc.computeNumBuckets(key.getPartitionPath());
+ } else {
+ bucketNum = conf.get(FlinkOptions.BUCKET_INDEX_NUM_BUCKETS);
}
int curBucket = BucketIdentifier.getBucketId(key.getRecordKey(),
indexKeyFields, bucketNum);
- return this.partitionIndexFunc.apply(key.getPartitionPath(), curBucket);
+ return this.partitionIndexFunc.apply(bucketNum, key.getPartitionPath(),
curBucket);
Review Comment:
add a new function NumBucketsFunction
--
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]