This is an automated email from the ASF dual-hosted git repository. yuqi4733 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 29bb2fd1f6 [#8418] Improvement(catalog): StarRocks table alter operation trigger IllegalPropertyOperation on unknown properties (#8472) 29bb2fd1f6 is described below commit 29bb2fd1f6f855dcb5cc5d50a40baa805ce53fe5 Author: MaAng <ang.ma.mar...@gmail.com> AuthorDate: Tue Sep 9 11:37:05 2025 +0800 [#8418] Improvement(catalog): StarRocks table alter operation trigger IllegalPropertyOperation on unknown properties (#8472) ### What changes were proposed in this pull request? Add a new `IllegalPropertyException` which extends `GravitinoRuntimeException` to handle the unknown property issue in Starrocks. ### Why are the changes needed? Unknown properties in Starrocks can not be well handled. It throw an generic `GravitinoRuntimeException` when set up an unknown property to table. So raise this PR to add a new Custom Exception class to handle the case. Fix: #8418 ### Does this PR introduce _any_ user-facing change? NO ### How was this patch tested? run `./gradlew build` and passed all the UTs and ITs. run `./gradlew :catalogs:catalog-jdbc-starrocks:test --tests "org.apache.gravitino.catalog.starrocks.operation.TestStarRocksTableOperations" -PskipDockerTests=false` and passed docker test in `StarRocksTableOperations` --- .../exceptions/IllegalPropertyException.java | 49 ++++++++++++++++++++++ .../converter/StarRocksExceptionConverter.java | 7 ++++ .../operation/TestStarRocksTableOperations.java | 30 +++++++++++++ 3 files changed, 86 insertions(+) diff --git a/api/src/main/java/org/apache/gravitino/exceptions/IllegalPropertyException.java b/api/src/main/java/org/apache/gravitino/exceptions/IllegalPropertyException.java new file mode 100644 index 0000000000..b4c97e2a22 --- /dev/null +++ b/api/src/main/java/org/apache/gravitino/exceptions/IllegalPropertyException.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.exceptions; + +import com.google.errorprone.annotations.FormatMethod; +import com.google.errorprone.annotations.FormatString; + +/** An exception thrown when a property is invalid. */ +public class IllegalPropertyException extends GravitinoRuntimeException { + + /** + * Constructs a new exception with the specified detail message. + * + * @param message the detail message. + * @param args the arguments to the message. + */ + @FormatMethod + public IllegalPropertyException(@FormatString String message, Object... args) { + super(message, args); + } + + /** + * Constructs a new exception with the specified detail message and cause. + * + * @param cause the cause. + * @param message the detail message. + * @param args the arguments to the message. + */ + @FormatMethod + public IllegalPropertyException(Throwable cause, @FormatString String message, Object... args) { + super(cause, message, args); + } +} diff --git a/catalogs/catalog-jdbc-starrocks/src/main/java/org/apache/gravitino/catalog/starrocks/converter/StarRocksExceptionConverter.java b/catalogs/catalog-jdbc-starrocks/src/main/java/org/apache/gravitino/catalog/starrocks/converter/StarRocksExceptionConverter.java index 889ba3bcf8..af57eabd98 100644 --- a/catalogs/catalog-jdbc-starrocks/src/main/java/org/apache/gravitino/catalog/starrocks/converter/StarRocksExceptionConverter.java +++ b/catalogs/catalog-jdbc-starrocks/src/main/java/org/apache/gravitino/catalog/starrocks/converter/StarRocksExceptionConverter.java @@ -23,6 +23,7 @@ import java.sql.SQLException; import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter; import org.apache.gravitino.exceptions.ConnectionFailedException; import org.apache.gravitino.exceptions.GravitinoRuntimeException; +import org.apache.gravitino.exceptions.IllegalPropertyException; import org.apache.gravitino.exceptions.NoSuchColumnException; import org.apache.gravitino.exceptions.NoSuchPartitionException; import org.apache.gravitino.exceptions.NoSuchSchemaException; @@ -47,6 +48,7 @@ public class StarRocksExceptionConverter extends JdbcExceptionConverter { static final int CODE_NO_SUCH_COLUMN = 1054; static final int CODE_DELETE_NON_EXISTING_PARTITION = 1507; static final int CODE_PARTITION_ALREADY_EXISTS = 1517; + static final int CODE_GENERIC_ERROR = 5064; @SuppressWarnings("FormatStringAnnotation") @Override @@ -72,6 +74,11 @@ public class StarRocksExceptionConverter extends JdbcExceptionConverter { return new NoSuchPartitionException(se, se.getMessage()); case CODE_PARTITION_ALREADY_EXISTS: return new PartitionAlreadyExistsException(se, se.getMessage()); + case CODE_GENERIC_ERROR: + if (se.getMessage() != null && se.getMessage().contains("Unknown properties")) { + return new IllegalPropertyException(se, se.getMessage()); + } + return new GravitinoRuntimeException(se, se.getMessage()); default: if (se.getMessage() != null && se.getMessage().contains("Access denied")) { return new ConnectionFailedException(se, se.getMessage()); diff --git a/catalogs/catalog-jdbc-starrocks/src/test/java/org/apache/gravitino/catalog/starrocks/operation/TestStarRocksTableOperations.java b/catalogs/catalog-jdbc-starrocks/src/test/java/org/apache/gravitino/catalog/starrocks/operation/TestStarRocksTableOperations.java index fc8b804aec..d074ff0bfe 100644 --- a/catalogs/catalog-jdbc-starrocks/src/test/java/org/apache/gravitino/catalog/starrocks/operation/TestStarRocksTableOperations.java +++ b/catalogs/catalog-jdbc-starrocks/src/test/java/org/apache/gravitino/catalog/starrocks/operation/TestStarRocksTableOperations.java @@ -37,6 +37,7 @@ import org.apache.gravitino.catalog.jdbc.converter.JdbcTypeConverter; import org.apache.gravitino.catalog.jdbc.operation.JdbcTablePartitionOperations; import org.apache.gravitino.catalog.starrocks.converter.StarRocksTypeConverter; import org.apache.gravitino.catalog.starrocks.operations.StarRocksTablePartitionOperations; +import org.apache.gravitino.exceptions.IllegalPropertyException; import org.apache.gravitino.integration.test.util.GravitinoITUtils; import org.apache.gravitino.rel.TableChange; import org.apache.gravitino.rel.expressions.Expression; @@ -580,4 +581,33 @@ public class TestStarRocksTableOperations extends TestStarRocks { assertTrue(loadedListPartitions.containsKey("p2")); assertTrue(Arrays.deepEquals(listPartition2.lists(), loadedListPartitions.get("p2").lists())); } + + @Test + public void testUnsupportedPropertyThrows() { + String tableName = GravitinoITUtils.genRandomName("starrocks_alter_test_table"); + + String tableComment = "test_comment"; + List<JdbcColumn> columns = new ArrayList<>(); + JdbcColumn col1 = + JdbcColumn.builder().withName("col_1").withType(INT).withComment("id").build(); + columns.add(col1); + Map<String, String> properties = new HashMap<>(); + Index[] indexes = new Index[] {}; + + // create table + TABLE_OPERATIONS.create( + databaseName, + tableName, + columns.toArray(new JdbcColumn[0]), + tableComment, + properties, + null, + null, + indexes); + + TableChange.SetProperty change = new TableChange.SetProperty("unsupported.property", "value"); + Assertions.assertThrows( + IllegalPropertyException.class, + () -> TABLE_OPERATIONS.alterTable(databaseName, tableName, change)); + } }