JingsongLi commented on code in PR #6142: URL: https://github.com/apache/paimon/pull/6142#discussion_r2297580240
########## paimon-flink/paimon-flink-common/src/main/java/org/apache/paimon/flink/source/SuggestedTaskCalculator.java: ########## @@ -0,0 +1,96 @@ +/* + * 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.paimon.flink.source; + +import org.apache.paimon.CoreOptions; +import org.apache.paimon.flink.FlinkConnectorOptions; +import org.apache.paimon.options.Options; +import org.apache.paimon.table.BucketMode; +import org.apache.paimon.table.sink.ChannelComputer; +import org.apache.paimon.table.source.DataSplit; +import org.apache.paimon.utils.Preconditions; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * Given a {@link DataSplit}, calculate suggested task id for {@link ContinuousFileSplitEnumerator}. + */ +public interface SuggestedTaskCalculator { + + int suggest(DataSplit dataSplit, int parallelism); + + /** Calculate task id according to both bucket and partition. */ + class BucketAndPartitionCalculator implements SuggestedTaskCalculator { + + @Override + public int suggest(DataSplit dataSplit, int parallelism) { + return ChannelComputer.select(dataSplit.partition(), dataSplit.bucket(), parallelism); + } + } + + /** Calculate task id only considering bucket. */ + class BucketIgnorePartitionCalculator implements SuggestedTaskCalculator { + + @Override + public int suggest(DataSplit dataSplit, int parallelism) { + return ChannelComputer.select(dataSplit.bucket(), parallelism); + } + } + + /** + * Special {@link SuggestedTaskCalculator} for postpone bucket tables with no changelog + * producer. + */ + class PostponeBucketNoChangelogProducerCalculator implements SuggestedTaskCalculator { + + private final Pattern pattern; + + public PostponeBucketNoChangelogProducerCalculator() { + this.pattern = Pattern.compile("-s-(\\d+?)-"); + } + + @Override + public int suggest(DataSplit dataSplit, int parallelism) { + String fileName = dataSplit.dataFiles().get(0).fileName(); Review Comment: You should judge bucket of data split. -- 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]
