This is an automated email from the ASF dual-hosted git repository.
yuqi1129 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new 62a948972d [#13923] fix(starrocks): reject unsupported indexes when
creating tables (#13924)
62a948972d is described below
commit 62a948972d5b7e8762020ccc099a52f7cfc91331
Author: Qi Yu <[email protected]>
AuthorDate: Mon Oct 19 14:07:28 2026 +0800
[#13923] fix(starrocks): reject unsupported indexes when creating tables
(#13924)
### What changes were proposed in this pull request?
Reject non-empty index definitions in the StarRocks CREATE TABLE SQL
generator before acquiring a database connection. Return an
unsupported-operation error that tells the caller to remove the index
definitions, and document this behavior.
### Why are the changes needed?
The StarRocks connector silently ignores requested indexes, while the
create response echoes them back. The catalog documentation already
marks indexes as unsupported. Rejecting these requests prevents creating
a table whose definition differs from the successful response.
Fix: #13923
### Does this PR introduce _any_ user-facing change?
StarRocks create-table requests with non-empty `indexes` now fail
explicitly. Null and empty index arrays retain their existing behavior.
### How was this patch tested?
- Ran `./gradlew :catalogs:catalog-jdbc-starrocks:spotlessApply`.
- Ran `./gradlew :catalogs:catalog-jdbc-starrocks:test -PskipITs
-PskipDockerTests=true`: 34 tests passed with Docker tests excluded.
- Added tests for all 21 index types, rejection before acquiring a
connection, and unchanged SQL for null/empty index arrays.
- Temporarily removed the validation: all 21 rejection cases failed as
expected. Restored the fix and reran the module tests successfully.
---
.../operations/StarRocksTableOperations.java | 6 ++
.../TestStarRocksTableOperationsSqlGeneration.java | 66 +++++++++++++++++++++-
docs/jdbc-starrocks-catalog.md | 2 +-
3 files changed, 72 insertions(+), 2 deletions(-)
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 f7b9dbd06a..e94615f4c2 100644
--- a/docs/jdbc-starrocks-catalog.md
+++ b/docs/jdbc-starrocks-catalog.md
@@ -153,7 +153,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