amogh-jahagirdar commented on code in PR #5618:
URL: https://github.com/apache/iceberg/pull/5618#discussion_r997573067


##########
core/src/test/java/org/apache/iceberg/TestRemoveSnapshots.java:
##########
@@ -1455,6 +1455,56 @@ public void testMaxSnapshotAgeMultipleBranches() {
     Assert.assertNull(table.ops().current().snapshot(initialSnapshotId));
   }
 
+  @Test
+  public void testRetainFilesOnRetainedBranches() {
+    // Append a file to main and test branch
+    String testBranch = "test-branch";
+    table.newAppend().appendFile(FILE_A).commit();
+    Snapshot a = table.currentSnapshot();
+    table.manageSnapshots().createBranch(testBranch, a.snapshotId()).commit();
+
+    // Delete A from main
+    table.newDelete().deleteFile(FILE_A).commit();
+    Snapshot deletionA = table.currentSnapshot();
+    // Add B to main
+    table.newAppend().appendFile(FILE_B).commit();
+    long tAfterCommits = 
waitUntilAfter(table.currentSnapshot().timestampMillis());
+    Set<String> deletedFiles = Sets.newHashSet();
+    Set<String> expectedDeletes = Sets.newHashSet();
+
+    // Only deletionA's manifest list and manifests should be removed
+    expectedDeletes.add(deletionA.manifestListLocation());
+    expectedDeletes.addAll(
+        deletionA.allManifests(table.io()).stream().map(manifest -> 
manifest.path()).collect(Collectors.toSet()));
+    
table.expireSnapshots().expireOlderThan(tAfterCommits).deleteWith(deletedFiles::add).commit();
+
+    Assert.assertEquals(2, Iterables.size(table.snapshots()));
+    Assert.assertEquals(expectedDeletes, deletedFiles);
+
+    // Delete A on test branch
+    table.newDelete().deleteFile(FILE_A).toBranch(testBranch).commit();
+    Snapshot branchDelete = table.snapshot(testBranch);
+    table.newAppend().appendFile(FILE_C).toBranch(testBranch).commit();
+    Snapshot testBranchHead = table.snapshot(testBranch);
+
+    deletedFiles = Sets.newHashSet();
+    expectedDeletes = Sets.newHashSet();
+    
table.expireSnapshots().expireOlderThan(testBranchHead.timestampMillis()).deleteWith(deletedFiles::add).commit();

Review Comment:
   Ah yes, there should be a waitUntilAfter 



##########
core/src/test/java/org/apache/iceberg/TestRemoveSnapshots.java:
##########
@@ -1455,6 +1455,56 @@ public void testMaxSnapshotAgeMultipleBranches() {
     Assert.assertNull(table.ops().current().snapshot(initialSnapshotId));
   }
 
+  @Test
+  public void testRetainFilesOnRetainedBranches() {
+    // Append a file to main and test branch
+    String testBranch = "test-branch";
+    table.newAppend().appendFile(FILE_A).commit();
+    Snapshot a = table.currentSnapshot();
+    table.manageSnapshots().createBranch(testBranch, a.snapshotId()).commit();
+
+    // Delete A from main
+    table.newDelete().deleteFile(FILE_A).commit();
+    Snapshot deletionA = table.currentSnapshot();
+    // Add B to main
+    table.newAppend().appendFile(FILE_B).commit();
+    long tAfterCommits = 
waitUntilAfter(table.currentSnapshot().timestampMillis());
+    Set<String> deletedFiles = Sets.newHashSet();
+    Set<String> expectedDeletes = Sets.newHashSet();
+
+    // Only deletionA's manifest list and manifests should be removed
+    expectedDeletes.add(deletionA.manifestListLocation());
+    expectedDeletes.addAll(
+        deletionA.allManifests(table.io()).stream().map(manifest -> 
manifest.path()).collect(Collectors.toSet()));
+    
table.expireSnapshots().expireOlderThan(tAfterCommits).deleteWith(deletedFiles::add).commit();
+
+    Assert.assertEquals(2, Iterables.size(table.snapshots()));
+    Assert.assertEquals(expectedDeletes, deletedFiles);
+
+    // Delete A on test branch
+    table.newDelete().deleteFile(FILE_A).toBranch(testBranch).commit();
+    Snapshot branchDelete = table.snapshot(testBranch);
+    table.newAppend().appendFile(FILE_C).toBranch(testBranch).commit();
+    Snapshot testBranchHead = table.snapshot(testBranch);
+
+    deletedFiles = Sets.newHashSet();
+    expectedDeletes = Sets.newHashSet();
+    
table.expireSnapshots().expireOlderThan(testBranchHead.timestampMillis()).deleteWith(deletedFiles::add).commit();
+
+    //
+    expectedDeletes.add(a.manifestListLocation());
+    expectedDeletes.addAll(
+        a.allManifests(table.io()).stream().map(manifest -> 
manifest.path()).collect(Collectors.toSet()));

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to