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 4ba156fb23 [#13417] fix(jdbc): name the schema in the schema-comment
rejection message (#13418)
4ba156fb23 is described below
commit 4ba156fb232f9241294c4417e3cfdc86fefc2402
Author: Qi Yu <[email protected]>
AuthorDate: Tue Sep 22 22:37:21 2026 +0800
[#13417] fix(jdbc): name the schema in the schema-comment rejection message
(#13418)
### What changes were proposed in this pull request?
When a JDBC catalog does not support schema comments,
`JdbcDatabaseOperations.create` (and the duplicated check in
`ClickHouseDatabaseOperations`) now rejects a create request that
carries one with
```
Schema <name>: catalog does not support schema comments
```
instead of `Doesn't support setting schema comment: <comment value>`.
Updated the assertions in `CatalogMysqlIT` and `CatalogOceanBaseIT` that
pinned the old wording, and added
`TestJdbcDatabaseOperations#testCreateWithCommentNamesSchemaInRejection`,
which exercises the shared check through a minimal subclass (the SQLite
test double overrides `create()`) and verifies the request is rejected
before a connection is opened.
### Why are the changes needed?
The old message appended the comment VALUE where the schema name belongs
and read as a fragment, e.g. `reason [Doesn't support setting schema
comment: probe]` on Oracle.
Fix: #13417
### Does this PR introduce _any_ user-facing change?
Only the wording of the `UnsupportedOperationException` message.
### How was this patch tested?
`TestJdbcDatabaseOperations` locally; `catalog-jdbc-mysql`,
`catalog-jdbc-clickhouse` and `catalog-jdbc-oceanbase` test sources
compile. The MySQL/OceanBase ITs run in CI.
---
.../operations/ClickHouseDatabaseOperations.java | 4 +-
.../integration/test/CatalogOceanBaseIT.java | 4 +-
.../jdbc/operation/JdbcDatabaseOperations.java | 2 +-
.../jdbc/operation/TestJdbcDatabaseOperations.java | 47 ++++++++++++++++++++++
.../mysql/integration/test/CatalogMysqlIT.java | 4 +-
5 files changed, 56 insertions(+), 5 deletions(-)
diff --git
a/catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java
b/catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java
index e35946364d..931b4b2c5a 100644
---
a/catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java
+++
b/catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java
@@ -105,7 +105,7 @@ public class ClickHouseDatabaseOperations extends
JdbcDatabaseOperations {
String originComment = StringIdentifier.removeIdFromComment(comment);
if (!supportSchemaComment() && StringUtils.isNotEmpty(originComment)) {
throw new UnsupportedOperationException(
- "Doesn't support setting schema comment: " + originComment);
+ "Schema " + databaseName + ": catalog does not support schema
comments");
}
StringBuilder createDatabaseSql =
@@ -132,7 +132,7 @@ public class ClickHouseDatabaseOperations extends
JdbcDatabaseOperations {
String originComment = StringIdentifier.removeIdFromComment(comment);
if (!supportSchemaComment() && StringUtils.isNotEmpty(originComment)) {
throw new UnsupportedOperationException(
- "Doesn't support setting schema comment: " + originComment);
+ "Schema " + databaseName + ": catalog does not support schema
comments");
}
try (final Connection connection = getConnection()) {
diff --git
a/catalogs-contrib/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/integration/test/CatalogOceanBaseIT.java
b/catalogs-contrib/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/integration/test/CatalogOceanBaseIT.java
index 260d851ac7..f930af31ec 100644
---
a/catalogs-contrib/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/integration/test/CatalogOceanBaseIT.java
+++
b/catalogs-contrib/catalog-jdbc-oceanbase/src/test/java/org/apache/gravitino/catalog/oceanbase/integration/test/CatalogOceanBaseIT.java
@@ -1155,7 +1155,9 @@ public class CatalogOceanBaseIT extends BaseIT {
UnsupportedOperationException.class,
() -> catalog.asSchemas().createSchema(testSchemaName, "comment",
null));
Assertions.assertTrue(
- exception.getMessage().contains("Doesn't support setting schema
comment: comment"));
+ exception
+ .getMessage()
+ .contains("Schema " + testSchemaName + ": catalog does not support
schema comments"));
// test null comment
String testSchemaName2 = "test2";
diff --git
a/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/operation/JdbcDatabaseOperations.java
b/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/operation/JdbcDatabaseOperations.java
index 68f9d97bae..7dd96aa444 100644
---
a/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/operation/JdbcDatabaseOperations.java
+++
b/catalogs/catalog-jdbc-common/src/main/java/org/apache/gravitino/catalog/jdbc/operation/JdbcDatabaseOperations.java
@@ -65,7 +65,7 @@ public abstract class JdbcDatabaseOperations implements
DatabaseOperation {
String originComment = StringIdentifier.removeIdFromComment(comment);
if (!supportSchemaComment() && StringUtils.isNotEmpty(originComment)) {
throw new UnsupportedOperationException(
- "Doesn't support setting schema comment: " + originComment);
+ "Schema " + databaseName + ": catalog does not support schema
comments");
}
try (final Connection connection = getConnection()) {
diff --git
a/catalogs/catalog-jdbc-common/src/test/java/org/apache/gravitino/catalog/jdbc/operation/TestJdbcDatabaseOperations.java
b/catalogs/catalog-jdbc-common/src/test/java/org/apache/gravitino/catalog/jdbc/operation/TestJdbcDatabaseOperations.java
index d7951b95af..e5088077f0 100644
---
a/catalogs/catalog-jdbc-common/src/test/java/org/apache/gravitino/catalog/jdbc/operation/TestJdbcDatabaseOperations.java
+++
b/catalogs/catalog-jdbc-common/src/test/java/org/apache/gravitino/catalog/jdbc/operation/TestJdbcDatabaseOperations.java
@@ -25,9 +25,12 @@ import java.nio.file.Files;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import javax.sql.DataSource;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.catalog.jdbc.JdbcSchema;
import org.apache.gravitino.catalog.jdbc.config.JdbcConfig;
import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
import org.apache.gravitino.catalog.jdbc.converter.SqliteExceptionConverter;
@@ -84,6 +87,50 @@ public class TestJdbcDatabaseOperations {
JDBC_DATABASE_OPERATIONS.initialize(DATA_SOURCE, EXCEPTION_MAPPER,
Collections.emptyMap());
}
+ @Test
+ public void testCreateWithCommentNamesSchemaInRejection() {
+ // SqliteDatabaseOperations overrides create(), so exercise the shared
check through a
+ // minimal subclass that does not support schema comments.
+ JdbcDatabaseOperations operations =
+ new JdbcDatabaseOperations() {
+ @Override
+ public JdbcSchema load(String databaseName) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ protected String generateCreateDatabaseSql(
+ String databaseName, String comment, Map<String, String>
properties) {
+ return "CREATE DATABASE " + databaseName;
+ }
+
+ @Override
+ protected String generateDropDatabaseSql(String databaseName,
boolean cascade) {
+ return "DROP DATABASE " + databaseName;
+ }
+
+ @Override
+ protected boolean supportSchemaComment() {
+ return false;
+ }
+
+ @Override
+ protected Set<String> createSysDatabaseNameSet() {
+ return Collections.emptySet();
+ }
+ };
+ // A null DataSource makes any attempt to open a connection fail with an
NPE, so the
+ // assertion below also proves the request is rejected before a connection
is opened.
+ operations.initialize(null, EXCEPTION_MAPPER, Collections.emptyMap());
+
+ UnsupportedOperationException exception =
+ Assertions.assertThrows(
+ UnsupportedOperationException.class,
+ () -> operations.create("commented", "probe", null));
+ Assertions.assertEquals(
+ "Schema commented: catalog does not support schema comments",
exception.getMessage());
+ }
+
@Test
public void testOperationDatabase() {
String database1 = "test";
diff --git
a/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java
b/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java
index d496c5f2dd..7d23739c5e 100644
---
a/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java
+++
b/catalogs/catalog-jdbc-mysql/src/test/java/org/apache/gravitino/catalog/mysql/integration/test/CatalogMysqlIT.java
@@ -1487,7 +1487,9 @@ public class CatalogMysqlIT extends BaseIT {
UnsupportedOperationException.class,
() -> catalog.asSchemas().createSchema(testSchemaName, "comment",
null));
Assertions.assertTrue(
- exception.getMessage().contains("Doesn't support setting schema
comment: comment"));
+ exception
+ .getMessage()
+ .contains("Schema " + testSchemaName + ": catalog does not support
schema comments"));
// test null comment
String testSchemaName2 = "test2";