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 the code is 
clearer
   ```
    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);
   }
   ```



##########
core/src/test/java/org/apache/iceberg/TestSchemaUpdate.java:
##########
@@ -1438,12 +1435,19 @@ public void testSetIdentifierFieldsFails() {
             .setIdentifierFields("new_map.value.val_col")
             .apply());
 
-    AssertHelpers.assertThrows("add a nested field in struct of a map should 
fail",
+    AssertHelpers.assertThrows("add a nested field in struct of a list should 
fail",
         IllegalArgumentException.class,
         "must not be nested in " + newSchema.findField("new.fields"),
         () -> new SchemaUpdate(newSchema, lastColId)
             .setIdentifierFields("new.fields.element.nested")
             .apply());
+
+    AssertHelpers.assertThrows("add a nested field in an optional struct which 
should fail",

Review Comment:
   We don't need "which"



##########
core/src/test/java/org/apache/iceberg/TestSchemaUpdate.java:
##########
@@ -1261,14 +1261,6 @@ public void testAddNewIdentifierFieldColumns() {
   @Test
   public void testAddNestedIdentifierFieldColumns() {
     Schema newSchema = new SchemaUpdate(SCHEMA, SCHEMA_LAST_COLUMN_ID)
-        .setIdentifierFields("preferences.feature1")
-        .apply();
-
-    Assert.assertEquals("set existing nested field as identifier should 
succeed",

Review Comment:
   I dont think we should remove this test?



##########
core/src/test/java/org/apache/iceberg/TestSchemaUpdate.java:
##########
@@ -1476,6 +1480,20 @@ public void testDeleteIdentifierFieldColumnsFails() {
         "Cannot delete identifier field 1: id: required int. To force 
deletion, " +
             "also call setIdentifierFields to update identifier fields.",
         () -> new SchemaUpdate(schemaWithIdentifierFields, 
SCHEMA_LAST_COLUMN_ID).deleteColumn("id").apply());
+
+    Schema newSchema = new SchemaUpdate(SCHEMA, SCHEMA_LAST_COLUMN_ID)

Review Comment:
   Can we split this out into new test method, to make it easier?



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