JingsongLi commented on code in PR #6038:
URL: https://github.com/apache/paimon/pull/6038#discussion_r2262006472


##########
paimon-core/src/main/java/org/apache/paimon/table/source/RowLineageSplitGenerator.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.paimon.table.source;
+
+import org.apache.paimon.io.DataFileMeta;
+import org.apache.paimon.utils.BinPacking;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.function.Function;
+import java.util.function.ToLongFunction;
+import java.util.stream.Collectors;
+
+/** Append only implementation of {@link SplitGenerator}. */
+public class RowLineageSplitGenerator implements SplitGenerator {
+
+    private final long targetSplitSize;
+    private final long openFileCost;
+
+    public RowLineageSplitGenerator(long targetSplitSize, long openFileCost) {
+        this.targetSplitSize = targetSplitSize;
+        this.openFileCost = openFileCost;
+    }
+
+    @Override
+    public boolean alwaysRawConvertible() {
+        return true;
+    }
+
+    @Override
+    public List<SplitGroup> splitForBatch(List<DataFileMeta> input) {
+        List<List<DataFileMeta>> files = split(input);
+        Function<List<DataFileMeta>, Long> weightFunc =
+                file ->
+                        Math.max(
+                                
file.stream().mapToLong(DataFileMeta::fileSize).sum(),
+                                openFileCost);
+        return BinPacking.packForOrdered(files, weightFunc, 
targetSplitSize).stream()
+                .flatMap(Collection::stream)
+                .map(SplitGroup::rawConvertibleGroup)
+                .collect(Collectors.toList());
+    }
+
+    @Override
+    public List<SplitGroup> splitForStreaming(List<DataFileMeta> files) {
+        return splitForBatch(files);
+    }
+
+    public static List<List<DataFileMeta>> split(List<DataFileMeta> files) {
+        List<List<DataFileMeta>> splitByRowId = new ArrayList<>();
+        // Sort files by firstRowId and then by maxSequenceNumber
+        files.sort(
+                Comparator.comparingLong(
+                                (ToLongFunction<DataFileMeta>)
+                                        value ->
+                                                value.firstRowId() == null
+                                                        ? Long.MIN_VALUE
+                                                        : value.firstRowId())
+                        .thenComparing(
+                                (f1, f2) -> {
+                                    // If firstRowId is the same, we should 
read the file with
+                                    // larger sequence number first. Because 
larger sequence number
+                                    // file is more fresh
+                                    return Long.compare(
+                                            f2.maxSequenceNumber(), 
f1.maxSequenceNumber());
+                                }));
+
+        // Split files by firstRowId
+        long lastRowId = -1;

Review Comment:
   Should throw exception for exception case.



-- 
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: issues-unsubscr...@paimon.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to