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


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/HiveIcebergMetaHook.java:
##########
@@ -624,15 +630,65 @@ private void 
alterTableProperties(org.apache.hadoop.hive.metastore.api.Table hms
     Map<String, String> hmsTableParameters = hmsTable.getParameters();
     Splitter splitter = Splitter.on(PROPERTIES_SEPARATOR);
     UpdateProperties icebergUpdateProperties = icebergTable.updateProperties();
+
     if (contextProperties.containsKey(SET_PROPERTIES)) {
-      splitter.splitToList(contextProperties.get(SET_PROPERTIES))
-          .forEach(k -> icebergUpdateProperties.set(k, 
hmsTableParameters.get(k)));
+      List<String> propertiesToSet = 
splitter.splitToList(contextProperties.get(SET_PROPERTIES));
+
+      // Define handlers for properties that need special processing
+      Map<String, Consumer<String>> propertyHandlers = Maps.newHashMap();
+      propertyHandlers.put(TableProperties.DEFAULT_SORT_ORDER,
+          key -> handleDefaultSortOrder(hmsTable, hmsTableParameters));
+
+      // Process each property using handlers or default behavior
+      propertiesToSet.forEach(key ->
+          propertyHandlers.getOrDefault(key,
+              k -> icebergUpdateProperties.set(k, hmsTableParameters.get(k))
+          ).accept(key)
+      );
     } else if (contextProperties.containsKey(UNSET_PROPERTIES)) {
       
splitter.splitToList(contextProperties.get(UNSET_PROPERTIES)).forEach(icebergUpdateProperties::remove);
     }
+
     icebergUpdateProperties.commit();
   }
 
+  /**
+   * Handles conversion of Hive SortFields JSON to Iceberg SortOrder.
+   * Uses Iceberg's replaceSortOrder() API to properly handle the reserved 
property.
+   */
+  private void 
handleDefaultSortOrder(org.apache.hadoop.hive.metastore.api.Table hmsTable,
+      Map<String, String> hmsTableParameters) {
+    String sortOrderJSONString = 
hmsTableParameters.get(TableProperties.DEFAULT_SORT_ORDER);
+
+    List<SortFieldDesc> sortFieldDescList = 
parseSortFieldsJSON(sortOrderJSONString);
+    if (sortFieldDescList != null) {
+      try {
+        ReplaceSortOrder replaceSortOrder = icebergTable.replaceSortOrder();
+
+        // Chain all the sort field additions
+        for (SortFieldDesc fieldDesc : sortFieldDescList) {
+          NullOrder nullOrder = convertNullOrder(fieldDesc.getNullOrdering());
+
+          if (fieldDesc.getDirection() == SortFieldDesc.SortDirection.ASC) {

Review Comment:
   we call set order just in 1 place, similar to 
https://github.com/apache/hive/pull/6256/files#diff-e7a6dc1b51c479f2b51a7b66596d321c7c0d4a2a2ccea09a5ea65d4e5c6e0f61R64-R67.
 I think it's more clear that use if else branching



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