difin commented on code in PR #5995:
URL: https://github.com/apache/hive/pull/5995#discussion_r2285076927


##########
iceberg/iceberg-catalog/src/main/java/org/apache/iceberg/hive/HMSTablePropertyHelper.java:
##########
@@ -131,20 +139,70 @@ public static void updateHmsTableForIcebergTable(
     tbl.setParameters(parameters);
   }
 
-  private static void setCommonParameters(
-      String newMetadataLocation,
-      String uuid,
-      Set<String> obsoleteProps,
-      String currentLocation,
-      Map<String, String> parameters,
-      String tableType,
-      Schema schema,
+  public static SortOrder getSortOrder(Properties props, Schema schema) {
+    String sortOrderJsonString = 
props.getProperty(TableProperties.DEFAULT_SORT_ORDER);
+    return Strings.isNullOrEmpty(sortOrderJsonString) ? SortOrder.unsorted() : 
SortOrderParser.fromJson(schema,
+        sortOrderJsonString);
+  }
+
+  /**
+   * Calculates the properties we would like to send to the catalog.
+   * <ul>
+   * <li>The base of the properties is the properties stored at the Hive 
Metastore for the given table
+   * <li>We add the {@link CatalogUtils#LOCATION} as the table location
+   * <li>We add the {@link CatalogUtils#NAME} as
+   * TableIdentifier defined by the database name and table name
+   * <li>We add the serdeProperties of the HMS table
+   * <li>We remove some parameters that we don't want to push down to the 
Iceberg table props
+   * </ul>
+   * @param hmsTable Table for which we are calculating the properties
+   * @return The properties we can provide for Iceberg functions
+   */
+  public static Properties 
getCatalogProperties(org.apache.hadoop.hive.metastore.api.Table hmsTable) {
+    Properties properties = new Properties();
+    properties.putAll(toIcebergProperties(hmsTable.getParameters()));
+
+    if (properties.get(CatalogUtils.LOCATION) == null && hmsTable.getSd() != 
null &&
+        hmsTable.getSd().getLocation() != null) {
+      properties.put(CatalogUtils.LOCATION, hmsTable.getSd().getLocation());
+    }
+
+    if (properties.get(CatalogUtils.NAME) == null) {
+      properties.put(CatalogUtils.NAME, 
TableIdentifier.of(hmsTable.getDbName(),
+          hmsTable.getTableName()).toString());
+    }
+
+    SerDeInfo serdeInfo = hmsTable.getSd().getSerdeInfo();
+    if (serdeInfo != null) {
+      properties.putAll(toIcebergProperties(serdeInfo.getParameters()));
+    }
+
+    // Remove HMS table parameters we don't want to propagate to Iceberg
+    PROPERTIES_TO_REMOVE.forEach(properties::remove);
+
+    return properties;
+  }
+
+  public static Properties toIcebergProperties(Map<String, String> parameters) 
{

Review Comment:
   done



-- 
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: gitbox-unsubscr...@hive.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org
For additional commands, e-mail: gitbox-h...@hive.apache.org

Reply via email to