This is an automated email from the ASF dual-hosted git repository.

lzljs3620320 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new 8688206d73 [hive] Make HiveCatalog alterTable works for Hive 1.x
8688206d73 is described below

commit 8688206d731ea0762b82980097ca2141c9acded2
Author: Jingsong <[email protected]>
AuthorDate: Sun Nov 24 23:34:01 2024 +0800

    [hive] Make HiveCatalog alterTable works for Hive 1.x
---
 .../apache/paimon/hive/HiveAlterTableUtils.java    | 54 ++++++++++++++++++++++
 .../java/org/apache/paimon/hive/HiveCatalog.java   | 23 +--------
 2 files changed, 55 insertions(+), 22 deletions(-)

diff --git 
a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveAlterTableUtils.java
 
b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveAlterTableUtils.java
new file mode 100644
index 0000000000..8f77499486
--- /dev/null
+++ 
b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveAlterTableUtils.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.paimon.hive;
+
+import org.apache.paimon.catalog.Identifier;
+
+import org.apache.hadoop.hive.common.StatsSetupConst;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.api.EnvironmentContext;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.thrift.TException;
+
+/** Utils for hive alter table. */
+public class HiveAlterTableUtils {
+
+    public static void alterTable(IMetaStoreClient client, Identifier 
identifier, Table table)
+            throws TException {
+        try {
+            alterTableWithEnv(client, identifier, table);
+        } catch (NoClassDefFoundError | NoSuchMethodError e) {
+            alterTableWithoutEnv(client, identifier, table);
+        }
+    }
+
+    private static void alterTableWithEnv(
+            IMetaStoreClient client, Identifier identifier, Table table) 
throws TException {
+        EnvironmentContext environmentContext = new EnvironmentContext();
+        environmentContext.putToProperties(StatsSetupConst.CASCADE, "true");
+        
environmentContext.putToProperties(StatsSetupConst.DO_NOT_UPDATE_STATS, 
"false");
+        client.alter_table_with_environmentContext(
+                identifier.getDatabaseName(), identifier.getTableName(), 
table, environmentContext);
+    }
+
+    private static void alterTableWithoutEnv(
+            IMetaStoreClient client, Identifier identifier, Table table) 
throws TException {
+        client.alter_table(identifier.getDatabaseName(), 
identifier.getTableName(), table, true);
+    }
+}
diff --git 
a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java
 
b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java
index 0f2fb6fa9d..b92c3b59d9 100644
--- 
a/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java
+++ 
b/paimon-hive/paimon-hive-catalog/src/main/java/org/apache/paimon/hive/HiveCatalog.java
@@ -56,12 +56,10 @@ import org.apache.paimon.view.ViewImpl;
 import org.apache.flink.table.hive.LegacyHiveClasses;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileSystem;
-import org.apache.hadoop.hive.common.StatsSetupConst;
 import org.apache.hadoop.hive.conf.HiveConf;
 import org.apache.hadoop.hive.metastore.IMetaStoreClient;
 import org.apache.hadoop.hive.metastore.TableType;
 import org.apache.hadoop.hive.metastore.api.Database;
-import org.apache.hadoop.hive.metastore.api.EnvironmentContext;
 import org.apache.hadoop.hive.metastore.api.FieldSchema;
 import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
 import org.apache.hadoop.hive.metastore.api.SerDeInfo;
@@ -87,7 +85,6 @@ import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Objects;
 import java.util.Optional;
 import java.util.Set;
 import java.util.function.Function;
@@ -876,25 +873,7 @@ public class HiveCatalog extends AbstractCatalog {
         updateHmsTablePars(table, newSchema);
         Path location = getTableLocation(identifier, table);
         updateHmsTable(table, identifier, newSchema, 
newSchema.options().get("provider"), location);
-        clients.execute(
-                client ->
-                        client.alter_table_with_environmentContext(
-                                identifier.getDatabaseName(),
-                                identifier.getTableName(),
-                                table,
-                                createHiveEnvironmentContext()));
-    }
-
-    private EnvironmentContext createHiveEnvironmentContext() {
-        EnvironmentContext environmentContext = new EnvironmentContext();
-        environmentContext.putToProperties(StatsSetupConst.CASCADE, "true");
-        if (Objects.isNull(options)) {
-            return environmentContext;
-        }
-        environmentContext.putToProperties(
-                StatsSetupConst.DO_NOT_UPDATE_STATS,
-                options.getString(StatsSetupConst.DO_NOT_UPDATE_STATS, 
"false"));
-        return environmentContext;
+        clients.execute(client -> HiveAlterTableUtils.alterTable(client, 
identifier, table));
     }
 
     @Override

Reply via email to