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

[GOBBLIN-2169] Fix NPE if table has no previous snapshot #4073

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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 @@ -239,7 +239,8 @@ protected void registerIcebergTable(TableMetadata srcMetadata, TableMetadata dst
public List<DataFile> getPartitionSpecificDataFiles(Predicate<StructLike> icebergPartitionFilterPredicate)
throws IOException {
TableMetadata tableMetadata = accessTableMetadata();
Snapshot currentSnapshot = tableMetadata.currentSnapshot();
Snapshot currentSnapshot = Optional.ofNullable(tableMetadata.currentSnapshot())
.orElseThrow(() -> new IOException(String.format("~%s~ No snapshots found", tableId)));
long currentSnapshotId = currentSnapshot.snapshotId();
List<DataFile> knownDataFiles = new ArrayList<>();
GrowthMilestoneTracker growthMilestoneTracker = new GrowthMilestoneTracker();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,18 @@ public void testGetPartitionSpecificDataFiles() throws IOException {
Assert.assertEquals(icebergTable.getPartitionSpecificDataFiles(alwaysFalsePredicate).size(), 0);
}

@Test
public void testGetPartitionSpecificDataFilesThrowsExceptionWhenNoSnapshotsFound() throws IOException {
IcebergTable icebergTable = new IcebergTable(tableId,
catalog.newTableOps(tableId),
catalogUri,
catalog.loadTable(tableId));
// Using AlwaysTrue Predicate to avoid mocking of predicate class
Predicate<StructLike> alwaysTruePredicate = partition -> true;
IOException exception = Assert.expectThrows(IOException.class, () -> icebergTable.getPartitionSpecificDataFiles(alwaysTruePredicate));
Assert.assertEquals(exception.getMessage(), String.format("~%s~ No snapshots found", tableId));
}

/** Verify that overwritePartition replace data files belonging to given partition col and value */
@Test
public void testOverwritePartition() throws IOException {
Expand Down
Loading