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



##########
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:
       The `PartitionField` is created in this method, as is `partitionName`. I 
think that by reordering a couple of statements here, you can use the correct 
name on the field from the start and avoid more changes.

##########
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:
       Why use `UUID.randomUUID()` instead of the partition field ID? I think 
it makes more sense to use `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:
       Here as well, I'd prefer not to use a UUID. This should be able to 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