gaborkaszab commented on code in PR #12089: URL: https://github.com/apache/iceberg/pull/12089#discussion_r1952507098
########## core/src/main/java/org/apache/iceberg/RemoveSnapshots.java: ########## @@ -218,23 +218,34 @@ private TableMetadata internalApply() { updatedMetaBuilder.removeSnapshots(idsToRemove); if (cleanExpiredMetadata) { - // TODO: Support cleaning expired schema as well. Set<Integer> reachableSpecs = Sets.newConcurrentHashSet(); reachableSpecs.add(base.defaultSpecId()); + Set<Integer> reachableSchemas = Sets.newConcurrentHashSet(); + reachableSchemas.add(base.currentSchemaId()); + Tasks.foreach(idsToRetain) .executeWith(planExecutorService) .run( - snapshot -> - base.snapshot(snapshot).allManifests(ops.io()).stream() - .map(ManifestFile::partitionSpecId) - .forEach(reachableSpecs::add)); + snapshotId -> { + base.snapshot(snapshotId).allManifests(ops.io()).stream() Review Comment: Done ########## core/src/test/java/org/apache/iceberg/TestRemoveSnapshots.java: ########## @@ -1705,6 +1706,36 @@ public void testRemoveSpecsDoesntRemoveDefaultSpec() throws IOException { .containsExactly(dataBucketSpec.specId()); } + @TestTemplate + public void testRemoveSchemas() { + table.newAppend().appendFile(FILE_A).commit(); + + Set<String> expectedDeletedFiles = Sets.newHashSet(); + expectedDeletedFiles.add(table.currentSnapshot().manifestListLocation()); + + table.updateSchema().addColumn("extra_col1", Types.StringType.get()).commit(); + + table.newAppend().appendFile(FILE_B).commit(); + expectedDeletedFiles.add(table.currentSnapshot().manifestListLocation()); + + table.updateSchema().addColumn("extra_col2", Types.LongType.get()).deleteColumn("id").commit(); + + table.newAppend().appendFile(FILE_A2).commit(); + + assertThat(table.schemas().size()).isEqualTo(3); + + Set<String> deletedFiles = Sets.newHashSet(); + // Expire all snapshots except the current one. Also expire all schemas except the current one. Review Comment: Done ########## core/src/main/java/org/apache/iceberg/TableMetadata.java: ########## @@ -1183,6 +1183,21 @@ Builder removeSpecs(Iterable<Integer> specIds) { .filter(s -> !specIdsToRemove.contains(s.specId())) .collect(Collectors.toList()); changes.add(new MetadataUpdate.RemovePartitionSpecs(specIdsToRemove)); + + return this; + } + + Builder removeSchemas(Iterable<Integer> schemaIds) { Review Comment: Done ########## core/src/main/java/org/apache/iceberg/TableMetadata.java: ########## @@ -1183,6 +1183,21 @@ Builder removeSpecs(Iterable<Integer> specIds) { .filter(s -> !specIdsToRemove.contains(s.specId())) .collect(Collectors.toList()); changes.add(new MetadataUpdate.RemovePartitionSpecs(specIdsToRemove)); + + return this; + } + + Builder removeSchemas(Iterable<Integer> schemaIds) { + Set<Integer> schemaIdsToRemove = Sets.newHashSet(schemaIds); + Preconditions.checkArgument( + !schemaIdsToRemove.contains(currentSchemaId), "Cannot remove the current schema"); + + this.schemas = + schemas.stream() + .filter(s -> !schemaIdsToRemove.contains(s.schemaId())) + .collect(Collectors.toList()); + changes.add(new MetadataUpdate.RemoveSchemas(schemaIdsToRemove)); Review Comment: Good point! Done Will create a separate PR for the same for RemovePartitionSpecs once we sort this one out. -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org