pvary commented on code in PR #6570:
URL: https://github.com/apache/iceberg/pull/6570#discussion_r1174885729


##########
hive-metastore/src/main/java/org/apache/iceberg/hive/MetastoreUtil.java:
##########
@@ -48,14 +50,28 @@ public class MetastoreUtil {
   private MetastoreUtil() {}
 
   /**
-   * Calls alter_table method using the metastore client. If possible, an 
environmental context will
-   * be used that turns off stats updates to avoid recursive listing.
+   * Calls alter_table method using the metastore client. If the HMS supports 
then, environmental
+   * context with will be set in a way that turns off stats updates to avoid 
recursive file listing.
    */
   public static void alterTable(
       IMetaStoreClient client, String databaseName, String tblName, Table 
table) {
-    EnvironmentContext envContext =
-        new EnvironmentContext(
-            ImmutableMap.of(StatsSetupConst.DO_NOT_UPDATE_STATS, 
StatsSetupConst.TRUE));
-    ALTER_TABLE.invoke(client, databaseName, tblName, table, envContext);
+    alterTable(client, databaseName, tblName, table, ImmutableMap.of());
+  }
+
+  /**
+   * Calls alter_table method using the metastore client. If the HMS supports 
then, environmental
+   * context with will be set in a way that turns off stats updates to avoid 
recursive file listing.
+   */
+  public static void alterTable(
+      IMetaStoreClient client,
+      String databaseName,
+      String tblName,
+      Table table,
+      Map<String, String> extraEnv) {
+    Map<String, String> env = Maps.newHashMapWithExpectedSize(extraEnv.size() 
+ 1);
+    env.putAll(extraEnv);
+    env.put(StatsSetupConst.DO_NOT_UPDATE_STATS, StatsSetupConst.TRUE);
+

Review Comment:
   We always add `ImmutableMap.of(StatsSetupConst.DO_NOT_UPDATE_STATS, 
StatsSetupConst.TRUE)` which is an optimisation for skipping stats generation / 
file listing when it is not needed on alter table commands. This always 
depended on DynMethod skipping last parameters (maybe by accident)
   
   See: 
https://github.com/apache/iceberg/blob/fede493d59f17ff2bfc0744b296d90bd36130386/hive-metastore/src/main/java/org/apache/iceberg/hive/MetastoreUtil.java#L56-L59
   
   We can modify the proposed command to:
   ```
   if (env.size() > 1) {
     Preconditions.checkArgument("Environment context is non-empty but 
alter_table method does not support it", 
     ALTER_TABLE.args().size() == 5);
   }
   ```
   
   Or add a new check to the the new `alterTable` method, but I find it better 
/ more readable to add the check to the NoLock constructor.
   
   WDYT?



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