rdblue commented on code in PR #13445:
URL: https://github.com/apache/iceberg/pull/13445#discussion_r2308241312


##########
spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/data/ParquetWithSparkSchemaVisitor.java:
##########
@@ -182,19 +183,17 @@ private static <T> T visitField(
 
   private static <T> List<T> visitFields(
       StructType struct, GroupType group, ParquetWithSparkSchemaVisitor<T> 
visitor) {
-    StructField[] sFields = struct.fields();
-    Preconditions.checkArgument(
-        sFields.length == group.getFieldCount(), "Structs do not match: %s and 
%s", struct, group);
     List<T> results = 
Lists.newArrayListWithExpectedSize(group.getFieldCount());
-    for (int i = 0; i < sFields.length; i += 1) {
-      Type field = group.getFields().get(i);
-      StructField sField = sFields[i];
-      Preconditions.checkArgument(
-          
field.getName().equals(AvroSchemaUtil.makeCompatibleName(sField.name())),
-          "Structs do not match: field %s != %s",
-          field.getName(),
-          sField.name());
-      results.add(visitField(sField, field, visitor));
+    for (StructField sField : struct.fields()) {
+      String fieldName = AvroSchemaUtil.makeCompatibleName(sField.name());
+      if (sField.dataType() != DataTypes.NullType) {
+        Type field = group.getType(fieldName);

Review Comment:
   I think that this should still preserve the check above by aligning the 
columns that do exist. The current version allows the structs to differ in 
field order, which I would like to avoid. Here's my version of the change:
   
   ```java
     private static <T> List<T> visitFields(
         StructType struct, GroupType group, ParquetWithSparkSchemaVisitor<T> 
visitor) {
       List<T> results = 
Lists.newArrayListWithExpectedSize(group.getFieldCount());
   
       int i = 0;
       for (StructField sField : struct.fields()) {
         if (sField.dataType() != DataTypes.NullType) {
           Type field = group.getFields().get(i);
           Preconditions.checkArgument(
               
field.getName().equals(AvroSchemaUtil.makeCompatibleName(sField.name())),
               "Structs do not match: field %s != %s",
               field.getName(),
               sField.name());
           results.add(visitField(sField, field, visitor));
   
           i += 1;
         }
       }
   
       // all the group fields should have been visited
       Preconditions.checkArgument(
           i == group.getFieldCount(), "Structs do not match: %s and %s", 
struct, group);
   
       return results;
     }
   ```



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