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 c835583b5 [hive] Hive catalog, name should be lower case (#994)
c835583b5 is described below

commit c835583b5aac3b6d25a2997272139d5e0da6c2c2
Author: zhaoym <[email protected]>
AuthorDate: Thu Apr 27 12:16:03 2023 +0800

    [hive] Hive catalog, name should be lower case (#994)
---
 docs/content/how-to/creating-catalogs.md           |  2 ++
 .../java/org/apache/paimon/hive/HiveCatalog.java   | 27 +++++++++++++++++++---
 .../org/apache/paimon/hive/HiveCatalogTest.java    |  6 +++--
 .../apache/paimon/hive/HiveCatalogITCaseBase.java  | 12 ++++++++--
 4 files changed, 40 insertions(+), 7 deletions(-)

diff --git a/docs/content/how-to/creating-catalogs.md 
b/docs/content/how-to/creating-catalogs.md
index 71efc7a9a..d24c8ea1c 100644
--- a/docs/content/how-to/creating-catalogs.md
+++ b/docs/content/how-to/creating-catalogs.md
@@ -80,6 +80,8 @@ USE paimon.default;
 
 By using Paimon Hive catalog, changes to the catalog will directly affect the 
corresponding Hive metastore. Tables created in such catalog can also be 
accessed directly from Hive.
 
+To use Hive catalog, Database name, Table name and Field names should be lower 
case.
+
 {{< tabs "hive-metastore-example" >}}
 
 {{< tab "Flink" >}}
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 d8c75dd79..ea77d7e14 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
@@ -305,6 +305,7 @@ public class HiveCatalog extends AbstractCatalog {
         }
 
         try {
+            checkIdentifierUpperCase(toTable);
             String fromDB = fromTable.getDatabaseName();
             String fromTableName = fromTable.getObjectName();
             Table table = client.getTable(fromDB, fromTableName);
@@ -329,6 +330,7 @@ public class HiveCatalog extends AbstractCatalog {
             }
         }
 
+        checkFieldNamesUpperCaseInSchemaChange(changes);
         try {
             final SchemaManager schemaManager = schemaManager(identifier);
             // first commit changes to underlying files
@@ -368,12 +370,29 @@ public class HiveCatalog extends AbstractCatalog {
         checkState(
                 
identifier.getDatabaseName().equals(identifier.getDatabaseName().toLowerCase()),
                 String.format(
-                        "Database name[%s] cannot contain upper case",
+                        "Database name[%s] cannot contain upper case in hive 
catalog",
                         identifier.getDatabaseName()));
         checkState(
                 
identifier.getObjectName().equals(identifier.getObjectName().toLowerCase()),
                 String.format(
-                        "Table name[%s] cannot contain upper case", 
identifier.getObjectName()));
+                        "Table name[%s] cannot contain upper case in hive 
catalog",
+                        identifier.getObjectName()));
+    }
+
+    private void checkFieldNamesUpperCaseInSchemaChange(List<SchemaChange> 
changes) {
+        List<String> fieldNames = new ArrayList<>();
+        for (SchemaChange change : changes) {
+            if (change instanceof SchemaChange.AddColumn) {
+                SchemaChange.AddColumn addColumn = (SchemaChange.AddColumn) 
change;
+                fieldNames.add(addColumn.fieldName());
+            } else if (change instanceof SchemaChange.RenameColumn) {
+                SchemaChange.RenameColumn rename = (SchemaChange.RenameColumn) 
change;
+                fieldNames.add(rename.newName());
+            } else {
+                // do nothing
+            }
+        }
+        checkFieldNamesUpperCase(fieldNames);
     }
 
     private void checkFieldNamesUpperCase(List<String> fieldNames) {
@@ -383,7 +402,9 @@ public class HiveCatalog extends AbstractCatalog {
                         .collect(Collectors.toList());
         checkState(
                 illegalFieldNames.isEmpty(),
-                String.format("Field names %s cannot contain upper case", 
illegalFieldNames));
+                String.format(
+                        "Field names %s cannot contain upper case in hive 
catalog",
+                        illegalFieldNames));
     }
 
     private Database convertToDatabase(String name) {
diff --git 
a/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/HiveCatalogTest.java
 
b/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/HiveCatalogTest.java
index cc490c7ed..6695e1d3e 100644
--- 
a/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/HiveCatalogTest.java
+++ 
b/paimon-hive/paimon-hive-catalog/src/test/java/org/apache/paimon/hive/HiveCatalogTest.java
@@ -72,7 +72,8 @@ public class HiveCatalogTest extends CatalogTestBase {
                                         DEFAULT_TABLE_SCHEMA,
                                         false))
                 .hasRootCauseInstanceOf(IllegalStateException.class)
-                .hasRootCauseMessage("Database name[TEST_DB] cannot contain 
upper case");
+                .hasRootCauseMessage(
+                        "Database name[TEST_DB] cannot contain upper case in 
hive catalog");
 
         assertThatThrownBy(
                         () ->
@@ -81,7 +82,8 @@ public class HiveCatalogTest extends CatalogTestBase {
                                         DEFAULT_TABLE_SCHEMA,
                                         false))
                 .hasRootCauseInstanceOf(IllegalStateException.class)
-                .hasRootCauseMessage("Table name[NEW_TABLE] cannot contain 
upper case");
+                .hasRootCauseMessage(
+                        "Table name[NEW_TABLE] cannot contain upper case in 
hive catalog");
     }
 
     private static final String HADOOP_CONF_DIR =
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 1065a51db..3528b4a92 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
@@ -429,6 +429,11 @@ public abstract class HiveCatalogITCaseBase {
                 .hasMessage(
                         "Could not execute ALTER TABLE my_hive.test_db.t1 
RENAME TO my_hive.test_db.t2");
 
+        // the target table name has upper case.
+        assertThatThrownBy(() -> tEnv.executeSql("ALTER TABLE t1 RENAME TO 
T1"))
+                .hasMessage(
+                        "Could not execute ALTER TABLE my_hive.test_db.t1 
RENAME TO my_hive.test_db.T1");
+
         tEnv.executeSql("ALTER TABLE t1 RENAME TO t3").await();
         List<String> tables = hiveShell.executeQuery("SHOW TABLES");
         Assert.assertTrue(tables.contains("t3"));
@@ -497,7 +502,8 @@ public abstract class HiveCatalogITCaseBase {
                                                 "CREATE TABLE T ( a INT, b 
STRING ) WITH ( 'file.format' = 'avro' )")
                                         .await())
                 .hasRootCauseMessage(
-                        String.format("Table name[%s] cannot contain upper 
case", "T"));
+                        String.format(
+                                "Table name[%s] cannot contain upper case in 
hive catalog", "T"));
 
         assertThatThrownBy(
                         () ->
@@ -505,7 +511,9 @@ public abstract class HiveCatalogITCaseBase {
                                                 "CREATE TABLE t (A INT, b 
STRING, C STRING) WITH ( 'file.format' = 'avro')")
                                         .await())
                 .hasRootCauseMessage(
-                        String.format("Field names %s cannot contain upper 
case", "[A, C]"));
+                        String.format(
+                                "Field names %s cannot contain upper case in 
hive catalog",
+                                "[A, C]"));
     }
 
     @Test

Reply via email to