jackye1995 commented on a change in pull request #2957:
URL: https://github.com/apache/iceberg/pull/2957#discussion_r686513009



##########
File path: core/src/main/java/org/apache/iceberg/TableMetadata.java
##########
@@ -835,49 +856,41 @@ public TableMetadata buildReplacement(Schema 
updatedSchema, PartitionSpec update
       schemasBuilder.add(new Schema(freshSchemaId, freshSchema.columns(), 
freshSchema.identifierFieldIds()));
     }
 
-    TableMetadata metadata = new TableMetadata(null, formatVersion, uuid, 
newLocation,
-        lastSequenceNumber, System.currentTimeMillis(), newLastColumnId.get(), 
freshSchemaId, schemasBuilder.build(),
-        specId, specListBuilder.build(), Math.max(lastAssignedPartitionId, 
newSpec.lastAssignedFieldId()),
-        orderId, sortOrdersBuilder.build(), ImmutableMap.copyOf(newProperties),
-        -1, snapshots, ImmutableList.of(), addPreviousFile(file, 
lastUpdatedMillis, newProperties));
-
-    if (formatVersion != newFormatVersion) {
-      metadata = metadata.upgradeToFormatVersion(newFormatVersion);
-    }
-
-    return metadata;
+    return builder().from(this)
+        .refreshLastUpdateMillis()
+        .withFormatVersion(newFormatVersion)
+        .withLocation(newLocation)
+        .withLastColumnId(newLastColumnId.get())
+        .withCurrentSchemaId(freshSchemaId)
+        .withSchemas(schemasBuilder.build())
+        .withDefaultSpecId(specId)
+        .withSpecs(specListBuilder.build())
+        .withLastAssignedPartitionId(Math.max(lastAssignedPartitionId, 
newSpec.lastAssignedFieldId()))
+        .withDefaultSortOrderId(orderId)
+        .withSortOrders(sortOrdersBuilder.build())
+        .withProperties(ImmutableMap.copyOf(newProperties))
+        .withCurrentSnapshotId(INITIAL_SNAPSHOT_ID)
+        .withSnapshotLog(ImmutableList.of())
+        .build();
   }
 
   public TableMetadata updateLocation(String newLocation) {
-    return new TableMetadata(null, formatVersion, uuid, newLocation,
-        lastSequenceNumber, System.currentTimeMillis(), lastColumnId, 
currentSchemaId, schemas, defaultSpecId, specs,
-        lastAssignedPartitionId, defaultSortOrderId, sortOrders, properties, 
currentSnapshotId,
-        snapshots, snapshotLog, addPreviousFile(file, lastUpdatedMillis));
+    return builder().from(this)
+        .refreshLastUpdateMillis()
+        .withLocation(newLocation)
+        .build();
   }
 
   public TableMetadata upgradeToFormatVersion(int newFormatVersion) {
-    Preconditions.checkArgument(newFormatVersion <= 
SUPPORTED_TABLE_FORMAT_VERSION,

Review comment:
       this logic here is moved to the builder. What we are doing here is 
simple precondition checks and then directly run the constructor logic with the 
new format version, so the logic in the original PR to call 
upgradeToFormatVersion is unnecessary, and can be centralized to the build 
logic.




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