kokila-19 commented on code in PR #6256:
URL: https://github.com/apache/hive/pull/6256#discussion_r2690466030
##########
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:
I considered the BiConsumer approach but I don’t see a clear benefit here
since it introduces an extra level of indirection without reducing complexity.
The logic is a simple ASC vs DESC decision and directly mutates
replaceSortOrder, so an explicit if/else is more readable and easier to
understand and debug.
If there is significant advantage to using BiConsumer in this context, it
can be changed.
--
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]