amogh-jahagirdar commented on code in PR #10352: URL: https://github.com/apache/iceberg/pull/10352#discussion_r1605826546
########## core/src/main/java/org/apache/iceberg/SchemaUpdate.java: ########## @@ -533,6 +537,34 @@ private static Schema applyChanges( } } + Map<Integer, List<Integer>> specToDeletes = Maps.newHashMap(); + if (base != null) { + for (int fieldIdToDelete : deletes) { + for (PartitionSpec spec : base.specs()) { + if (spec.schema().findField(fieldIdToDelete) != null) { + List<Integer> deletesForSpec = + specToDeletes.computeIfAbsent(spec.specId(), k -> Lists.newArrayList()); + deletesForSpec.add(fieldIdToDelete); + specToDeletes.put(spec.specId(), deletesForSpec); + } + } + } + } + + if (!specToDeletes.isEmpty() && base.currentSnapshot() != null) { + List<ManifestFile> manifests = + ManifestLists.read(ops.io().newInputFile(base.currentSnapshot().manifestListLocation())); + Optional<ManifestFile> manifestReferencingActivePartition = + manifests.stream() + .filter(manifest -> specToDeletes.containsKey(manifest.partitionSpecId())) + .findAny(); + Preconditions.checkArgument( + !manifestReferencingActivePartition.isPresent(), + "Cannot delete field %s as it is used by an active partition spec %s", Review Comment: Probably use the field name in the error message instead of the ID so it's more useful to a user -- 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