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/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new e083825f5 [core] Manifest table query throw exception with range of 
snapshot when snapshot id not exist (#4145)
e083825f5 is described below

commit e083825f5b6fa704c321f4802ce27b8571548deb
Author: xuzifu666 <[email protected]>
AuthorDate: Tue Sep 10 11:52:23 2024 +0800

    [core] Manifest table query throw exception with range of snapshot when 
snapshot id not exist (#4145)
---
 .../java/org/apache/paimon/table/system/ManifestsTable.java  | 12 +++++++++++-
 .../org/apache/paimon/table/system/ManifestsTableTest.java   |  8 ++++++--
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git 
a/paimon-core/src/main/java/org/apache/paimon/table/system/ManifestsTable.java 
b/paimon-core/src/main/java/org/apache/paimon/table/system/ManifestsTable.java
index 6184dbdad..0c7d36d5e 100644
--- 
a/paimon-core/src/main/java/org/apache/paimon/table/system/ManifestsTable.java
+++ 
b/paimon-core/src/main/java/org/apache/paimon/table/system/ManifestsTable.java
@@ -45,6 +45,7 @@ import org.apache.paimon.utils.IteratorRecordReader;
 import org.apache.paimon.utils.ProjectedRow;
 import org.apache.paimon.utils.SerializationUtils;
 import org.apache.paimon.utils.SnapshotManager;
+import org.apache.paimon.utils.SnapshotNotExistException;
 
 import org.apache.paimon.shade.guava30.com.google.common.collect.Iterators;
 
@@ -195,7 +196,16 @@ public class ManifestsTable implements ReadonlyTable {
         SnapshotManager snapshotManager = dataTable.snapshotManager();
         Long snapshotId = coreOptions.scanSnapshotId();
         Snapshot snapshot = null;
-        if (snapshotId != null && snapshotManager.snapshotExists(snapshotId)) {
+        if (snapshotId != null) {
+            // reminder user with snapshot id range
+            if (!snapshotManager.snapshotExists(snapshotId)) {
+                Long earliestSnapshotId = snapshotManager.earliestSnapshotId();
+                Long latestSnapshotId = snapshotManager.latestSnapshotId();
+                throw new SnapshotNotExistException(
+                        String.format(
+                                "Specified scan.snapshot-id %s is not exist, 
you can set it in range from %s to %s",
+                                snapshotId, earliestSnapshotId, 
latestSnapshotId));
+            }
             snapshot = snapshotManager.snapshot(snapshotId);
         } else if (snapshotId == null) {
             snapshot = snapshotManager.latestSnapshot();
diff --git 
a/paimon-core/src/test/java/org/apache/paimon/table/system/ManifestsTableTest.java
 
b/paimon-core/src/test/java/org/apache/paimon/table/system/ManifestsTableTest.java
index edca0831d..32dd0d248 100644
--- 
a/paimon-core/src/test/java/org/apache/paimon/table/system/ManifestsTableTest.java
+++ 
b/paimon-core/src/test/java/org/apache/paimon/table/system/ManifestsTableTest.java
@@ -36,6 +36,7 @@ import org.apache.paimon.table.Table;
 import org.apache.paimon.table.TableTestBase;
 import org.apache.paimon.types.DataTypes;
 import org.apache.paimon.utils.SnapshotManager;
+import org.apache.paimon.utils.SnapshotNotExistException;
 
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -46,6 +47,7 @@ import java.util.List;
 
 import static 
org.apache.paimon.utils.FileStorePathFactoryTest.createNonPartFactory;
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertThrows;
 
 /** Unit tests for {@link ManifestsTable}. */
 public class ManifestsTableTest extends TableTestBase {
@@ -118,8 +120,10 @@ public class ManifestsTableTest extends TableTestBase {
                 (ManifestsTable)
                         manifestsTable.copy(
                                 
Collections.singletonMap(CoreOptions.SCAN_SNAPSHOT_ID.key(), "3"));
-        List<InternalRow> result = read(manifestsTable);
-        assertThat(result).isEmpty();
+        assertThrows(
+                "Specified scan.snapshot-id 3 is not exist, you can set it in 
range from 1 to 2",
+                SnapshotNotExistException.class,
+                () -> read(manifestsTable));
     }
 
     private List<InternalRow> getExpectedResult(long snapshotId) {

Reply via email to