diff --git a/docs/content/maintenance/manage-branches.md b/docs/content/maintenance/manage-branches.md index d1a45e962262d..87d0279719fb2 100644 --- a/docs/content/maintenance/manage-branches.md +++ b/docs/content/maintenance/manage-branches.md @@ -223,6 +223,20 @@ SELECT * FROM T; | 20240726 | pear | 6 | +------------------+------------------+--------+ */ + +-- reset fallback branch +ALTER TABLE T RESET ( 'scan.fallback-branch' ); + +-- now it only reads from default branch +SELECT * FROM T; +/* ++------------------+------------------+--------+ +| dt | name | amount | ++------------------+------------------+--------+ +| 20240725 | apple | 5 | +| 20240725 | banana | 7 | ++------------------+------------------+--------+ +*/ ``` {{< /tab >}} diff --git a/paimon-core/src/main/java/org/apache/paimon/table/FallbackReadFileStoreTable.java b/paimon-core/src/main/java/org/apache/paimon/table/FallbackReadFileStoreTable.java index d254c68806132..d26ce955a5970 100644 --- a/paimon-core/src/main/java/org/apache/paimon/table/FallbackReadFileStoreTable.java +++ b/paimon-core/src/main/java/org/apache/paimon/table/FallbackReadFileStoreTable.java @@ -60,6 +60,9 @@ public FallbackReadFileStoreTable(FileStoreTable main, FileStoreTable fallback) super(main); this.fallback = fallback; + Preconditions.checkArgument(!(main instanceof FallbackReadFileStoreTable)); + Preconditions.checkArgument(!(fallback instanceof FallbackReadFileStoreTable)); + String mainBranch = main.coreOptions().branch(); String fallbackBranch = fallback.coreOptions().branch(); RowType mainRowType = main.schema().logicalRowType(); diff --git a/paimon-core/src/main/java/org/apache/paimon/table/FileStoreTableFactory.java b/paimon-core/src/main/java/org/apache/paimon/table/FileStoreTableFactory.java index 74cc9fd35d780..a8764a751cc60 100644 --- a/paimon-core/src/main/java/org/apache/paimon/table/FileStoreTableFactory.java +++ b/paimon-core/src/main/java/org/apache/paimon/table/FileStoreTableFactory.java @@ -25,7 +25,6 @@ import org.apache.paimon.options.Options; import org.apache.paimon.schema.SchemaManager; import org.apache.paimon.schema.TableSchema; -import org.apache.paimon.utils.Preconditions; import org.apache.paimon.utils.StringUtils; import java.io.IOException; @@ -106,9 +105,6 @@ public static FileStoreTable create( new SchemaManager(fileIO, tablePath, fallbackBranch).latest().get(), branchOptions, catalogEnvironment); - - Preconditions.checkArgument(!(table instanceof FallbackReadFileStoreTable)); - Preconditions.checkArgument(!(fallbackTable instanceof FallbackReadFileStoreTable)); table = new FallbackReadFileStoreTable(table, fallbackTable); } diff --git a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/BranchSqlITCase.java b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/BranchSqlITCase.java index 8fd76616cbe6c..6ba0e4ebb93e5 100644 --- a/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/BranchSqlITCase.java +++ b/paimon-flink/paimon-flink-common/src/test/java/org/apache/paimon/flink/BranchSqlITCase.java @@ -338,6 +338,10 @@ public void testFallbackBranchBatchRead() throws Exception { assertThat(collectResult("SELECT v, k FROM t")) .containsExactlyInAnyOrder( "+I[apple, 10]", "+I[banana, 20]", "+I[lion, 10]", "+I[wolf, 20]"); + + sql("ALTER TABLE t RESET ( 'scan.fallback-branch' )"); + assertThat(collectResult("SELECT v, k FROM t")) + .containsExactlyInAnyOrder("+I[apple, 10]", "+I[banana, 20]"); } @Test