rdblue commented on a change in pull request #499: Add persistent IDs to 
partition fields (WIP)
URL: https://github.com/apache/incubator-iceberg/pull/499#discussion_r361010372
 
 

 ##########
 File path: core/src/main/java/org/apache/iceberg/TableMetadata.java
 ##########
 @@ -471,26 +482,33 @@ private static PartitionSpec updateSpecSchema(Schema 
schema, PartitionSpec parti
 
     // add all of the fields to the builder. IDs should not change.
     for (PartitionField field : partitionSpec.fields()) {
-      specBuilder.add(field.sourceId(), field.name(), 
field.transform().toString());
+      specBuilder.add(field.sourceId(), field.fieldId(), field.name(), 
field.transform().toString());
     }
 
     return specBuilder.build();
   }
 
-  private static PartitionSpec freshSpec(int specId, Schema schema, 
PartitionSpec partitionSpec) {
-    PartitionSpec.Builder specBuilder = PartitionSpec.builderFor(schema)
+  private static PartitionSpec freshSpecWithAssignIds(int specId, Schema 
newSchema, Schema oldSchema,
+                                                      PartitionSpec 
partitionSpec, AtomicInteger nextPartitionFieldId,
+                                                      Map<String, Integer> 
partitionFieldIdByColumnName) {
+
+    PartitionSpec.Builder specBuilder = PartitionSpec.builderFor(newSchema)
         .withSpecId(specId);
 
     for (PartitionField field : partitionSpec.fields()) {
       // look up the name of the source field in the old schema to get the new 
schema's id
-      String sourceName = 
partitionSpec.schema().findColumnName(field.sourceId());
+      String sourceName = oldSchema.findColumnName(field.sourceId());
       specBuilder.add(
-          schema.findField(sourceName).fieldId(),
+          newSchema.findField(sourceName).fieldId(),
+          // increment and assign new id, if this column_transform has not 
used in partition yet.
+          (partitionFieldIdByColumnName == null) ? 
nextPartitionFieldId.incrementAndGet()
+          : ((partitionFieldIdByColumnName.containsKey(field.name())) ? 
partitionFieldIdByColumnName.get(field.name())
+              : nextPartitionFieldId.incrementAndGet()),
           field.name(),
           field.transform().toString());
     }
-
-    return specBuilder.build();
+    PartitionSpec freshSpec = specBuilder.build();
+    return freshSpec;
 
 Review comment:
   Looks like this change is unnecessary.

----------------------------------------------------------------
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:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to