XuQianJin-Stars commented on code in PR #3456:
URL: https://github.com/apache/fluss/pull/3456#discussion_r3402522018


##########
fluss-lake/fluss-lake-hudi/src/main/java/org/apache/fluss/lake/hudi/source/HudiSplitPlanner.java:
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.annotation.VisibleForTesting;
+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.Locale;
+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 = toHudiInstantTime(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()) {
+                if (hudiTableInfo.isPartitioned()) {
+                    LOG.debug(
+                            "No Hudi partition paths discovered for 
partitioned table {} at instant {}.",
+                            tablePath,
+                            snapshotTime);
+                    LOG.info(
+                            "Planned no Hudi splits for partitioned table {} 
at instant {} because no Hudi partition paths were discovered.",
+                            tablePath,
+                            snapshotTime);
+                    return Collections.emptyList();
+                } else {
+                    partitionPaths = Collections.singletonList("");
+                }
+            }
+
+            List<HudiSplit> splits = new ArrayList<>();
+            for (String partitionPath : partitionPaths) {
+                splits.addAll(planPartition(hudiTableInfo, snapshotTime, 
partitionPath));
+            }
+            if (splits.isEmpty()) {
+                LOG.info(
+                        "Planned no Hudi splits for table {} at instant {} 
across {} Hudi partition paths.",
+                        tablePath,
+                        snapshotTime,
+                        partitionPaths.size());
+            } else {
+                LOG.debug(
+                        "Planned {} Hudi splits for table {} at instant {}.",
+                        splits.size(),
+                        tablePath,
+                        snapshotTime);
+            }
+            return splits;
+        }
+    }
+
+    @VisibleForTesting
+    static String toHudiInstantTime(long snapshotId) {
+        return String.format(Locale.ROOT, "%017d", snapshotId);
+    }
+
+    private List<HudiSplit> planPartition(
+            HudiTableInfo hudiTableInfo, String snapshotTime, String 
partitionPath)
+            throws IOException {
+        HoodieTableFileSystemView fileSystemView = 
hudiTableInfo.getFileSystemView();
+        List<HudiSplit> splits = new ArrayList<>();
+        if (hudiTableInfo.getTableType() == HoodieTableType.MERGE_ON_READ) {

Review Comment:
   The MOR branch uses `getLatestMergedFileSlicesBeforeOrOn`, the COW branch 
uses `getLatestBaseFilesBeforeOrOn`. That's correct for COW. But the planner 
only dispatches on `tableType == MERGE_ON_READ`; everything else falls into the 
COW branch.
   
   Question: is **everything that is not exactly `MERGE_ON_READ` guaranteed to 
be COW** by Hudi's contract? `HoodieTableType` only has these two today, but a 
defensive `default → throw new IOException("Unsupported Hudi table type: " + 
...)` would future-proof this and avoids silently dropping log files if a new 
type is added. Suggest:
   
   ```java
   if (tableType == HoodieTableType.MERGE_ON_READ) { ... }
   else if (tableType == HoodieTableType.COPY_ON_WRITE) { ... }
   else { throw new IOException("Unsupported Hudi table type: " + tableType); }
   ```
   



##########
fluss-lake/fluss-lake-hudi/src/main/java/org/apache/fluss/lake/hudi/source/HudiSplitPlanner.java:
##########
@@ -0,0 +1,180 @@
+/*
+ * 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.annotation.VisibleForTesting;
+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.Locale;
+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 = toHudiInstantTime(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()) {
+                if (hudiTableInfo.isPartitioned()) {
+                    LOG.debug(
+                            "No Hudi partition paths discovered for 
partitioned table {} at instant {}.",
+                            tablePath,
+                            snapshotTime);
+                    LOG.info(
+                            "Planned no Hudi splits for partitioned table {} 
at instant {} because no Hudi partition paths were discovered.",
+                            tablePath,
+                            snapshotTime);
+                    return Collections.emptyList();
+                } else {
+                    partitionPaths = Collections.singletonList("");

Review Comment:
   - `L74–L77` logs at DEBUG and `L78–L81 `immediately logs almost the same 
content at INFO. The DEBUG line is dead weight — remove it, or merge them.
   
   - For a partitioned table where partitions truly haven't been created yet, 
returning empty splits silently is fine, but consider whether the caller 
(Flink/Spark) actually expects this vs. an IOException. At minimum, the INFO 
log should also include the table type so operators can tell "no partitions 
yet" from a misconfiguration.



-- 
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]

Reply via email to