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



##########
File path: core/src/main/java/org/apache/iceberg/TableMetadata.java
##########
@@ -679,10 +700,23 @@ private TableMetadata setCurrentSnapshotTo(Snapshot 
snapshot) {
 
   public TableMetadata replaceProperties(Map<String, String> newProperties) {
     ValidationException.check(newProperties != null, "Cannot set properties to 
null");
-    return new TableMetadata(null, formatVersion, uuid, location,
+    Map<String, String> validProperties = newProperties;
+    int newFormatVersion = formatVersion;
+    if (newProperties.containsKey(PROPERTY_FORMAT_VERSION)) {
+      validProperties = Maps.newHashMap(newProperties);
+      newFormatVersion = 
Integer.parseInt(validProperties.remove(PROPERTY_FORMAT_VERSION));
+    }
+
+    TableMetadata metadata = new TableMetadata(null, formatVersion, uuid, 
location,
         lastSequenceNumber, System.currentTimeMillis(), lastColumnId, 
currentSchemaId, schemas, defaultSpecId, specs,
-        lastAssignedPartitionId, defaultSortOrderId, sortOrders, 
newProperties, currentSnapshotId, snapshots,
-        snapshotLog, addPreviousFile(file, lastUpdatedMillis, newProperties));
+        lastAssignedPartitionId, defaultSortOrderId, sortOrders, 
validProperties, currentSnapshotId, snapshots,
+        snapshotLog, addPreviousFile(file, lastUpdatedMillis, 
validProperties));
+
+    if (formatVersion != newFormatVersion) {
+      metadata = metadata.upgradeToFormatVersion(newFormatVersion);

Review comment:
       It seems a bit weird to call another instance method to produce a second 
`TableMetadata` here. I'm thinking that maybe the builder pattern would work 
better for complicated cases... Seems fine for now though.




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