humengyu2012 commented on pull request #3912:
URL: https://github.com/apache/iceberg/pull/3912#issuecomment-1023914271


   @rdblue Do you mean the method should like this:
   ```java
      static Schema rebuildSchemaWithIdentifierFieldIds(Schema schema, 
Set<String> identifierFieldNames) {
       if (identifierFieldNames.size() == 0) {
         return schema;
       }
   
       Map<Integer, Integer> indexParents = 
TypeUtil.indexParents(schema.asStruct());
       Set<Integer> identifierFieldIds = identifierFieldNames.stream()
           .map(name -> {
             Types.NestedField field = schema.findField(name);
             Preconditions.checkArgument(field != null, "Column %s does not 
exist", name);
             
             int id = field.fieldId();
             Optional<Types.NestedField> parent = 
Optional.ofNullable(indexParents.get(id)).map(schema::findField);
             parent.ifPresent(parentField -> 
Preconditions.checkArgument(parentField.type().isStructType(),
                 "Cannot add field %s as an identifier field: must not be 
nested in %s", field.name(), parent));
             
             Preconditions.checkArgument(field.type().isPrimitiveType(),
                 "Cannot add field %s as an identifier field: not a primitive 
type field", field.name());
             return id;
           }).collect(Collectors.toSet());
   
       List<Types.NestedField> columns = schema.columns().stream()
           .map(column -> identifierFieldIds.contains(column.fieldId()) ? 
column.asRequired() : column)
           .collect(Collectors.toList());
       return new Schema(columns, identifierFieldIds);
     }
   ```
   The original implementation of this method looked like this, but @pvary and 
me both think it it would be better to simply just check the first level fields 
instead of a recursive check. We just want to simplify the calculation for 
finding fields. I would like to know your suggestions.


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