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/incubator-paimon.git


The following commit(s) were added to refs/heads/master by this push:
     new f5225b628 [flink] clear schema after create/alter hive table error 
(#1662)
f5225b628 is described below

commit f5225b6284ef4c24d0c9d1e2254ebeaea0c31416
Author: JunZhang <[email protected]>
AuthorDate: Mon Jul 31 13:28:45 2023 +0800

    [flink] clear schema after create/alter hive table error (#1662)
---
 .../java/org/apache/paimon/hive/HiveCatalog.java   |  6 ++---
 .../apache/paimon/hive/HiveCatalogITCaseBase.java  | 26 ++++++++++++++++++++++
 2 files changed, 29 insertions(+), 3 deletions(-)

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 5b263f262..ea9e91139 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
@@ -313,10 +313,10 @@ public class HiveCatalog extends AbstractCatalog {
                     e);
         }
         Table table = newHmsTable(identifier);
-        updateHmsTable(table, identifier, tableSchema);
         try {
+            updateHmsTable(table, identifier, tableSchema);
             client.createTable(table);
-        } catch (TException e) {
+        } catch (Exception e) {
             Path path = getDataTableLocation(identifier);
             try {
                 fileIO.deleteDirectoryQuietly(path);
@@ -381,7 +381,7 @@ public class HiveCatalog extends AbstractCatalog {
             Table table = client.getTable(identifier.getDatabaseName(), 
identifier.getObjectName());
             updateHmsTable(table, identifier, schema);
             client.alter_table(identifier.getDatabaseName(), 
identifier.getObjectName(), table);
-        } catch (TException te) {
+        } catch (Exception te) {
             schemaManager.deleteSchema(schema.id());
             throw new RuntimeException(te);
         }
diff --git 
a/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveCatalogITCaseBase.java
 
b/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveCatalogITCaseBase.java
index 17c50b48f..32346a404 100644
--- 
a/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveCatalogITCaseBase.java
+++ 
b/paimon-hive/paimon-hive-connector-common/src/test/java/org/apache/paimon/hive/HiveCatalogITCaseBase.java
@@ -27,6 +27,7 @@ import org.apache.paimon.fs.local.LocalFileIO;
 import org.apache.paimon.hive.annotation.Minio;
 import org.apache.paimon.hive.runner.PaimonEmbeddedHiveRunner;
 import org.apache.paimon.s3.MinioTestContainer;
+import org.apache.paimon.table.FileStoreTable;
 
 import com.klarna.hiverunner.HiveShell;
 import com.klarna.hiverunner.annotations.HiveSQL;
@@ -60,6 +61,7 @@ import java.util.Map;
 import java.util.Objects;
 import java.util.UUID;
 import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
@@ -751,6 +753,30 @@ public abstract class HiveCatalogITCaseBase {
         Assertions.assertThat(tableOptions).doesNotContainKey("lock.enabled");
     }
 
+    @Test
+    public void testClearSchemaAfterUnSupportType()
+            throws InterruptedException, ExecutionException, 
Catalog.TableNotExistException {
+        try {
+            tEnv.executeSql("CREATE TABLE t001(id INT PRIMARY KEY NOT ENFORCED 
, d TIME)").await();
+        } catch (Throwable t) {
+            ExceptionUtils.assertThrowableWithMessage(t, "Unsupported logical 
type TIME(0)");
+        }
+        Identifier identifier = new Identifier("test_db", "t001");
+        Catalog catalog =
+                ((FlinkCatalog) 
tEnv.getCatalog(tEnv.getCurrentCatalog()).get()).catalog();
+        Assert.assertFalse(catalog.tableExists(identifier));
+
+        tEnv.executeSql("CREATE TABLE  t002(id INT PRIMARY KEY NOT ENFORCED , 
b STRING)").await();
+        try {
+            tEnv.executeSql("ALTER TABLE t002 MODIFY b TIME").await();
+        } catch (Throwable t) {
+            ExceptionUtils.assertThrowableWithMessage(t, "Unsupported logical 
type TIME(0)");
+        }
+        identifier = new Identifier("test_db", "t002");
+        FileStoreTable table = (FileStoreTable) catalog.getTable(identifier);
+        Assert.assertEquals("[`id` INT NOT NULL, `b` STRING]", 
table.schema().fields().toString());
+    }
+
     @Test
     public void testAddPartitionsToMetastore() throws Exception {
         prepareTestAddPartitionsToMetastore();

Reply via email to