Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[core] Manifest table query throw exception with range of snapshot when snapshot id not exist #4145

Merged
merged 7 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SnapshotNotExistException

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
Loading