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

diqiu50 pushed a commit to branch branch-1.3
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/branch-1.3 by this push:
     new 49bccb20f1 [Cherry-pick to branch-1.3] [#13024] 
fix(catalog-jdbc-postgresql): Quote table name in ALTER statements for 
mixed-case tables (#13026) (#13055)
49bccb20f1 is described below

commit 49bccb20f161748ce47d705c422c7a7795119ad7
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Thu Sep 10 11:50:58 2026 +0800

    [Cherry-pick to branch-1.3] [#13024] fix(catalog-jdbc-postgresql): Quote 
table name in ALTER statements for mixed-case tables (#13026) (#13055)
    
    **Cherry-pick Information:**
    - Original commit: 25de374597b28f7b35f2e88aac0d85c28aa8f57a
    - Target branch: `branch-1.3`
    - Status: ✅ Clean cherry-pick (no conflicts)
    
    Co-authored-by: Yuhui <[email protected]>
    Co-authored-by: Claude Sonnet 5 <[email protected]>
---
 .../operation/PostgreSqlTableOperations.java       | 10 ++++-
 ...TestPostgreSqlTableOperationsSqlGeneration.java | 50 +++++++++++++++++++++-
 2 files changed, 57 insertions(+), 3 deletions(-)

diff --git 
a/catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/operation/PostgreSqlTableOperations.java
 
b/catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/operation/PostgreSqlTableOperations.java
index 83be0efcaa..9ce61a0281 100644
--- 
a/catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/operation/PostgreSqlTableOperations.java
+++ 
b/catalogs/catalog-jdbc-postgresql/src/main/java/org/apache/gravitino/catalog/postgresql/operation/PostgreSqlTableOperations.java
@@ -563,7 +563,8 @@ public class PostgreSqlTableOperations extends 
JdbcTableOperations
       throw new NoSuchColumnException("Column %s does not exist.", col);
     }
 
-    StringBuilder sqlBuilder = new StringBuilder(ALTER_TABLE + 
jdbcTable.name());
+    StringBuilder sqlBuilder =
+        new StringBuilder(ALTER_TABLE + PG_QUOTE + jdbcTable.name() + 
PG_QUOTE);
     sqlBuilder
         .append("\n")
         .append(ALTER_COLUMN)
@@ -592,7 +593,8 @@ public class PostgreSqlTableOperations extends 
JdbcTableOperations
     if (null == column) {
       throw new NoSuchColumnException("Column %s does not exist.", col);
     }
-    StringBuilder sqlBuilder = new StringBuilder(ALTER_TABLE + 
jdbcTable.name());
+    StringBuilder sqlBuilder =
+        new StringBuilder(ALTER_TABLE + PG_QUOTE + jdbcTable.name() + 
PG_QUOTE);
     sqlBuilder
         .append("\n")
         .append(ALTER_COLUMN)
@@ -619,7 +621,9 @@ public class PostgreSqlTableOperations extends 
JdbcTableOperations
       throw new 
UnsupportedOperationException(POSTGRESQL_NOT_SUPPORT_NESTED_COLUMN_MSG);
     }
     return ALTER_TABLE
+        + PG_QUOTE
         + tableName
+        + PG_QUOTE
         + " RENAME COLUMN "
         + PG_QUOTE
         + renameColumn.fieldName()[0]
@@ -644,7 +648,9 @@ public class PostgreSqlTableOperations extends 
JdbcTableOperations
     StringBuilder columnDefinition = new StringBuilder();
     columnDefinition
         .append(ALTER_TABLE)
+        .append(PG_QUOTE)
         .append(lazyLoadTable.name())
+        .append(PG_QUOTE)
         .append(SPACE)
         .append("ADD COLUMN ")
         .append(PG_QUOTE)
diff --git 
a/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/operation/TestPostgreSqlTableOperationsSqlGeneration.java
 
b/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/operation/TestPostgreSqlTableOperationsSqlGeneration.java
index f428271c6a..2862f98412 100644
--- 
a/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/operation/TestPostgreSqlTableOperationsSqlGeneration.java
+++ 
b/catalogs/catalog-jdbc-postgresql/src/test/java/org/apache/gravitino/catalog/postgresql/operation/TestPostgreSqlTableOperationsSqlGeneration.java
@@ -64,7 +64,17 @@ public class TestPostgreSqlTableOperationsSqlGeneration {
     @Override
     protected JdbcTable getOrCreateTable(
         String databaseName, String tableName, JdbcTable lazyLoadCreateTable) {
-      return JdbcTable.builder().withName(tableName).build();
+      return JdbcTable.builder()
+          .withName(tableName)
+          .withColumns(
+              new JdbcColumn[] {
+                JdbcColumn.builder()
+                    .withName("col1")
+                    .withType(Types.VarCharType.of(255))
+                    .withNullable(true)
+                    .build()
+              })
+          .build();
     }
   }
 
@@ -146,4 +156,42 @@ public class TestPostgreSqlTableOperationsSqlGeneration {
             "COMMENT ON COLUMN \"test_table\".\"col2\" IS E'owner\\\\''s 
\"comment\"; --';"),
         alterSql);
   }
+
+  @Test
+  public void testMixedCaseTableNameIsQuotedOnAddColumn() {
+    TestablePostgreSqlTableOperations ops = new 
TestablePostgreSqlTableOperations();
+    String alterSql =
+        ops.alterTableSql(
+            "MixedCaseTbl", TableChange.addColumn(new String[] {"extra"}, 
Types.IntegerType.get()));
+    Assertions.assertTrue(alterSql.contains("ALTER TABLE \"MixedCaseTbl\""), 
alterSql);
+  }
+
+  @Test
+  public void testMixedCaseTableNameIsQuotedOnUpdateColumnDefaultValue() {
+    TestablePostgreSqlTableOperations ops = new 
TestablePostgreSqlTableOperations();
+    String alterSql =
+        ops.alterTableSql(
+            "MixedCaseTbl",
+            TableChange.updateColumnDefaultValue(
+                new String[] {"col1"}, Literals.of("abc", 
Types.VarCharType.of(255))));
+    Assertions.assertTrue(alterSql.contains("ALTER TABLE \"MixedCaseTbl\""), 
alterSql);
+  }
+
+  @Test
+  public void testMixedCaseTableNameIsQuotedOnUpdateColumnType() {
+    TestablePostgreSqlTableOperations ops = new 
TestablePostgreSqlTableOperations();
+    String alterSql =
+        ops.alterTableSql(
+            "MixedCaseTbl",
+            TableChange.updateColumnType(new String[] {"col1"}, 
Types.VarCharType.of(255)));
+    Assertions.assertTrue(alterSql.contains("ALTER TABLE \"MixedCaseTbl\""), 
alterSql);
+  }
+
+  @Test
+  public void testMixedCaseTableNameIsQuotedOnRenameColumn() {
+    TestablePostgreSqlTableOperations ops = new 
TestablePostgreSqlTableOperations();
+    String alterSql =
+        ops.alterTableSql("MixedCaseTbl", TableChange.renameColumn(new 
String[] {"col1"}, "col2"));
+    Assertions.assertTrue(alterSql.contains("ALTER TABLE \"MixedCaseTbl\""), 
alterSql);
+  }
 }

Reply via email to