szehon-ho commented on code in PR #4535:
URL: https://github.com/apache/iceberg/pull/4535#discussion_r854705228


##########
core/src/main/java/org/apache/iceberg/SchemaUpdate.java:
##########
@@ -438,13 +438,18 @@ private static Schema applyChanges(Schema schema, 
List<Integer> deletes,
                                      Multimap<Integer, Types.NestedField> adds,
                                      Multimap<Integer, Move> moves,
                                      Set<String> identifierFieldNames) {
-    // validate existing identifier fields are not deleted
+    Map<Integer, Integer> idToParent = 
TypeUtil.indexParents(schema.asStruct());
+
     for (String name : identifierFieldNames) {
       Types.NestedField field = schema.findField(name);
       if (field != null) {
-        Preconditions.checkArgument(!deletes.contains(field.fieldId()),
-            "Cannot delete identifier field %s. To force deletion, " +
-                "also call setIdentifierFields to update identifier fields.", 
field);
+        Integer idNotToDelete = field.fieldId();

Review Comment:
   Can we keep the original Precondition check as is, and then have code after 
to check parents.  
   
   The message can have more information in the new case, and (in my opinion) 
the code is a bit clearer as we separate the two concerns.
   ```
    Preconditions.checkArgument(!deletes.contains(field.fieldId()),
               "Cannot delete identifier field %s. To force deletion, " +
                   "also call setIdentifierFields to update identifier 
fields.", field);
   Integer parentId = fieldId;
   while (parentId != null) {
      Preconditions.checkArgument(... "Cannot delete field %s as it will delete 
nested identifier field %s",...)
      parentId = idToParent.get(parentId);
   }
   ```



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