fhan688 commented on code in PR #3456: URL: https://github.com/apache/fluss/pull/3456#discussion_r3400712253
########## 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); Review Comment: > Hudi instant time is a string (canonical format is a 17-digit timestamp like `20260608010101000`). Round-tripping it through a `long` and then `String.valueOf` will drop any leading zeros. Today, Hudi writes don't normally produce leading-zero instants, but repaired or imported tables can. Note also that `LakeSource.PlannerContext#snapshotId()` returning `long` is itself a lossy carrier for Hudi. > > * Document the constraint that Hudi `snapshotId`s must not have leading zeros. > * Or use `String.format("%017d", snapshotId)` to enforce the 17-digit instant format. > * Add a "leading-zero instant" case to `HudiSplitPlannerTest`. Good point. Since `LakeSource.PlannerContext#snapshotId()` currently carries the lake snapshot as long, this PR cannot fully preserve arbitrary Hudi instant strings without changing the common source API. As a low-risk fix, I now format the snapshot id as a canonical 17-digit Hudi instant via `String.format(Locale.ROOT, "%017d", snapshotId)`, and added a planner test covering a leading-zero 17-digit instant. If we need to support non-canonical/imported instant strings beyond this, I think the follow-up should extend the lake snapshot carrier to preserve the original string value. -- 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]
