mxm commented on code in PR #14728:
URL: https://github.com/apache/iceberg/pull/14728#discussion_r2588746794


##########
flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/sink/dynamic/CompareSchemasVisitor.java:
##########
@@ -97,6 +101,11 @@ public Result struct(Types.StructType struct, Integer 
tableSchemaId, List<Result
     }
 
     if (struct.fields().size() != 
tableSchemaType.asStructType().fields().size()) {
+      if (dropUnusedColumns
+          && struct.fields().size() < 
tableSchemaType.asStructType().fields().size()) {
+        // We need to drop fields
+        return Result.SCHEMA_UPDATE_NEEDED;

Review Comment:
   Here both blocks:
   
   ```java
       for (Types.NestedField tableField : 
tableSchemaType.asStructType().fields()) {
         if (tableField.isRequired() && struct.field(tableField.name()) == 
null) {
           // If a field from the table schema does not exist in the input 
schema, then we won't visit
           // it and check for required/optional compatibility. The only choice 
is to make the table
           // field optional.
           return Result.SCHEMA_UPDATE_NEEDED;
         }
       }
   
       if (struct.fields().size() != 
tableSchemaType.asStructType().fields().size()) {
         if (dropUnusedColumns
             && struct.fields().size() < 
tableSchemaType.asStructType().fields().size()) {
           // We need to drop fields
           return Result.SCHEMA_UPDATE_NEEDED;
         }
         return Result.DATA_CONVERSION_NEEDED;
       }
   ```
   
   This can probably be simplified to:
   
   ```java
   
       for (Types.NestedField tableField : 
tableSchemaType.asStructType().fields()) {
         if (struct.field(tableField.name()) == null && 
(tableField.isRequired() || dropUnusedColumns)) {
           // If a field from the table schema does not exist in the input 
schema, then we won't visit
           // it. The only choice is to make the table field optional or drop 
it.
           return Result.SCHEMA_UPDATE_NEEDED;
         }
       }
   
       if (struct.fields().size() != 
tableSchemaType.asStructType().fields().size()) {
         return Result.DATA_CONVERSION_NEEDED;
       }
   
   ```



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