jbewing commented on code in PR #15150:
URL: https://github.com/apache/iceberg/pull/15150#discussion_r2963807856


##########
spark/v4.1/spark/src/main/java/org/apache/iceberg/spark/SparkWriteConf.java:
##########
@@ -171,6 +172,26 @@ public int outputSpecId() {
     return outputSpecId;
   }
 
+  public int outputSortOrderId(SparkWriteRequirements writeRequirements) {
+    String explicitId =
+        
confParser.stringConf().option(SparkWriteOptions.OUTPUT_SORT_ORDER_ID).parseOptional();
+
+    if (explicitId != null) {
+      int id = Integer.parseInt(explicitId);
+      Preconditions.checkArgument(
+          table.sortOrders().containsKey(id),
+          "Cannot use output sort order id %s because the table does not 
contain a sort order with that id",
+          id);
+      return id;
+    }
+
+    if (writeRequirements.hasOrdering()) {
+      return table.sortOrder().orderId();

Review Comment:
   > Why are we using the table's sort order and not the ordering from the 
writeRequirements?
   
   There's lots of great candor outlining this above, but essentially iceberg 
sort order != spark sort order -> why this PR has a bit of complexity.
   
   The logic performed above essentially is saying:
   - if a sort order was explicitly pinned during a write w/ OUTPUT_SORT_ORDER 
(set by rewrite data files)
   - else, if spark has a sort order set, it _must_ correspond to the iceberg 
sort order
   
   I do agree that it's a bit clever and I had originally opted for a bit more 
of an explicit approach as agreed upon with the maintainers above. 



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