deniskuzZ commented on code in PR #6256:
URL: https://github.com/apache/hive/pull/6256#discussion_r2690128641
##########
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) {
+ replaceSortOrder.asc(fieldDesc.getColumnName(), nullOrder);
+ } else {
+ replaceSortOrder.desc(fieldDesc.getColumnName(), nullOrder);
+ }
+ }
+
+ replaceSortOrder.commit();
+
+ // Update HMS table parameters with the Iceberg SortOrder JSON
+ SortOrder newSortOrder = icebergTable.sortOrder();
+ hmsTableParameters.put(TableProperties.DEFAULT_SORT_ORDER,
SortOrderParser.toJson(newSortOrder));
+
+ LOG.info("Successfully set sort order for table {}: {}",
hmsTable.getTableName(), newSortOrder);
Review Comment:
should it be under debug?
--
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]