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

yuqi1129 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 4ba643cec6 [Cherry-pick to branch-1.3] [#13923] fix(starrocks): reject 
unsupported indexes when creating tables (#13924) (#13934)
4ba643cec6 is described below

commit 4ba643cec61f0f849d0e69ca83a00f2ef5c52266
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon Oct 19 23:44:41 2026 +0800

    [Cherry-pick to branch-1.3] [#13923] fix(starrocks): reject unsupported 
indexes when creating tables (#13924) (#13934)
    
    **Cherry-pick Information:**
    - Original commit: 62a948972d5b7e8762020ccc099a52f7cfc91331
    - Target branch: `branch-1.3`
    - Status: Clean cherry-pick with an additional branch-1.3 compatibility
    fix.
    
    ### Backport compatibility fix
    
    Generate create-table SQL before acquiring the execution connection,
    matching main. This allows unsupported StarRocks indexes to be rejected
    before connecting, and avoids holding an execution connection while
    generators perform their own queries.
    
    ### Validation
    
    - JDBC common and StarRocks non-Docker unit suites passed (60 and 29
    tests), including all 16 index-rejection cases.
    - MySQL, PostgreSQL, and Doris table SQL-generation suites passed.
    - Spotless checks passed.
    
    ---------
    
    Co-authored-by: Qi Yu <[email protected]>
---
 .../jdbc/operation/JdbcTableOperations.java        | 23 ++++----
 .../operations/StarRocksTableOperations.java       |  6 ++
 .../TestStarRocksTableOperationsSqlGeneration.java | 66 +++++++++++++++++++++-
 docs/jdbc-starrocks-catalog.md                     |  2 +-
 4 files changed, 84 insertions(+), 13 deletions(-)

diff --git 
a/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/operation/JdbcTableOperations.java
 
b/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/operation/JdbcTableOperations.java
index 516b3c01b9..73ba6fe1b6 100644
--- 
a/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/operation/JdbcTableOperations.java
+++ 
b/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/operation/JdbcTableOperations.java
@@ -142,18 +142,19 @@ public abstract class JdbcTableOperations implements 
TableOperation {
       SortOrder[] sortOrders)
       throws TableAlreadyExistsException {
     LOG.info("Attempting to create table {} in database {}", tableName, 
databaseName);
+    // Generate SQL before borrowing the execution connection so validation 
can fail early and
+    // generators that query the server do not hold another connection while 
doing so.
+    String sql =
+        generateCreateTableSql(
+            tableName,
+            columns,
+            comment,
+            properties,
+            partitioning,
+            distribution,
+            indexes,
+            sortOrders);
     try (Connection connection = getConnection(databaseName)) {
-      String sql =
-          generateCreateTableSql(
-              tableName,
-              columns,
-              comment,
-              properties,
-              partitioning,
-              distribution,
-              indexes,
-              sortOrders);
-
       JdbcConnectorUtils.executeUpdate(connection, sql);
       LOG.info("Created table {} in database {} with SQL:\n{}", tableName, 
databaseName, sql);
     } catch (final SQLException se) {
diff --git 
a/catalogs/catalog-jdbc-starrocks/src/main/java/org/apache/gravitino/catalog/starrocks/operations/StarRocksTableOperations.java
 
b/catalogs/catalog-jdbc-starrocks/src/main/java/org/apache/gravitino/catalog/starrocks/operations/StarRocksTableOperations.java
index e123be6103..8d6af056fc 100644
--- 
a/catalogs/catalog-jdbc-starrocks/src/main/java/org/apache/gravitino/catalog/starrocks/operations/StarRocksTableOperations.java
+++ 
b/catalogs/catalog-jdbc-starrocks/src/main/java/org/apache/gravitino/catalog/starrocks/operations/StarRocksTableOperations.java
@@ -99,6 +99,12 @@ public class StarRocksTableOperations extends 
JdbcTableOperations {
       Distribution distribution,
       Index[] indexes) {
 
+    if (ArrayUtils.isNotEmpty(indexes)) {
+      throw new UnsupportedOperationException(
+          "StarRocks catalog does not support creating table indexes. "
+              + "Remove indexes from the create table request.");
+    }
+
     StringBuilder sqlBuilder = new StringBuilder();
     sqlBuilder.append(String.format("CREATE TABLE `%s` ( \n", tableName));
     // Add columns
diff --git 
a/catalogs/catalog-jdbc-starrocks/src/test/java/org/apache/gravitino/catalog/starrocks/operation/TestStarRocksTableOperationsSqlGeneration.java
 
b/catalogs/catalog-jdbc-starrocks/src/test/java/org/apache/gravitino/catalog/starrocks/operation/TestStarRocksTableOperationsSqlGeneration.java
index 12195a08cb..b16e0e96b4 100644
--- 
a/catalogs/catalog-jdbc-starrocks/src/test/java/org/apache/gravitino/catalog/starrocks/operation/TestStarRocksTableOperationsSqlGeneration.java
+++ 
b/catalogs/catalog-jdbc-starrocks/src/test/java/org/apache/gravitino/catalog/starrocks/operation/TestStarRocksTableOperationsSqlGeneration.java
@@ -18,6 +18,7 @@
  */
 package org.apache.gravitino.catalog.starrocks.operation;
 
+import java.sql.Connection;
 import java.util.Collections;
 import org.apache.gravitino.StringIdentifier;
 import org.apache.gravitino.catalog.jdbc.JdbcColumn;
@@ -32,10 +33,15 @@ import 
org.apache.gravitino.rel.expressions.distributions.Distribution;
 import org.apache.gravitino.rel.expressions.distributions.Distributions;
 import org.apache.gravitino.rel.expressions.literals.Literals;
 import org.apache.gravitino.rel.expressions.transforms.Transforms;
+import org.apache.gravitino.rel.indexes.Index;
 import org.apache.gravitino.rel.indexes.Indexes;
 import org.apache.gravitino.rel.types.Types;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EmptySource;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.NullSource;
 
 public class TestStarRocksTableOperationsSqlGeneration {
 
@@ -54,6 +60,15 @@ public class TestStarRocksTableOperationsSqlGeneration {
 
     public String createTableSql(
         String tableName, JdbcColumn[] columns, Distribution distribution, 
String comment) {
+      return createTableSql(tableName, columns, distribution, comment, 
Indexes.EMPTY_INDEXES);
+    }
+
+    String createTableSql(
+        String tableName,
+        JdbcColumn[] columns,
+        Distribution distribution,
+        String comment,
+        Index[] indexes) {
       return generateCreateTableSql(
           tableName,
           columns,
@@ -61,7 +76,7 @@ public class TestStarRocksTableOperationsSqlGeneration {
           Collections.emptyMap(),
           Transforms.EMPTY_TRANSFORM,
           distribution,
-          Indexes.EMPTY_INDEXES);
+          indexes);
     }
 
     public String alterTableSql(String tableName, TableChange... changes) {
@@ -79,6 +94,55 @@ public class TestStarRocksTableOperationsSqlGeneration {
     }
   }
 
+  @ParameterizedTest
+  @EnumSource(Index.IndexType.class)
+  void testCreateTableRejectsIndexesBeforeConnecting(Index.IndexType 
indexType) {
+    TestableStarRocksTableOperations ops =
+        new TestableStarRocksTableOperations() {
+          @Override
+          protected Connection getConnection(String databaseName) {
+            throw new AssertionError("Index validation must happen before 
acquiring a connection");
+          }
+        };
+    JdbcColumn column =
+        
JdbcColumn.builder().withName("col1").withType(Types.IntegerType.get()).build();
+    Index index = Indexes.of(indexType, "test_index", new String[][] 
{{"col1"}});
+
+    UnsupportedOperationException exception =
+        Assertions.assertThrows(
+            UnsupportedOperationException.class,
+            () ->
+                ops.create(
+                    "database",
+                    "test_table",
+                    new JdbcColumn[] {column},
+                    "comment",
+                    Collections.emptyMap(),
+                    Transforms.EMPTY_TRANSFORM,
+                    Distributions.hash(1, NamedReference.field("col1")),
+                    new Index[] {index}));
+
+    Assertions.assertEquals(
+        "StarRocks catalog does not support creating table indexes. "
+            + "Remove indexes from the create table request.",
+        exception.getMessage());
+  }
+
+  @ParameterizedTest
+  @NullSource
+  @EmptySource
+  void testCreateTableWithoutIndexes(Index[] indexes) {
+    TestableStarRocksTableOperations ops = new 
TestableStarRocksTableOperations();
+    JdbcColumn column =
+        
JdbcColumn.builder().withName("col1").withType(Types.IntegerType.get()).build();
+    Distribution distribution = Distributions.hash(1, 
NamedReference.field("col1"));
+
+    Assertions.assertEquals(
+        ops.createTableSql("test_table", new JdbcColumn[] {column}, 
distribution),
+        ops.createTableSql(
+            "test_table", new JdbcColumn[] {column}, distribution, "comment", 
indexes));
+  }
+
   @Test
   public void testCreateTableWithEmptyStringDefaultValue() {
     TestableStarRocksTableOperations ops = new 
TestableStarRocksTableOperations();
diff --git a/docs/jdbc-starrocks-catalog.md b/docs/jdbc-starrocks-catalog.md
index 178f8bf4d1..26839c4d33 100644
--- a/docs/jdbc-starrocks-catalog.md
+++ b/docs/jdbc-starrocks-catalog.md
@@ -149,7 +149,7 @@ Unsupported for now.
 
 ### Table Indexes
 
-Unsupported
+Unsupported. Creating a table with non-empty index definitions is rejected 
before the table is created.
 
 ### Table Partitioning
 

Reply via email to