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


##########
spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/actions/ExpireSnapshotsSparkAction.java:
##########
@@ -158,6 +165,10 @@ public Dataset<FileInfo> expireFiles() {
         expireSnapshots = expireSnapshots.retainLast(retainLastValue);
       }
 
+      if (cleanExpiredMetadata != null) {
+        expireSnapshots.cleanExpiredMetadata(cleanExpiredMetadata);
+      }

Review Comment:
   If we make it a primitive we can just remove the `if` and it'll be 
`expireSnapshots.cleanExpiredMetadata(cleanExpiredMetadata);`



##########
spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/actions/TestExpireSnapshotsAction.java:
##########
@@ -1342,4 +1342,62 @@ public void testExpireSomeCheckFilesDeleted() {
         .contains(FILE_A.location())
         .doesNotContain(FILE_B.location(), FILE_C.location(), 
FILE_D.location());
   }
+
+  @TestTemplate
+  public void testNoExpiredMetadataCleanupByDefault() {
+    table.newAppend().appendFile(FILE_A).commit();
+    table.newDelete().deleteFile(FILE_A).commit();
+
+    long after = rightAfterSnapshot();
+
+    table.updateSchema().addColumn("extra_col", 
Types.IntegerType.get()).commit();
+    table.newAppend().appendFile(FILE_B).commit();
+
+    Set<Integer> schemaIds = table.schemas().keySet();
+
+    Set<String> deletedFiles = Sets.newHashSet();
+    SparkActions.get()
+        .expireSnapshots(table)
+        .expireOlderThan(after)
+        .deleteWith(deletedFiles::add)
+        .execute();
+
+    
assertThat(table.schemas().keySet()).containsExactlyInAnyOrderElementsOf(schemaIds);
+    
assertThat(deletedFiles).contains(FILE_A.location()).doesNotContain(FILE_B.location());
+  }
+
+  @TestTemplate
+  public void testCleanExpiredMetadata() {
+    table.newAppend().appendFile(FILE_A).commit();
+    table.newDelete().deleteFile(FILE_A).commit();
+
+    long after = rightAfterSnapshot();
+    int schemaIdToRemove = table.schema().schemaId();
+    int specIdToRemove = table.spec().specId();
+
+    table.updateSchema().addColumn("extra_col", 
Types.IntegerType.get()).commit();
+    table.updateSpec().addField("extra_col").commit();
+
+    DataFile fileInNewSpec =
+        DataFiles.builder(table.spec())
+            .withPath("/path/to/data-in-new-spec.parquet")
+            .withFileSizeInBytes(10)
+            .withPartitionPath("c1=1/extra_col=11")
+            .withRecordCount(1)
+            .build();
+
+    table.newAppend().appendFile(fileInNewSpec).commit();
+
+    Set<String> deletedFiles = Sets.newHashSet();
+    SparkActions.get()
+        .expireSnapshots(table)
+        .expireOlderThan(after)
+        .deleteWith(deletedFiles::add)
+        .cleanExpiredMetadata(true)
+        .execute();
+
+    assertThat(table.specs().keySet()).doesNotContain(specIdToRemove);
+    assertThat(table.schemas().keySet()).doesNotContain(schemaIdToRemove);

Review Comment:
   Nit: Similar to the test above, could we make this a stronger assertion by 
asserting the exact contents of the specs/schemas rather than it doesn't 
containing the removed ones.



##########
spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/actions/ExpireSnapshotsSparkAction.java:
##########
@@ -79,6 +79,7 @@ public class ExpireSnapshotsSparkAction extends 
BaseSparkAction<ExpireSnapshotsS
   private Consumer<String> deleteFunc = null;
   private ExecutorService deleteExecutorService = null;
   private Dataset<FileInfo> expiredFileDS = null;
+  private Boolean cleanExpiredMetadata = null;

Review Comment:
   Could we just make this a primitive `boolean` defaulting to false?



-- 
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