yuzelin commented on code in PR #755:
URL: https://github.com/apache/incubator-paimon/pull/755#discussion_r1151559656


##########
paimon-core/src/main/java/org/apache/paimon/append/AppendOnlyCompactManager.java:
##########
@@ -301,4 +302,39 @@ public List<DataFileMeta> after() {
     public interface CompactRewriter {
         List<DataFileMeta> rewrite(List<DataFileMeta> compactBefore) throws 
Exception;
     }
+
+    /**
+     * New files may be created during the compaction process, then the 
results of the compaction
+     * may be put after the new files, and this order will be disrupted. We 
need to ensure this
+     * order, so we force the order by sequence.
+     */
+    public static List<DataFileMeta> sortFiles(Collection<DataFileMeta> input) 
{
+        List<DataFileMeta> files = new ArrayList<>(input);
+        files.sort(
+                (o1, o2) -> {
+                    if (isOverlap(o1, o2)) {
+                        throw new RuntimeException(
+                                String.format(
+                                        "There should no overlap in append 
files, there is a bug!"
+                                                + " Range1(%s, %s), Range2(%s, 
%s)",
+                                        o1.minSequenceNumber(),
+                                        o1.maxSequenceNumber(),
+                                        o2.minSequenceNumber(),
+                                        o2.maxSequenceNumber()));
+                    }
+
+                    return Long.compare(o1.minSequenceNumber(), 
o2.minSequenceNumber());
+                });
+        return files;
+    }
+
+    private static boolean isOverlap(DataFileMeta o1, DataFileMeta o2) {
+        if (o1.minSequenceNumber() <= o2.maxSequenceNumber()
+                && o1.maxSequenceNumber() >= o2.minSequenceNumber()) {
+            return true;
+        }

Review Comment:
   Duplicated.



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