aokolnychyi commented on a change in pull request #1373:
URL: https://github.com/apache/iceberg/pull/1373#discussion_r477696898



##########
File path: core/src/main/java/org/apache/iceberg/TableMetadata.java
##########
@@ -598,20 +649,39 @@ public TableMetadata buildReplacement(Schema 
updatedSchema, PartitionSpec update
       builder.add(freshSpec);
     }
 
+    // determine the next order id
+    int maxOrderId = 
sortOrders.stream().mapToInt(SortOrder::orderId).max().orElse(INITIAL_SORT_ORDER_ID);
+    int nextOrderId = maxOrderId + 1;
+
+    // rebuild the sort order using new column ids
+    SortOrder freshSortOrder = freshSortOrder(nextOrderId, freshSchema, 
updatedSortOrder);
+
+    // if the order already exists, use the same ID. otherwise, use 1 more 
than the highest ID.
+    Optional<SortOrder> sameSortOrder = sortOrders.stream()
+        .filter(sortOrder -> sortOrder.sameOrder(freshSortOrder))
+        .findAny();
+    int orderId = sameSortOrder.map(SortOrder::orderId).orElse(nextOrderId);
+
+    ImmutableList.Builder<SortOrder> sortOrdersBuilder = 
ImmutableList.<SortOrder>builder().addAll(sortOrders);

Review comment:
       This place, probably, requires additional attention. I've added a test 
to `TestReplaceTransaction`.




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