fhan688 commented on code in PR #3456: URL: https://github.com/apache/fluss/pull/3456#discussion_r3400708746
########## fluss-lake/fluss-lake-hudi/src/main/java/org/apache/fluss/lake/hudi/source/HudiSplitPlanner.java: ########## @@ -0,0 +1,157 @@ +/* + * 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.fluss.lake.hudi.source; + +import org.apache.fluss.config.Configuration; +import org.apache.fluss.lake.hudi.utils.HudiTableInfo; +import org.apache.fluss.lake.source.Planner; +import org.apache.fluss.metadata.TablePath; + +import org.apache.hudi.common.fs.FSUtils; +import org.apache.hudi.common.model.FileSlice; +import org.apache.hudi.common.model.HoodieBaseFile; +import org.apache.hudi.common.model.HoodieFileGroupId; +import org.apache.hudi.common.model.HoodieTableType; +import org.apache.hudi.common.table.view.HoodieTableFileSystemView; +import org.apache.hudi.index.bucket.BucketIdentifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; + +/** Planner for creating Hudi splits. */ +public class HudiSplitPlanner implements Planner<HudiSplit> { + + private static final Logger LOG = LoggerFactory.getLogger(HudiSplitPlanner.class); + + private final Configuration hudiConfig; + private final TablePath tablePath; + private final long snapshotId; + + public HudiSplitPlanner(Configuration hudiConfig, TablePath tablePath, long snapshotId) { + this.hudiConfig = hudiConfig; + this.tablePath = tablePath; + this.snapshotId = snapshotId; + } + + @Override + public List<HudiSplit> plan() throws IOException { + String snapshotTime = String.valueOf(snapshotId); + try (HudiTableInfo hudiTableInfo = HudiTableInfo.create(tablePath, hudiConfig)) { + if (!hudiTableInfo.getCompletedTimeline().containsInstant(snapshotTime)) { + throw new IOException( + String.format( + "Hudi instant time %s does not exist in table %s.", + snapshotTime, tablePath)); + } + + List<String> partitionPaths = + FSUtils.getAllPartitionPaths( + hudiTableInfo.getEngineContext(), hudiTableInfo.getMetaClient(), false); + if (partitionPaths.isEmpty()) { + partitionPaths = Collections.singletonList(""); + } + + List<HudiSplit> splits = new ArrayList<>(); + for (String partitionPath : partitionPaths) { + splits.addAll(planPartition(hudiTableInfo, snapshotTime, partitionPath)); + } + LOG.debug( + "Planned {} Hudi splits for table {} at instant {}.", + splits.size(), + tablePath, + snapshotTime); + return splits; + } catch (IOException e) { Review Comment: > The first catch is redundant, and the second one converts every `RuntimeException` (e.g. `IllegalStateException`, `HoodieException`) into an `IOException`, hiding the original type and making operational diagnosis harder. Thanks for pointing this out. I removed the redundant catch blocks `in HudiSplitPlanner#plan()`. `IOException` is now propagated directly by the method signature, and unchecked Hudi/runtime exceptions are no longer wrapped into `IOException`, so their original types are preserved for diagnosis. -- 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]
