HuangZhenQiu commented on code in PR #18074: URL: https://github.com/apache/hudi/pull/18074#discussion_r2767317224
########## hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/util/SplitUtils.java: ########## @@ -0,0 +1,142 @@ +/* + * 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.util; + +import org.apache.flink.configuration.Configuration; +import org.apache.hudi.common.model.BaseFile; +import org.apache.hudi.common.model.FileSlice; +import org.apache.hudi.common.model.HoodieFileGroupId; +import org.apache.hudi.common.model.HoodieLogFile; +import org.apache.hudi.common.table.HoodieTableMetaClient; +import org.apache.hudi.common.table.view.HoodieTableFileSystemView; +import org.apache.hudi.common.util.Option; +import org.apache.hudi.configuration.FlinkOptions; +import org.apache.hudi.exception.HoodieException; +import org.apache.hudi.source.FileIndex; +import org.apache.hudi.source.split.HoodieSourceSplit; +import org.apache.hudi.storage.StoragePath; +import org.apache.hudi.storage.StoragePathInfo; +import org.apache.hudi.table.format.FilePathUtils; +import org.apache.hudi.table.format.mor.MergeOnReadInputSplit; + +import java.util.Collections; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; + +import static org.apache.hudi.util.StreamerUtil.EMPTY_PARTITION_PATH; + +/** + * Utils for creating splits from file index. + */ +public class SplitUtils { + + /** + * Get the reader paths with partition path expanded. + */ + public static List<FileSlice> getBaseFileOnlyFileSlices(HoodieTableMetaClient metaClient, FileIndex fileIndex) { + List<String> relPartitionPaths = fileIndex.getOrBuildPartitionPaths(); + if (relPartitionPaths.isEmpty()) { + return Collections.emptyList(); + } + List<StoragePathInfo> pathInfoList = fileIndex.getFilesInPartitions(); + try (HoodieTableFileSystemView fsView = new HoodieTableFileSystemView(metaClient, + metaClient.getCommitsAndCompactionTimeline().filterCompletedAndCompactionInstants(), pathInfoList)) { + + List<FileSlice> allFileSlices = relPartitionPaths.stream() + .flatMap(par -> fsView.getLatestBaseFiles(par) + .map(baseFile -> new FileSlice(new HoodieFileGroupId(par, baseFile.getFileId()), baseFile.getCommitTime(), baseFile, Collections.emptyList()))) + .collect(Collectors.toList()); + return fileIndex.filterFileSlices(allFileSlices); + } + } + + public static List<HoodieSourceSplit> baseFileOnlyHoodieSourceSplit(HoodieTableMetaClient metaClient, StoragePath path, FileIndex fileIndex, String mergeType) { + final List<FileSlice> fileSlices = getBaseFileOnlyFileSlices(metaClient, fileIndex); + if (fileSlices.isEmpty()) { + return Collections.emptyList(); + } + + List<HoodieSourceSplit> hoodieSourceSplits = fileSlices.stream().filter(fileSlice -> fileSlice.getBaseFile().isPresent()).map(fileSlice -> + new HoodieSourceSplit( + HoodieSourceSplit.SPLIT_COUNTER.incrementAndGet(), + fileSlice.getBaseFile().get().getPath(), + Option.empty(), FilePathUtils.toFlinkPath(path).getPath(), + fileSlice.getPartitionPath(), mergeType, + fileSlice.getLatestInstantTime(), + fileSlice.getFileId()) + ).collect(Collectors.toList()); + + return hoodieSourceSplits; + } + + public static List<HoodieSourceSplit> buildHoodieSplits(HoodieTableMetaClient metaClient, Configuration conf, FileIndex fileIndex) { + List<MergeOnReadInputSplit> splits = buildInputSplits(metaClient, conf, fileIndex); + List<HoodieSourceSplit> hoodieSourceSplits = splits.stream().map(split -> + new HoodieSourceSplit( + HoodieSourceSplit.SPLIT_COUNTER.incrementAndGet(), + split.getBasePath().orElse(null), + split.getLogPaths(), split.getTablePath(), + EMPTY_PARTITION_PATH, split.getMergeType(), Review Comment: Yes, it is not used. I will remove it in a follow up PR. -- 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]
