vinson0526 commented on a change in pull request #2691:
URL: https://github.com/apache/iceberg/pull/2691#discussion_r654136628



##########
File path: core/src/main/java/org/apache/iceberg/BaseUpdatePartitionSpec.java
##########
@@ -149,7 +151,14 @@ public BaseUpdatePartitionSpec addField(String name, Term 
term) {
       nameToAddedField.put(name, newField);
     }
 
-    adds.add(newField);
+    String partitionName;
+    if (newField.name() != null) {
+      partitionName = newField.name();
+    } else {
+      partitionName = PartitionSpecVisitor.visit(schema, newField, 
PartitionNameGenerator.INSTANCE);
+    }
+
+    adds.add(Pair.of(newField, partitionName));

Review comment:
       Regenerate `PartitionField` with `partitionName ` if `name` is null.

##########
File path: core/src/main/java/org/apache/iceberg/BaseUpdatePartitionSpec.java
##########
@@ -192,6 +211,12 @@ public BaseUpdatePartitionSpec removeField(Term term) {
 
   @Override
   public BaseUpdatePartitionSpec renameField(String name, String newName) {
+    PartitionField existingField = nameToField.get(newName);
+    if (existingField != null && isVoidTransform(existingField)) {
+      // rename the old deleted field that is being replaced by the new field
+      renameField(existingField.name(), existingField.name() + "_" + 
UUID.randomUUID());

Review comment:
       change to `existingField.fieldId()`

##########
File path: core/src/main/java/org/apache/iceberg/BaseUpdatePartitionSpec.java
##########
@@ -145,11 +146,29 @@ public BaseUpdatePartitionSpec addField(String name, Term 
term) {
     checkForRedundantAddedPartitions(newField);
 
     transformToAddedField.put(validationKey, newField);
-    if (name != null) {
-      nameToAddedField.put(name, newField);
+
+    String partitionName;
+    if (newField.name() != null) {
+      partitionName = newField.name();
+    } else {
+      partitionName = PartitionSpecVisitor.visit(schema, newField, 
PartitionNameGenerator.INSTANCE);
     }
 
-    adds.add(newField);
+    PartitionField existingField = nameToField.get(partitionName);
+    if (existingField != null) {
+      if (isVoidTransform(existingField)) {
+        // rename the old deleted field that is being replaced by the new field
+        renameField(existingField.name(), existingField.name() + "_" + 
UUID.randomUUID());

Review comment:
       use the existing field's ID instead.




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