cshuo commented on code in PR #18074:
URL: https://github.com/apache/hudi/pull/18074#discussion_r2766884836
##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/source/HoodieSource.java:
##########
@@ -130,37 +141,76 @@ private SplitEnumerator<HoodieSourceSplit,
HoodieSplitEnumeratorState> createEnu
splitProvider = new DefaultHoodieSplitProvider(new
HoodieSourceSplitComparator());
} else {
LOG.info(
- "Hoodie source restored {} splits from state for table {}",
- enumeratorState.getPendingSplitStates().size(),
- metaClient.getTableConfig().getTableName());
+ "Hoodie source restored {} splits from state for table {}",
+ enumeratorState.getPendingSplitStates().size(),
+ metaClient.getTableConfig().getTableName());
List<HoodieSourceSplit> pendingSplits =
-
enumeratorState.getPendingSplitStates().stream().map(HoodieSourceSplitState::split).collect(Collectors.toList());
+
enumeratorState.getPendingSplitStates().stream().map(HoodieSourceSplitState::split).collect(Collectors.toList());
splitProvider = new DefaultHoodieSplitProvider();
splitProvider.onDiscoveredSplits(pendingSplits);
}
if (scanContext.isStreaming()) {
HoodieContinuousSplitDiscover discover = new DefaultHoodieSplitDiscover(
- scanContext, metaClient);
+ scanContext, metaClient);
return new HoodieContinuousSplitEnumerator(enumContext, splitProvider,
discover, scanContext, enumeratorState == null ? Option.empty() :
Option.of(enumeratorState));
} else {
if (enumeratorState == null) {
+ List<HoodieSourceSplit> splits = createBatchHoodieSplits();
+ splitProvider.onDiscoveredSplits(splits);
+ }
+ return new HoodieStaticSplitEnumerator(enumContext, splitProvider);
+ }
+ }
+
+ @VisibleForTesting
+ List<HoodieSourceSplit> createBatchHoodieSplits() {
+ final Configuration flinkConf = this.scanContext.getConf();
+ final String queryType = flinkConf.get(FlinkOptions.QUERY_TYPE);
+ switch (queryType) {
+ case FlinkOptions.QUERY_TYPE_SNAPSHOT:
+ final HoodieTableType tableType =
HoodieTableType.valueOf(flinkConf.get(FlinkOptions.TABLE_TYPE));
+ switch (tableType) {
+ case MERGE_ON_READ:
+ List<HoodieSourceSplit> splits =
SplitUtils.buildHoodieSplits(metaClient, flinkConf, createFileIndex());
+ if (splits.isEmpty()) {
+ // When there is no input splits, just return an empty source.
+ LOG.info("No input splits generate for MERGE_ON_READ input
format. Returning empty collection");
+ }
+ return splits;
+ case COPY_ON_WRITE:
+ return SplitUtils.baseFileOnlyHoodieSourceSplit(metaClient,
storagePath, createFileIndex(), flinkConf.get(FlinkOptions.MERGE_TYPE));
+ default:
+ throw new HoodieException("Unexpected table type: " +
flinkConf.get(FlinkOptions.TABLE_TYPE));
+ }
+ case FlinkOptions.QUERY_TYPE_READ_OPTIMIZED:
+ return SplitUtils.baseFileOnlyHoodieSourceSplit(metaClient,
storagePath, createFileIndex(), flinkConf.get(FlinkOptions.MERGE_TYPE));
+ case FlinkOptions.QUERY_TYPE_INCREMENTAL: {
Review Comment:
nit: remove bracket.
##########
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) {
Review Comment:
nit: baseFileOnlyHoodieSourceSplits
--
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]