deniskuzZ commented on code in PR #6138:
URL: https://github.com/apache/hive/pull/6138#discussion_r2460447051


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergStorageHandler.java:
##########
@@ -929,14 +934,64 @@ public DynamicPartitionCtx createDPContext(
       addCustomSortExpr(table, hmsTable, writeOperation, dpCtx, 
getSortTransformSpec(table));
     }
 
+    // Even if table has no explicit sort order, honor z-order if configured
+    Map<String, String> props = table.properties();
+    if (ZORDER.equalsIgnoreCase(props.getOrDefault(SORT_ORDER, ""))) {
+      addZOrderCustomExpr(props, dpCtx, table, hmsTable, writeOperation);
+    }
+
     return dpCtx;
   }
 
+  /**
+   * Adds a custom sort expression to the DynamicPartitionCtx that performs 
local Z-ordering on write.
+   *
+   * Behavior:
+   * - Reads Z-order properties from 'sort.order' and 'sort.columns' 
(comma-separated).
+   * - Resolves the referenced columns to their positions in the physical row 
(taking into account
+   *   ACID virtual columns offset for overwrite/update operations).
+   */
+  private void addZOrderCustomExpr(Map<String, String> props, 
DynamicPartitionCtx dpCtx, Table table,
+          org.apache.hadoop.hive.ql.metadata.Table hmsTable, Operation 
writeOperation) {
+    String colsProp = props.get(SORT_COLUMNS);
+    if (StringUtils.isNotBlank(colsProp)) {
+      List<String> zCols = Arrays.stream(colsProp.split(","))
+              .map(String::trim)

Review Comment:
   why 2 tabs? can you change formatting to just 1 the whole PR



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