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



##########
File path: core/src/main/java/org/apache/iceberg/Partitioning.java
##########
@@ -222,27 +224,41 @@ public static StructType partitionType(Table table) {
 
       for (PartitionField field : spec.fields()) {
         int fieldId = field.fieldId();
+        NestedField structField = spec.partitionType().field(fieldId);
+
         PartitionField existingField = fieldMap.get(fieldId);
 
         if (existingField == null) {
           fieldMap.put(fieldId, field);
-          NestedField structField = spec.partitionType().field(fieldId);
-          structFields.add(structField);
+          typeMap.put(fieldId, structField.type());
+          nameMap.put(fieldId, structField.name());
+
         } else {
           // verify the fields are compatible as they may conflict in v1 tables
           ValidationException.check(equivalentIgnoringNames(field, 
existingField),
               "Conflicting partition fields: ['%s', '%s']",
               field, existingField);
+
+          // use the correct type for dropped partitions in v1 tables
+          if (isVoidTransform(existingField) && !isVoidTransform(field)) {
+            fieldMap.put(fieldId, field);
+            typeMap.put(fieldId, structField.type());
+          }
         }
       }
     }
 
-    List<NestedField> sortedStructFields = structFields.stream()
-        .sorted(Comparator.comparingInt(NestedField::fieldId))
+    List<NestedField> sortedStructFields = fieldMap.keySet().stream()
+        .sorted(Comparator.naturalOrder())
+        .map(fieldId -> NestedField.optional(fieldId, nameMap.get(fieldId), 
typeMap.get(fieldId)))

Review comment:
       I think the changes in this file are correct and fix the first issue, 
where the type may be incorrect for void transform fields in v1 tables.




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