This is an automated email from the ASF dual-hosted git repository.

lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new f67a43203 [core] Remove duplicates LookupCompaction (#2740)
f67a43203 is described below

commit f67a432032d436bbc479808f9a869899d820443f
Author: Zouxxyy <[email protected]>
AuthorDate: Fri Jan 19 15:27:57 2024 +0800

    [core] Remove duplicates LookupCompaction (#2740)
---
 .../paimon/mergetree/compact/CompactStrategy.java  |  4 +-
 .../paimon/mergetree/compact/LookupCompaction.java | 59 ----------------------
 .../paimon/operation/KeyValueFileStoreWrite.java   |  4 +-
 .../mergetree/compact/UniversalCompactionTest.java |  3 +-
 4 files changed, 6 insertions(+), 64 deletions(-)

diff --git 
a/paimon-core/src/main/java/org/apache/paimon/mergetree/compact/CompactStrategy.java
 
b/paimon-core/src/main/java/org/apache/paimon/mergetree/compact/CompactStrategy.java
index 33d43824b..90471d1ca 100644
--- 
a/paimon-core/src/main/java/org/apache/paimon/mergetree/compact/CompactStrategy.java
+++ 
b/paimon-core/src/main/java/org/apache/paimon/mergetree/compact/CompactStrategy.java
@@ -41,8 +41,8 @@ public interface CompactStrategy {
     /** Pick a compaction unit consisting of all existing files. */
     static Optional<CompactUnit> pickFullCompaction(int numLevels, 
List<LevelSortedRun> runs) {
         int maxLevel = numLevels - 1;
-        if (runs.size() == 1 && runs.get(0).level() == maxLevel) {
-            // only 1 sorted run on the max level, nothing to compact
+        if (runs.isEmpty() || (runs.size() == 1 && runs.get(0).level() == 
maxLevel)) {
+            // no sorted run or only 1 sorted run on the max level, no need to 
compact
             return Optional.empty();
         } else {
             return Optional.of(CompactUnit.fromLevelRuns(maxLevel, runs));
diff --git 
a/paimon-core/src/main/java/org/apache/paimon/mergetree/compact/LookupCompaction.java
 
b/paimon-core/src/main/java/org/apache/paimon/mergetree/compact/LookupCompaction.java
deleted file mode 100644
index 6434d616a..000000000
--- 
a/paimon-core/src/main/java/org/apache/paimon/mergetree/compact/LookupCompaction.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.mergetree.compact;
-
-import org.apache.paimon.compact.CompactUnit;
-import org.apache.paimon.mergetree.LevelSortedRun;
-
-import java.util.List;
-import java.util.Optional;
-
-/** A {@link CompactStrategy} to force compacting level 0 files. */
-public class LookupCompaction implements CompactStrategy {
-
-    private final UniversalCompaction universalCompaction;
-
-    public LookupCompaction(UniversalCompaction universalCompaction) {
-        this.universalCompaction = universalCompaction;
-    }
-
-    @Override
-    public Optional<CompactUnit> pick(int numLevels, List<LevelSortedRun> 
runs) {
-        Optional<CompactUnit> pick = universalCompaction.pick(numLevels, runs);
-        if (pick.isPresent()) {
-            return pick;
-        }
-
-        if (runs.isEmpty() || runs.get(0).level() > 0) {
-            return Optional.empty();
-        }
-
-        // collect all level 0 files
-        int candidateCount = 1;
-        for (int i = candidateCount; i < runs.size(); i++) {
-            if (runs.get(i).level() > 0) {
-                break;
-            }
-            candidateCount++;
-        }
-
-        return Optional.of(
-                universalCompaction.pickForSizeRatio(numLevels - 1, runs, 
candidateCount, true));
-    }
-}
diff --git 
a/paimon-core/src/main/java/org/apache/paimon/operation/KeyValueFileStoreWrite.java
 
b/paimon-core/src/main/java/org/apache/paimon/operation/KeyValueFileStoreWrite.java
index fd71dfce4..2f0872845 100644
--- 
a/paimon-core/src/main/java/org/apache/paimon/operation/KeyValueFileStoreWrite.java
+++ 
b/paimon-core/src/main/java/org/apache/paimon/operation/KeyValueFileStoreWrite.java
@@ -43,8 +43,8 @@ import org.apache.paimon.mergetree.MergeTreeWriter;
 import org.apache.paimon.mergetree.compact.CompactRewriter;
 import org.apache.paimon.mergetree.compact.CompactStrategy;
 import org.apache.paimon.mergetree.compact.FirstRowMergeTreeCompactRewriter;
+import org.apache.paimon.mergetree.compact.ForceUpLevel0Compaction;
 import 
org.apache.paimon.mergetree.compact.FullChangelogMergeTreeCompactRewriter;
-import org.apache.paimon.mergetree.compact.LookupCompaction;
 import org.apache.paimon.mergetree.compact.LookupMergeTreeCompactRewriter;
 import org.apache.paimon.mergetree.compact.MergeFunctionFactory;
 import org.apache.paimon.mergetree.compact.MergeTreeCompactManager;
@@ -160,7 +160,7 @@ public class KeyValueFileStoreWrite extends 
MemoryFileStoreWrite<KeyValue> {
                         options.optimizedCompactionInterval());
         CompactStrategy compactStrategy =
                 options.changelogProducer() == ChangelogProducer.LOOKUP
-                        ? new LookupCompaction(universalCompaction)
+                        ? new ForceUpLevel0Compaction(universalCompaction)
                         : universalCompaction;
         CompactManager compactManager =
                 createCompactManager(partition, bucket, compactStrategy, 
compactExecutor, levels);
diff --git 
a/paimon-core/src/test/java/org/apache/paimon/mergetree/compact/UniversalCompactionTest.java
 
b/paimon-core/src/test/java/org/apache/paimon/mergetree/compact/UniversalCompactionTest.java
index 328f2e7c4..747023b2e 100644
--- 
a/paimon-core/src/test/java/org/apache/paimon/mergetree/compact/UniversalCompactionTest.java
+++ 
b/paimon-core/src/test/java/org/apache/paimon/mergetree/compact/UniversalCompactionTest.java
@@ -266,7 +266,8 @@ public class UniversalCompactionTest {
 
     @Test
     public void testLookup() {
-        LookupCompaction compaction = new LookupCompaction(new 
UniversalCompaction(25, 1, 3));
+        ForceUpLevel0Compaction compaction =
+                new ForceUpLevel0Compaction(new UniversalCompaction(25, 1, 3));
 
         // level 0 to max level
         Optional<CompactUnit> pick = compaction.pick(3, level0(1, 2, 2, 2));

Reply via email to