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


##########
iceberg/iceberg-handler/src/main/java/org/apache/iceberg/mr/hive/BaseHiveIcebergMetaHook.java:
##########
@@ -202,6 +203,65 @@ public void preCreateTable(CreateTableRequest request) {
     // Remove hive primary key columns from table request, as iceberg doesn't 
support hive primary key.
     request.setPrimaryKeys(null);
     setSortOrder(hmsTable, schema, catalogProperties);
+    setWriteMetadataCleanupProperties(hmsTable.getParameters());
+  }
+
+  private void setWriteMetadataCleanupProperties(Map<String, String> 
hmsParams) {
+
+    boolean isEnabled = isConfigEnabled(
+        TableProperties.METADATA_DELETE_AFTER_COMMIT_ENABLED,
+        HIVE_ICEBERG_METADATA_DELETE_AFTER_COMMIT_ENABLED_DEFAULT,
+        hmsParams);
+
+    if (isEnabled) {
+      
catalogProperties.put(TableProperties.METADATA_DELETE_AFTER_COMMIT_ENABLED, 
true);
+
+      addCatalogProperty(
+          TableProperties.METADATA_PREVIOUS_VERSIONS_MAX,
+          TableProperties.METADATA_PREVIOUS_VERSIONS_MAX_DEFAULT,
+          hmsParams);
+    }
+  }
+
+  /*
+   * Determines whether a given configuration is enabled, following this 
precedence:
+   * 1. If the configuration exists in the HMS table parameters (hmsParams), 
use its boolean value.
+   * 2. Otherwise, check the session configuration (conf) and parse its 
boolean value if present.
+   * 3. If neither HMS parameters nor session configuration provide a value, 
return the specified defaultValue.
+   * This ensures that table-level settings override session settings, with a 
fallback to the default.
+   */
+  private boolean isConfigEnabled(String configName, boolean defaultValue, 
Map<String, String> hmsParams) {
+
+    String hmsParamValue = hmsParams.get(configName);
+    if (hmsParamValue != null) {
+      return Boolean.parseBoolean(hmsParamValue);
+    }
+
+    String hiveConfValue = conf.get(configName);
+    if (hiveConfValue != null) {
+      return Boolean.parseBoolean(hiveConfValue);
+    }
+
+    return defaultValue;
+  }
+
+  /*
+   * Adds a catalog property to catalogProperties using the following 
precedence:
+   * 1. If the property exists in the HMS table parameters (hmsParams), that 
value is always used.
+   * 2. Otherwise, the value is taken from the session configuration (conf),
+   *    falling back to the provided defaultValue if not set in the session.
+   * This ensures table-level parameters override session, with a fallback to 
the default.
+   */
+  private void addCatalogProperty(String key, Object defaultValue, Map<String, 
String> hmsParams) {

Review Comment:
   should we move this to CatalogUtils?



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