gaborkaszab commented on code in PR #13509:
URL: https://github.com/apache/iceberg/pull/13509#discussion_r2199943583
##########
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:
Sure. I also added a `as()` to these assert and I updated the test for the
procedure too to be stronger similarly to these ones.
--
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]