From 1e81631e8a050be28755040613464ccbc41b585d Mon Sep 17 00:00:00 2001 From: Vivek Rai Date: Mon, 4 Nov 2024 10:10:06 +0530 Subject: [PATCH] throw exception incase no snapshot found for copying --- .../data/management/copy/iceberg/IcebergTable.java | 3 ++- .../management/copy/iceberg/IcebergTableTest.java | 12 ++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gobblin-data-management/src/main/java/org/apache/gobblin/data/management/copy/iceberg/IcebergTable.java b/gobblin-data-management/src/main/java/org/apache/gobblin/data/management/copy/iceberg/IcebergTable.java index e3ec46aa1e..fed375374a 100644 --- a/gobblin-data-management/src/main/java/org/apache/gobblin/data/management/copy/iceberg/IcebergTable.java +++ b/gobblin-data-management/src/main/java/org/apache/gobblin/data/management/copy/iceberg/IcebergTable.java @@ -239,7 +239,8 @@ protected void registerIcebergTable(TableMetadata srcMetadata, TableMetadata dst public List getPartitionSpecificDataFiles(Predicate 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 knownDataFiles = new ArrayList<>(); GrowthMilestoneTracker growthMilestoneTracker = new GrowthMilestoneTracker(); diff --git a/gobblin-data-management/src/test/java/org/apache/gobblin/data/management/copy/iceberg/IcebergTableTest.java b/gobblin-data-management/src/test/java/org/apache/gobblin/data/management/copy/iceberg/IcebergTableTest.java index 63aa27221b..69a9688fb1 100644 --- a/gobblin-data-management/src/test/java/org/apache/gobblin/data/management/copy/iceberg/IcebergTableTest.java +++ b/gobblin-data-management/src/test/java/org/apache/gobblin/data/management/copy/iceberg/IcebergTableTest.java @@ -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 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 {