Skip to content

Commit

Permalink
throw exception incase no snapshot found for copying
Browse files Browse the repository at this point in the history
  • Loading branch information
Blazer-007 committed Nov 4, 2024
1 parent edaf474 commit 1e81631
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
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

0 comments on commit 1e81631

Please sign in to comment.