Skip to content

Commit 1e81631

Browse files
committed
throw exception incase no snapshot found for copying
1 parent edaf474 commit 1e81631

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

gobblin-data-management/src/main/java/org/apache/gobblin/data/management/copy/iceberg/IcebergTable.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ protected void registerIcebergTable(TableMetadata srcMetadata, TableMetadata dst
239239
public List<DataFile> getPartitionSpecificDataFiles(Predicate<StructLike> icebergPartitionFilterPredicate)
240240
throws IOException {
241241
TableMetadata tableMetadata = accessTableMetadata();
242-
Snapshot currentSnapshot = tableMetadata.currentSnapshot();
242+
Snapshot currentSnapshot = Optional.ofNullable(tableMetadata.currentSnapshot())
243+
.orElseThrow(() -> new IOException(String.format("~%s~ No snapshots found", tableId)));
243244
long currentSnapshotId = currentSnapshot.snapshotId();
244245
List<DataFile> knownDataFiles = new ArrayList<>();
245246
GrowthMilestoneTracker growthMilestoneTracker = new GrowthMilestoneTracker();

gobblin-data-management/src/test/java/org/apache/gobblin/data/management/copy/iceberg/IcebergTableTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,18 @@ public void testGetPartitionSpecificDataFiles() throws IOException {
253253
Assert.assertEquals(icebergTable.getPartitionSpecificDataFiles(alwaysFalsePredicate).size(), 0);
254254
}
255255

256+
@Test
257+
public void testGetPartitionSpecificDataFilesThrowsExceptionWhenNoSnapshotsFound() throws IOException {
258+
IcebergTable icebergTable = new IcebergTable(tableId,
259+
catalog.newTableOps(tableId),
260+
catalogUri,
261+
catalog.loadTable(tableId));
262+
// Using AlwaysTrue Predicate to avoid mocking of predicate class
263+
Predicate<StructLike> alwaysTruePredicate = partition -> true;
264+
IOException exception = Assert.expectThrows(IOException.class, () -> icebergTable.getPartitionSpecificDataFiles(alwaysTruePredicate));
265+
Assert.assertEquals(exception.getMessage(), String.format("~%s~ No snapshots found", tableId));
266+
}
267+
256268
/** Verify that overwritePartition replace data files belonging to given partition col and value */
257269
@Test
258270
public void testOverwritePartition() throws IOException {

0 commit comments

Comments
 (0)