xinbinhuang commented on a change in pull request #3059:
URL: https://github.com/apache/iceberg/pull/3059#discussion_r753510975



##########
File path: core/src/main/java/org/apache/iceberg/DataFiles.java
##########
@@ -218,7 +219,9 @@ public Builder withFormat(FileFormat newFormat) {
     }
 
     public Builder withPartition(StructLike newPartition) {
-      this.partitionData = copyPartitionData(spec, newPartition, 
partitionData);
+      if (isPartitioned) {
+        this.partitionData = copyPartitionData(spec, newPartition, 
partitionData);
+      }

Review comment:
       @aokolnychyi Do you mind taking a look at this change?
   
   I have a chat with @RussellSpitzer offline, and would love to have your 
thoughts on this.
   
   The current implementation
   - works similar to how we do check for other methods inside the builder
       - 
https://github.com/apache/iceberg/blob/73ee251be87094183cf062f95d042c06b2acc6d5/core/src/main/java/org/apache/iceberg/DataFiles.java#L238-L245
       -  
https://github.com/apache/iceberg/blob/73ee251be87094183cf062f95d042c06b2acc6d5/core/src/main/java/org/apache/iceberg/DataFiles.java#L259-L266
   - Compatible with builder's whole building logics 
       - builder assign `partitionData` to be `null` if the spec is not 
partitioned: 
https://github.com/apache/iceberg/blob/73ee251be87094183cf062f95d042c06b2acc6d5/core/src/main/java/org/apache/iceberg/DataFiles.java#L141
       - And it do another check and pass in `null` to the final 
`GenericDataFile`: 
https://github.com/apache/iceberg/blob/73ee251be87094183cf062f95d042c06b2acc6d5/core/src/main/java/org/apache/iceberg/DataFiles.java#L294
   
   Alternatively, we are thinking:
   ```java
   GenericRecord emptyRecord = GenericRecord.create(spec.schema());
   delegate = writerFactory.newDataWriter(outputFile, spec, emptyRecord);
   ```
   at around here: 
https://github.com/apache/iceberg/blob/1e5abcece00d835235dccf0b902ffd988cbded0d/spark/v3.2/spark/src/main/java/org/apache/iceberg/spark/source/SparkWrite.java#L594




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