World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#8418] Improvement(catalog): StarRocks table alter operation trigger IllegalPropertyOperation on unknown properties (#8472)
MaAng29bb2fd1f6f8
diff --git a/api/src/main/java/org/apache/gravitino/exceptions/IllegalPropertyException.java b/api/src/main/java/org/apache/gravitino/exceptions/IllegalPropertyException.javanew file mode 100644index 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.javaindex 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.javaindex 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));+ }}