rdblue commented on a change in pull request #2465:
URL: https://github.com/apache/iceberg/pull/2465#discussion_r617121331



##########
File path: core/src/main/java/org/apache/iceberg/SchemaUpdate.java
##########
@@ -317,6 +320,31 @@ public UpdateSchema unionByNameWith(Schema newSchema) {
     return this;
   }
 
+  @Override
+  public UpdateSchema setIdentifierFields(Set<String> names) {
+    identifierFields = Sets.newHashSet();
+    names.forEach(this::addIdentifierField);
+    return this;
+  }
+
+  private void addIdentifierField(String name) {
+    Types.NestedField field = schema.findField(name);
+    if (field == null) {
+      field = adds.get(TABLE_ROOT_ID).stream()
+          .filter(f -> f.name().equals(name))
+          .findAny().orElse(null);
+    } else {
+      Preconditions.checkArgument(idToParent.get(field.fieldId()) == null,
+          "Cannot add column %s as an identifier: must not be nested in a map 
or list", name);

Review comment:
       [`IndexParents` supports maps and 
lists](https://github.com/apache/iceberg/blob/master/api/src/main/java/org/apache/iceberg/types/IndexParents.java#L67),
 so I think you need to actually look up the parent field and check its type. 
You'd also need to do that all the way up to the root to ensure that this isn't 
wrong because of multiple levels of nesting, like a struct as a map value.




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

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