advancedxy commented on code in PR #10755:
URL: https://github.com/apache/iceberg/pull/10755#discussion_r1701095912


##########
core/src/main/java/org/apache/iceberg/TableMetadata.java:
##########
@@ -1102,6 +1102,42 @@ public Builder setDefaultPartitionSpec(int specId) {
       return this;
     }
 
+    Builder removeUnusedSpecs(Iterable<PartitionSpec> specsToRemove) {
+      Set<Integer> specIdsToRemove = Sets.newHashSet();
+      for (PartitionSpec spec : specsToRemove) {
+        Preconditions.checkArgument(
+            spec.specId() != defaultSpecId, "Cannot remove default partition 
spec");
+        PartitionSpec toBeRemoved = specsById.remove(spec.specId());
+        Preconditions.checkArgument(
+            toBeRemoved == null || toBeRemoved.equals(spec),
+            "Cannot remove an unknown spec, spec id: %s",
+            spec.specId());
+        if (toBeRemoved != null) {
+          specIdsToRemove.add(spec.specId());
+        }
+      }
+      this.specs =
+          specs.stream()
+              .filter(s -> !specIdsToRemove.contains(s.specId()))
+              .collect(Collectors.toList());
+      changes.add(new MetadataUpdate.RemoveUnusedSpecs(specIdsToRemove));
+      return this;
+    }
+
+    Builder removeUnusedSpecsById(Iterable<Integer> specIds) {
+      Set<Integer> specIdsToRemove = Sets.newHashSet(specIds);
+      Preconditions.checkArgument(
+          !specIdsToRemove.contains(defaultSpecId), "Cannot remove default 
partition spec");
+      this.specs =
+          specs.stream()
+              .filter(s -> !specIdsToRemove.contains(s.specId()))
+              .collect(Collectors.toList());
+      specsById.clear();
+      specsById.putAll(indexSpecs(specs));

Review Comment:
   Good point, let me refine it.



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

Reply via email to