Skip to content

Commit

Permalink
[core] Manifest table query throw exception with range of snapshot wh…
Browse files Browse the repository at this point in the history
…en snapshot id not exist (apache#4145)

(cherry picked from commit e083825)
  • Loading branch information
xuzifu666 authored and wxplovecc committed Sep 10, 2024
1 parent 86140f5 commit ed419f1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
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;

Expand Down Expand Up @@ -195,7 +196,16 @@ private static List<ManifestFileMeta> allManifests(FileStoreTable dataTable) {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
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;
Expand All @@ -46,6 +47,7 @@

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 {
Expand Down Expand Up @@ -118,8 +120,10 @@ public void testReadManifestsFromNotExistSnapshot() throws Exception {
(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) {
Expand Down

0 comments on commit ed419f1

Please sign in to comment.