You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "yuqi1129 (via GitHub)" <gi...@apache.org> on 2026/01/20 09:00:56 UTC
[PR] [#9754] feat(clickhouse): Add schema operations for ClickHouse catalog [gravitino]
yuqi1129 opened a new pull request, #9761:
URL: https://github.com/apache/gravitino/pull/9761
### What changes were proposed in this pull request?
This PR adds support for schema operations.
### Why are the changes needed?
It's a need from the user community.
Fix: #9754
### Does this PR introduce _any_ user-facing change?
N/A
### How was this patch tested?
UTs
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9754] feat(clickhouse): Add schema operations for ClickHouse catalog [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #9761:
URL: https://github.com/apache/gravitino/pull/9761#discussion_r2740180367
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/converter/ClickHouseExceptionConverter.java:
##########
@@ -18,8 +18,36 @@
*/
package org.apache.gravitino.catalog.clickhouse.converter;
+import java.sql.SQLException;
import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.apache.gravitino.exceptions.NoSuchSchemaException;
+import org.apache.gravitino.exceptions.NoSuchTableException;
+import org.apache.gravitino.exceptions.SchemaAlreadyExistsException;
+import org.apache.gravitino.exceptions.TableAlreadyExistsException;
public class ClickHouseExceptionConverter extends JdbcExceptionConverter {
- // Implement ClickHouse specific exception conversions if needed
+ static final int UNKNOWN_DATABASE = 81;
+ static final int DATABASE_ALREADY_EXISTS = 82;
+
+ static final int TABLE_ALREADY_EXISTS = 57;
+ static final int TABLE_IS_DROPPED = 218;
+
+ @SuppressWarnings("FormatStringAnnotation")
+ @Override
+ public GravitinoRuntimeException toGravitinoException(SQLException sqlException) {
+ int errorCode = sqlException.getErrorCode();
+ switch (errorCode) {
Review Comment:
This will be conver by ITs raised later.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9754] feat(clickhouse): Add schema operations for ClickHouse catalog [gravitino]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #9761:
URL: https://github.com/apache/gravitino/pull/9761#discussion_r2735754628
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/ClickHouseCatalogPropertiesMeta.java:
##########
@@ -0,0 +1,78 @@
+/*
+ * 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.catalog.clickhouse;
+
+import static org.apache.gravitino.connector.PropertyEntry.booleanPropertyEntry;
+import static org.apache.gravitino.connector.PropertyEntry.stringPropertyEntry;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Maps;
+import java.util.List;
+import java.util.Map;
+import org.apache.gravitino.catalog.jdbc.JdbcCatalogPropertiesMetadata;
+import org.apache.gravitino.connector.PropertyEntry;
+
+public class ClickHouseCatalogPropertiesMeta extends JdbcCatalogPropertiesMetadata {
Review Comment:
Naming is inconsistent with the rest of the codebase: most property-metadata classes are named *PropertiesMetadata (e.g., JdbcCatalogPropertiesMetadata, HiveCatalogPropertiesMetadata), but this one ends with *PropertiesMeta. Consider renaming to ClickHouseCatalogPropertiesMetadata (and updating its usages/tests) for consistency.
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -18,19 +18,104 @@
*/
package org.apache.gravitino.catalog.clickhouse.operations;
-import com.google.common.collect.Sets;
+import static org.apache.gravitino.catalog.clickhouse.ClickHouseConfig.DEFAULT_CK_ON_CLUSTER;
+
+import com.google.common.collect.ImmutableSet;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.sql.DataSource;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.StringIdentifier;
+import org.apache.gravitino.catalog.clickhouse.ClickHouseConfig;
+import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
public class ClickHouseDatabaseOperations extends JdbcDatabaseOperations {
+ private boolean onCluster = false;
+ private String clusterName = null;
+
+ @Override
+ public void initialize(
+ DataSource dataSource, JdbcExceptionConverter exceptionMapper, Map<String, String> conf) {
+ super.initialize(dataSource, exceptionMapper, conf);
+
+ final String cn = conf.get(ClickHouseConfig.CK_CLUSTER_NAME.getKey());
+ if (StringUtils.isNotBlank(cn)) {
+ clusterName = cn;
+ }
+
+ final String oc =
+ conf.getOrDefault(
+ ClickHouseConfig.CK_ON_CLUSTER.getKey(), String.valueOf(DEFAULT_CK_ON_CLUSTER));
+ onCluster = Boolean.parseBoolean(oc);
+
+ if (onCluster && StringUtils.isBlank(clusterName)) {
+ throw new IllegalArgumentException(
+ "ClickHouse 'ON CLUSTER' is enabled, but cluster name is not provided.");
+ }
+ }
+
@Override
protected boolean supportSchemaComment() {
- return false;
+ return true;
}
@Override
protected Set<String> createSysDatabaseNameSet() {
- return Sets.newHashSet();
+ return ImmutableSet.of("information_schema", "INFORMATION_SCHEMA", "default", "system");
+ }
+
+ @Override
+ public List<String> listDatabases() {
+ List<String> databaseNames = new ArrayList<>();
+ try (final Connection connection = getConnection()) {
+ // It is possible that other catalogs have been deleted,
+ // causing the following statement to error,
+ // so here we manually set a system catalog
+ connection.setCatalog(createSysDatabaseNameSet().iterator().next());
+ try (Statement statement = connection.createStatement();
+ ResultSet resultSet = statement.executeQuery("SHOW DATABASES")) {
+ while (resultSet.next()) {
+ String databaseName = resultSet.getString(1);
+ if (!isSystemDatabase(databaseName)) {
+ databaseNames.add(databaseName);
+ }
+ }
+ }
+ return databaseNames;
+ } catch (final SQLException se) {
+ throw this.exceptionMapper.toGravitinoException(se);
+ }
+ }
+
+ @Override
+ protected String generateCreateDatabaseSql(
+ String databaseName, String comment, Map<String, String> properties) {
+
+ String originComment = StringIdentifier.removeIdFromComment(comment);
+ if (!supportSchemaComment() && StringUtils.isNotEmpty(originComment)) {
+ throw new UnsupportedOperationException(
+ "Doesn't support setting schema comment: " + originComment);
+ }
+
+ StringBuilder createDatabaseSql =
+ new StringBuilder(String.format("CREATE DATABASE `%s`", databaseName));
+ if (onCluster && StringUtils.isNotBlank(clusterName)) {
+ createDatabaseSql.append(String.format(" ON CLUSTER %s", clusterName));
+ }
+
+ if (StringUtils.isNotEmpty(comment)) {
Review Comment:
The COMMENT clause is guarded by StringUtils.isNotEmpty(comment), but the SQL uses originComment (comment with the Gravitino identifier removed). When users provide a blank comment, JdbcCatalogOperations will still add the identifier to the comment, making `comment` non-empty while `originComment` becomes empty, producing `COMMENT ''`. Gate the clause on originComment instead (and use originComment consistently).
```suggestion
if (StringUtils.isNotEmpty(originComment)) {
```
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -18,19 +18,104 @@
*/
package org.apache.gravitino.catalog.clickhouse.operations;
-import com.google.common.collect.Sets;
+import static org.apache.gravitino.catalog.clickhouse.ClickHouseConfig.DEFAULT_CK_ON_CLUSTER;
+
+import com.google.common.collect.ImmutableSet;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.sql.DataSource;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.StringIdentifier;
+import org.apache.gravitino.catalog.clickhouse.ClickHouseConfig;
+import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
public class ClickHouseDatabaseOperations extends JdbcDatabaseOperations {
+ private boolean onCluster = false;
+ private String clusterName = null;
+
+ @Override
+ public void initialize(
+ DataSource dataSource, JdbcExceptionConverter exceptionMapper, Map<String, String> conf) {
+ super.initialize(dataSource, exceptionMapper, conf);
+
+ final String cn = conf.get(ClickHouseConfig.CK_CLUSTER_NAME.getKey());
+ if (StringUtils.isNotBlank(cn)) {
+ clusterName = cn;
+ }
+
+ final String oc =
+ conf.getOrDefault(
+ ClickHouseConfig.CK_ON_CLUSTER.getKey(), String.valueOf(DEFAULT_CK_ON_CLUSTER));
+ onCluster = Boolean.parseBoolean(oc);
+
+ if (onCluster && StringUtils.isBlank(clusterName)) {
+ throw new IllegalArgumentException(
+ "ClickHouse 'ON CLUSTER' is enabled, but cluster name is not provided.");
+ }
+ }
+
@Override
protected boolean supportSchemaComment() {
- return false;
+ return true;
}
@Override
protected Set<String> createSysDatabaseNameSet() {
- return Sets.newHashSet();
+ return ImmutableSet.of("information_schema", "INFORMATION_SCHEMA", "default", "system");
+ }
+
+ @Override
+ public List<String> listDatabases() {
+ List<String> databaseNames = new ArrayList<>();
+ try (final Connection connection = getConnection()) {
+ // It is possible that other catalogs have been deleted,
+ // causing the following statement to error,
+ // so here we manually set a system catalog
+ connection.setCatalog(createSysDatabaseNameSet().iterator().next());
+ try (Statement statement = connection.createStatement();
+ ResultSet resultSet = statement.executeQuery("SHOW DATABASES")) {
+ while (resultSet.next()) {
+ String databaseName = resultSet.getString(1);
+ if (!isSystemDatabase(databaseName)) {
+ databaseNames.add(databaseName);
+ }
+ }
+ }
+ return databaseNames;
+ } catch (final SQLException se) {
+ throw this.exceptionMapper.toGravitinoException(se);
+ }
+ }
+
+ @Override
+ protected String generateCreateDatabaseSql(
+ String databaseName, String comment, Map<String, String> properties) {
+
+ String originComment = StringIdentifier.removeIdFromComment(comment);
+ if (!supportSchemaComment() && StringUtils.isNotEmpty(originComment)) {
Review Comment:
generateCreateDatabaseSql ignores the `properties` argument entirely. Since this catalog now exposes schema properties metadata (e.g., CK_ON_CLUSTER), either consume relevant schema-level properties here (and define precedence vs catalog config) or explicitly reject unsupported schema properties (similar to JdbcDatabaseOperations throwing when properties is non-empty).
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -18,19 +18,104 @@
*/
package org.apache.gravitino.catalog.clickhouse.operations;
-import com.google.common.collect.Sets;
+import static org.apache.gravitino.catalog.clickhouse.ClickHouseConfig.DEFAULT_CK_ON_CLUSTER;
+
+import com.google.common.collect.ImmutableSet;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.sql.DataSource;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.StringIdentifier;
+import org.apache.gravitino.catalog.clickhouse.ClickHouseConfig;
+import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
public class ClickHouseDatabaseOperations extends JdbcDatabaseOperations {
+ private boolean onCluster = false;
+ private String clusterName = null;
+
+ @Override
+ public void initialize(
+ DataSource dataSource, JdbcExceptionConverter exceptionMapper, Map<String, String> conf) {
+ super.initialize(dataSource, exceptionMapper, conf);
+
+ final String cn = conf.get(ClickHouseConfig.CK_CLUSTER_NAME.getKey());
+ if (StringUtils.isNotBlank(cn)) {
+ clusterName = cn;
+ }
+
+ final String oc =
+ conf.getOrDefault(
+ ClickHouseConfig.CK_ON_CLUSTER.getKey(), String.valueOf(DEFAULT_CK_ON_CLUSTER));
+ onCluster = Boolean.parseBoolean(oc);
+
+ if (onCluster && StringUtils.isBlank(clusterName)) {
+ throw new IllegalArgumentException(
+ "ClickHouse 'ON CLUSTER' is enabled, but cluster name is not provided.");
+ }
+ }
+
@Override
protected boolean supportSchemaComment() {
- return false;
+ return true;
}
@Override
protected Set<String> createSysDatabaseNameSet() {
- return Sets.newHashSet();
+ return ImmutableSet.of("information_schema", "INFORMATION_SCHEMA", "default", "system");
+ }
+
+ @Override
+ public List<String> listDatabases() {
+ List<String> databaseNames = new ArrayList<>();
+ try (final Connection connection = getConnection()) {
+ // It is possible that other catalogs have been deleted,
+ // causing the following statement to error,
+ // so here we manually set a system catalog
+ connection.setCatalog(createSysDatabaseNameSet().iterator().next());
+ try (Statement statement = connection.createStatement();
+ ResultSet resultSet = statement.executeQuery("SHOW DATABASES")) {
+ while (resultSet.next()) {
+ String databaseName = resultSet.getString(1);
+ if (!isSystemDatabase(databaseName)) {
+ databaseNames.add(databaseName);
+ }
+ }
+ }
+ return databaseNames;
+ } catch (final SQLException se) {
+ throw this.exceptionMapper.toGravitinoException(se);
+ }
+ }
+
+ @Override
+ protected String generateCreateDatabaseSql(
+ String databaseName, String comment, Map<String, String> properties) {
+
+ String originComment = StringIdentifier.removeIdFromComment(comment);
+ if (!supportSchemaComment() && StringUtils.isNotEmpty(originComment)) {
+ throw new UnsupportedOperationException(
+ "Doesn't support setting schema comment: " + originComment);
+ }
+
+ StringBuilder createDatabaseSql =
+ new StringBuilder(String.format("CREATE DATABASE `%s`", databaseName));
+ if (onCluster && StringUtils.isNotBlank(clusterName)) {
+ createDatabaseSql.append(String.format(" ON CLUSTER %s", clusterName));
+ }
Review Comment:
CREATE DATABASE appends "ON CLUSTER" when enabled, but DROP DATABASE still uses JdbcDatabaseOperations’ default SQL (no ON CLUSTER). If schemas are created cluster-wide, dropping without ON CLUSTER will only affect the local node. Consider overriding generateDropDatabaseSql to apply the same ON CLUSTER behavior when enabled.
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/converter/ClickHouseExceptionConverter.java:
##########
@@ -18,8 +18,36 @@
*/
package org.apache.gravitino.catalog.clickhouse.converter;
+import java.sql.SQLException;
import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.apache.gravitino.exceptions.NoSuchSchemaException;
+import org.apache.gravitino.exceptions.NoSuchTableException;
+import org.apache.gravitino.exceptions.SchemaAlreadyExistsException;
+import org.apache.gravitino.exceptions.TableAlreadyExistsException;
public class ClickHouseExceptionConverter extends JdbcExceptionConverter {
- // Implement ClickHouse specific exception conversions if needed
+ static final int UNKNOWN_DATABASE = 81;
+ static final int DATABASE_ALREADY_EXISTS = 82;
+
+ static final int TABLE_ALREADY_EXISTS = 57;
+ static final int TABLE_IS_DROPPED = 218;
+
+ @SuppressWarnings("FormatStringAnnotation")
+ @Override
+ public GravitinoRuntimeException toGravitinoException(SQLException sqlException) {
+ int errorCode = sqlException.getErrorCode();
+ switch (errorCode) {
+ case DATABASE_ALREADY_EXISTS:
+ return new SchemaAlreadyExistsException(sqlException, sqlException.getMessage());
+ case TABLE_ALREADY_EXISTS:
+ return new TableAlreadyExistsException(sqlException, sqlException.getMessage());
+ case UNKNOWN_DATABASE:
+ return new NoSuchSchemaException(sqlException, sqlException.getMessage());
+ case TABLE_IS_DROPPED:
+ return new NoSuchTableException(sqlException, sqlException.getMessage());
+ default:
+ return new GravitinoRuntimeException(sqlException, sqlException.getMessage());
Review Comment:
For unknown ClickHouse error codes, this converter always returns a generic GravitinoRuntimeException. That loses JdbcExceptionConverter’s default handling (e.g., mapping "Access denied" to ConnectionFailedException). Consider delegating the default branch to super.toGravitinoException(sqlException) so generic cases keep consistent behavior.
```suggestion
return super.toGravitinoException(sqlException);
```
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/converter/ClickHouseExceptionConverter.java:
##########
@@ -18,8 +18,36 @@
*/
package org.apache.gravitino.catalog.clickhouse.converter;
+import java.sql.SQLException;
import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.apache.gravitino.exceptions.NoSuchSchemaException;
+import org.apache.gravitino.exceptions.NoSuchTableException;
+import org.apache.gravitino.exceptions.SchemaAlreadyExistsException;
+import org.apache.gravitino.exceptions.TableAlreadyExistsException;
public class ClickHouseExceptionConverter extends JdbcExceptionConverter {
- // Implement ClickHouse specific exception conversions if needed
+ static final int UNKNOWN_DATABASE = 81;
+ static final int DATABASE_ALREADY_EXISTS = 82;
+
+ static final int TABLE_ALREADY_EXISTS = 57;
+ static final int TABLE_IS_DROPPED = 218;
+
+ @SuppressWarnings("FormatStringAnnotation")
+ @Override
+ public GravitinoRuntimeException toGravitinoException(SQLException sqlException) {
+ int errorCode = sqlException.getErrorCode();
+ switch (errorCode) {
Review Comment:
New exception mapping logic is introduced here (ClickHouse-specific error codes), but there are no unit tests covering the mappings. Add tests that construct SQLException instances with these error codes and assert the expected Gravitino exception types, including the default/fallback behavior.
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/ClickHouseCatalogCapability.java:
##########
@@ -1,26 +1,51 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.catalog.clickhouse;
-import org.apache.gravitino.catalog.jdbc.JdbcCatalogCapability;
+import org.apache.gravitino.connector.capability.Capability;
+import org.apache.gravitino.connector.capability.CapabilityResult;
+
+public class ClickHouseCatalogCapability implements Capability {
+ /**
+ * Regular expression explanation: ^[\w\p{L}-$/=]{1,64}$
+ *
+ * <p>^ - Start of the string
+ *
+ * <p>[\w\p{L}-$/=]{1,64} - Consist of 1 to 64 characters of letters (both cases), digits,
+ * underscores, any kind of letter from any language, hyphens, dollar signs, slashes or equal
+ * signs
+ *
+ * <p>\w - matches [a-zA-Z0-9_]
+ *
+ * <p>\p{L} - matches any kind of letter from any language
+ *
+ * <p>$ - End of the string
+ */
+ public static final String CLICKHOUSE_NAME_PATTERN = "^[\\w\\p{L}-$/=]{1,64}$";
-public class ClickHouseCatalogCapability extends JdbcCatalogCapability {
- // No additional capabilities for ClickHouse at this time
+ @Override
+ public CapabilityResult specificationOnName(Scope scope, String name) {
+ // TODO: Validate the name against reserved words
Review Comment:
Avoid adding TODOs without a tracking issue/reference. Either implement the reserved-word validation now or convert this to a linkable issue reference (e.g., TODO(#xxxx)).
```suggestion
// TODO(#xxxx): Validate the name against reserved words
```
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/ClickHouseCatalogCapability.java:
##########
@@ -1,26 +1,51 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.catalog.clickhouse;
-import org.apache.gravitino.catalog.jdbc.JdbcCatalogCapability;
+import org.apache.gravitino.connector.capability.Capability;
+import org.apache.gravitino.connector.capability.CapabilityResult;
+
+public class ClickHouseCatalogCapability implements Capability {
+ /**
+ * Regular expression explanation: ^[\w\p{L}-$/=]{1,64}$
+ *
+ * <p>^ - Start of the string
+ *
+ * <p>[\w\p{L}-$/=]{1,64} - Consist of 1 to 64 characters of letters (both cases), digits,
+ * underscores, any kind of letter from any language, hyphens, dollar signs, slashes or equal
+ * signs
+ *
+ * <p>\w - matches [a-zA-Z0-9_]
+ *
+ * <p>\p{L} - matches any kind of letter from any language
+ *
+ * <p>$ - End of the string
+ */
+ public static final String CLICKHOUSE_NAME_PATTERN = "^[\\w\\p{L}-$/=]{1,64}$";
Review Comment:
The character class in CLICKHOUSE_NAME_PATTERN contains an unescaped '-' ("[\\w\\p{L}-$/=]"). In Java regex this can be parsed as a character range and can throw PatternSyntaxException (or match an unintended range). Escape the hyphen ("\\-") or move it to the start/end of the character class.
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/ClickHouseCatalogCapability.java:
##########
@@ -1,26 +1,51 @@
/*
- * 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
+ * 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
+ * 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.
+ * 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.catalog.clickhouse;
-import org.apache.gravitino.catalog.jdbc.JdbcCatalogCapability;
+import org.apache.gravitino.connector.capability.Capability;
+import org.apache.gravitino.connector.capability.CapabilityResult;
+
+public class ClickHouseCatalogCapability implements Capability {
+ /**
+ * Regular expression explanation: ^[\w\p{L}-$/=]{1,64}$
+ *
+ * <p>^ - Start of the string
+ *
+ * <p>[\w\p{L}-$/=]{1,64} - Consist of 1 to 64 characters of letters (both cases), digits,
+ * underscores, any kind of letter from any language, hyphens, dollar signs, slashes or equal
+ * signs
+ *
+ * <p>\w - matches [a-zA-Z0-9_]
+ *
+ * <p>\p{L} - matches any kind of letter from any language
+ *
+ * <p>$ - End of the string
+ */
+ public static final String CLICKHOUSE_NAME_PATTERN = "^[\\w\\p{L}-$/=]{1,64}$";
-public class ClickHouseCatalogCapability extends JdbcCatalogCapability {
- // No additional capabilities for ClickHouse at this time
+ @Override
+ public CapabilityResult specificationOnName(Scope scope, String name) {
+ // TODO: Validate the name against reserved words
+ if (!name.matches(CLICKHOUSE_NAME_PATTERN)) {
+ return CapabilityResult.unsupported(
Review Comment:
This class introduces new name-validation behavior; add unit tests for specificationOnName covering representative valid/invalid names to prevent regex regressions (special characters + 64-char limit).
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -18,19 +18,104 @@
*/
package org.apache.gravitino.catalog.clickhouse.operations;
-import com.google.common.collect.Sets;
+import static org.apache.gravitino.catalog.clickhouse.ClickHouseConfig.DEFAULT_CK_ON_CLUSTER;
+
+import com.google.common.collect.ImmutableSet;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.sql.DataSource;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.StringIdentifier;
+import org.apache.gravitino.catalog.clickhouse.ClickHouseConfig;
+import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
public class ClickHouseDatabaseOperations extends JdbcDatabaseOperations {
+ private boolean onCluster = false;
+ private String clusterName = null;
+
+ @Override
+ public void initialize(
+ DataSource dataSource, JdbcExceptionConverter exceptionMapper, Map<String, String> conf) {
+ super.initialize(dataSource, exceptionMapper, conf);
+
+ final String cn = conf.get(ClickHouseConfig.CK_CLUSTER_NAME.getKey());
+ if (StringUtils.isNotBlank(cn)) {
+ clusterName = cn;
+ }
+
+ final String oc =
+ conf.getOrDefault(
+ ClickHouseConfig.CK_ON_CLUSTER.getKey(), String.valueOf(DEFAULT_CK_ON_CLUSTER));
+ onCluster = Boolean.parseBoolean(oc);
+
+ if (onCluster && StringUtils.isBlank(clusterName)) {
+ throw new IllegalArgumentException(
+ "ClickHouse 'ON CLUSTER' is enabled, but cluster name is not provided.");
+ }
+ }
+
@Override
protected boolean supportSchemaComment() {
- return false;
+ return true;
}
@Override
protected Set<String> createSysDatabaseNameSet() {
- return Sets.newHashSet();
+ return ImmutableSet.of("information_schema", "INFORMATION_SCHEMA", "default", "system");
+ }
Review Comment:
JdbcDatabaseOperations#createSysDatabaseNameSet is documented to return system database names in lowercase (catalogs/catalog-jdbc-common/.../JdbcDatabaseOperations.java:229-234). This set includes an uppercase entry ("INFORMATION_SCHEMA"), which will never match because isSystemDatabase() lowercases before lookup. Keep entries lowercase-only.
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -18,19 +18,104 @@
*/
package org.apache.gravitino.catalog.clickhouse.operations;
-import com.google.common.collect.Sets;
+import static org.apache.gravitino.catalog.clickhouse.ClickHouseConfig.DEFAULT_CK_ON_CLUSTER;
+
+import com.google.common.collect.ImmutableSet;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.sql.DataSource;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.StringIdentifier;
+import org.apache.gravitino.catalog.clickhouse.ClickHouseConfig;
+import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
public class ClickHouseDatabaseOperations extends JdbcDatabaseOperations {
+ private boolean onCluster = false;
+ private String clusterName = null;
+
+ @Override
+ public void initialize(
+ DataSource dataSource, JdbcExceptionConverter exceptionMapper, Map<String, String> conf) {
+ super.initialize(dataSource, exceptionMapper, conf);
+
+ final String cn = conf.get(ClickHouseConfig.CK_CLUSTER_NAME.getKey());
+ if (StringUtils.isNotBlank(cn)) {
+ clusterName = cn;
+ }
+
+ final String oc =
+ conf.getOrDefault(
+ ClickHouseConfig.CK_ON_CLUSTER.getKey(), String.valueOf(DEFAULT_CK_ON_CLUSTER));
+ onCluster = Boolean.parseBoolean(oc);
+
+ if (onCluster && StringUtils.isBlank(clusterName)) {
+ throw new IllegalArgumentException(
+ "ClickHouse 'ON CLUSTER' is enabled, but cluster name is not provided.");
+ }
+ }
+
@Override
protected boolean supportSchemaComment() {
- return false;
+ return true;
}
@Override
protected Set<String> createSysDatabaseNameSet() {
- return Sets.newHashSet();
+ return ImmutableSet.of("information_schema", "INFORMATION_SCHEMA", "default", "system");
+ }
+
+ @Override
+ public List<String> listDatabases() {
+ List<String> databaseNames = new ArrayList<>();
+ try (final Connection connection = getConnection()) {
+ // It is possible that other catalogs have been deleted,
+ // causing the following statement to error,
+ // so here we manually set a system catalog
+ connection.setCatalog(createSysDatabaseNameSet().iterator().next());
+ try (Statement statement = connection.createStatement();
Review Comment:
connection.setCatalog(createSysDatabaseNameSet().iterator().next()) relies on Set iteration order, which is not guaranteed. This can select different catalogs across JVMs and can fail if the chosen catalog isn’t present. Prefer a deterministic, known-to-exist catalog (e.g., "system" or "default") rather than iterator().next().
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9754] feat(clickhouse): Add schema operations for ClickHouse catalog [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao merged PR #9761:
URL: https://github.com/apache/gravitino/pull/9761
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9754] feat(clickhouse): Add schema operations for ClickHouse catalog [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #9761:
URL: https://github.com/apache/gravitino/pull/9761#discussion_r2736163327
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -18,19 +18,104 @@
*/
package org.apache.gravitino.catalog.clickhouse.operations;
-import com.google.common.collect.Sets;
+import static org.apache.gravitino.catalog.clickhouse.ClickHouseConfig.DEFAULT_CK_ON_CLUSTER;
+
+import com.google.common.collect.ImmutableSet;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.sql.DataSource;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.StringIdentifier;
+import org.apache.gravitino.catalog.clickhouse.ClickHouseConfig;
+import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
public class ClickHouseDatabaseOperations extends JdbcDatabaseOperations {
+ private boolean onCluster = false;
+ private String clusterName = null;
+
+ @Override
+ public void initialize(
+ DataSource dataSource, JdbcExceptionConverter exceptionMapper, Map<String, String> conf) {
+ super.initialize(dataSource, exceptionMapper, conf);
+
+ final String cn = conf.get(ClickHouseConfig.CK_CLUSTER_NAME.getKey());
+ if (StringUtils.isNotBlank(cn)) {
+ clusterName = cn;
+ }
+
+ final String oc =
+ conf.getOrDefault(
+ ClickHouseConfig.CK_ON_CLUSTER.getKey(), String.valueOf(DEFAULT_CK_ON_CLUSTER));
+ onCluster = Boolean.parseBoolean(oc);
+
+ if (onCluster && StringUtils.isBlank(clusterName)) {
+ throw new IllegalArgumentException(
+ "ClickHouse 'ON CLUSTER' is enabled, but cluster name is not provided.");
+ }
+ }
+
@Override
protected boolean supportSchemaComment() {
- return false;
+ return true;
}
@Override
protected Set<String> createSysDatabaseNameSet() {
- return Sets.newHashSet();
+ return ImmutableSet.of("information_schema", "INFORMATION_SCHEMA", "default", "system");
+ }
+
+ @Override
+ public List<String> listDatabases() {
+ List<String> databaseNames = new ArrayList<>();
+ try (final Connection connection = getConnection()) {
+ // It is possible that other catalogs have been deleted,
+ // causing the following statement to error,
+ // so here we manually set a system catalog
+ connection.setCatalog(createSysDatabaseNameSet().iterator().next());
+ try (Statement statement = connection.createStatement();
Review Comment:
It does not matter what is `createSysDatabaseNameSet().iterator().next()` here.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9754] feat(clickhouse): Add schema operations for ClickHouse catalog [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #9761:
URL: https://github.com/apache/gravitino/pull/9761#discussion_r2741126945
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -18,19 +18,106 @@
*/
package org.apache.gravitino.catalog.clickhouse.operations;
-import com.google.common.collect.Sets;
+import static org.apache.gravitino.catalog.clickhouse.ClickHouseConfig.DEFAULT_CK_ON_CLUSTER;
+
+import com.google.common.collect.ImmutableSet;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.sql.DataSource;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.StringIdentifier;
+import org.apache.gravitino.catalog.clickhouse.ClickHouseConfig;
+import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
public class ClickHouseDatabaseOperations extends JdbcDatabaseOperations {
+ // TODO: handle ClickHouse cluster properly when creating/dropping databases/tables
+ // use https://github.com/apache/gravitino/issues/9820 to track it.
+ @SuppressWarnings("unused")
+ private boolean onCluster = false;
+
+ @SuppressWarnings("unused")
+ private String clusterName = null;
+
+ @Override
+ public void initialize(
+ DataSource dataSource, JdbcExceptionConverter exceptionMapper, Map<String, String> conf) {
+ super.initialize(dataSource, exceptionMapper, conf);
+
+ final String cn = conf.get(ClickHouseConfig.CK_CLUSTER_NAME.getKey());
+ if (StringUtils.isNotBlank(cn)) {
+ clusterName = cn;
+ }
+
+ final String oc =
+ conf.getOrDefault(
+ ClickHouseConfig.CK_ON_CLUSTER.getKey(), String.valueOf(DEFAULT_CK_ON_CLUSTER));
+ onCluster = Boolean.parseBoolean(oc);
+
+ if (onCluster && StringUtils.isBlank(clusterName)) {
+ throw new IllegalArgumentException(
+ "ClickHouse 'ON CLUSTER' is enabled, but cluster name is not provided.");
+ }
+ }
+
@Override
protected boolean supportSchemaComment() {
- return false;
+ return true;
}
@Override
protected Set<String> createSysDatabaseNameSet() {
- return Sets.newHashSet();
+ return ImmutableSet.of("information_schema", "default", "system");
+ }
+
+ @Override
+ public List<String> listDatabases() {
+ List<String> databaseNames = new ArrayList<>();
+ try (final Connection connection = getConnection()) {
+ // It is possible that other catalogs have been deleted,
+ // causing the following statement to error,
+ // so here we manually set a system catalog
+ connection.setCatalog(createSysDatabaseNameSet().iterator().next());
+ try (Statement statement = connection.createStatement();
+ ResultSet resultSet = statement.executeQuery("SHOW DATABASES")) {
+ while (resultSet.next()) {
+ String databaseName = resultSet.getString(1);
+ if (!isSystemDatabase(databaseName)) {
+ databaseNames.add(databaseName);
+ }
+ }
+ }
+ return databaseNames;
+ } catch (final SQLException se) {
+ throw this.exceptionMapper.toGravitinoException(se);
+ }
+ }
+
+ @Override
+ protected String generateCreateDatabaseSql(
+ String databaseName, String comment, Map<String, String> properties) {
+
+ String originComment = StringIdentifier.removeIdFromComment(comment);
+ if (!supportSchemaComment() && StringUtils.isNotEmpty(originComment)) {
Review Comment:
This is a standard interface.
```
@Override
protected boolean supportSchemaComment() {
return true;
}
```
I would be reluctant to remove it.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9754] feat(clickhouse): Add schema operations for ClickHouse catalog [gravitino]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #9761:
URL: https://github.com/apache/gravitino/pull/9761#discussion_r2707435876
##########
catalogs/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.catalog.clickhouse.operations;
+
+import com.google.common.collect.ImmutableSet;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.sql.DataSource;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.StringIdentifier;
+import org.apache.gravitino.catalog.clickhouse.ClickHouseConfig;
+import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
+import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
+import org.apache.gravitino.exceptions.SchemaAlreadyExistsException;
+
+public class ClickHouseDatabaseOperations extends JdbcDatabaseOperations {
+
+ private boolean onCluster = false;
+ private String clusterName = null;
+
+ @Override
+ public void initialize(
+ DataSource dataSource, JdbcExceptionConverter exceptionMapper, Map<String, String> conf) {
+ super.initialize(dataSource, exceptionMapper, conf);
+
+ final String cn = conf.get(ClickHouseConfig.CK_CLUSTER_NAME.getKey());
+ if (StringUtils.isNoneBlank(cn)) {
Review Comment:
Incorrect use of StringUtils.isNoneBlank() with a single parameter. The method isNoneBlank() is designed for checking multiple strings (varargs), but here only a single string is being checked. Use StringUtils.isNotBlank(cn) instead, which is the standard pattern used throughout the codebase for single string null/blank checks.
```suggestion
if (StringUtils.isNotBlank(cn)) {
```
##########
catalogs/catalog-jdbc-clickhouse/src/test/java/org/apache/gravitino/catalog/clickhouse/operations/TestClickHouseDatabaseOperations.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.catalog.clickhouse.operations;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.gravitino.catalog.clickhouse.ClickHouseConfig;
+import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestClickHouseDatabaseOperations {
+
+ private static class TestableClickHouseDatabaseOperations extends ClickHouseDatabaseOperations {
+ String buildCreateSql(String databaseName, String comment, Map<String, String> properties) {
+ return generateCreateDatabaseSql(databaseName, comment, properties);
+ }
+ }
+
+ private TestableClickHouseDatabaseOperations newOps(Map<String, String> conf) {
+ TestableClickHouseDatabaseOperations ops = new TestableClickHouseDatabaseOperations();
+ ops.initialize(null, new JdbcExceptionConverter(), conf);
+ return ops;
+ }
+
+ @Test
+ void testGenerateCreateDatabaseSqlWithoutCluster() {
+ Map<String, String> conf = new HashMap<>();
+ String sql = newOps(conf).buildCreateSql("db_name", null, Collections.emptyMap());
+ Assertions.assertEquals("CREATE DATABASE `db_name`", sql);
+ }
+
+ @Test
+ void testGenerateCreateDatabaseSqlWithCluster() {
+ Map<String, String> conf = new HashMap<>();
+ conf.put(ClickHouseConfig.CK_CLUSTER_NAME.getKey(), "ck_cluster");
+ conf.put(ClickHouseConfig.CK_ON_CLUSTER.getKey(), "true");
+
+ String sql = newOps(conf).buildCreateSql("db_name", "comment", Collections.emptyMap());
+ Assertions.assertEquals(
+ "CREATE DATABASE `db_name` ON CLUSTER ck_cluster COMMENT 'comment'", sql);
+ }
+
+ @Test
+ void testGenerateCreateDatabaseSqlWithClusterNameButDisabled() {
+ Map<String, String> conf = new HashMap<>();
+ conf.put(ClickHouseConfig.CK_CLUSTER_NAME.getKey(), "ck_cluster");
+
+ String sql = newOps(conf).buildCreateSql("db_name", "comment", Collections.emptyMap());
+ Assertions.assertEquals("CREATE DATABASE `db_name` COMMENT 'comment'", sql);
+ }
+
+ @Test
+ void testGenerateCreateDatabaseSqlWithPropertiesThrows() {
+ Map<String, String> conf = new HashMap<>();
+ TestableClickHouseDatabaseOperations ops = newOps(conf);
+
+ Assertions.assertEquals(
+ "CREATE DATABASE `db_name` COMMENT 'comment'",
+ ops.buildCreateSql("db_name", "comment", Collections.emptyMap()));
+ }
Review Comment:
The test method name testGenerateCreateDatabaseSqlWithPropertiesThrows suggests it should test an exception being thrown, but the test actually just asserts that a SQL statement is generated correctly. Either rename the test to reflect what it actually tests (e.g., testGenerateCreateDatabaseSqlWithComment), or implement the intended exception-throwing test if properties are not supported.
##########
catalogs/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/ClickhouseConstants.java:
##########
@@ -0,0 +1,30 @@
+/*
+ * 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.catalog.clickhouse;
+
+public class ClickhouseConstants {
Review Comment:
Inconsistent naming convention: This class is named "ClickhouseConstants" with lowercase 'h', while all other classes in the package use "ClickHouse" with uppercase 'H' (e.g., ClickHouseCatalog, ClickHouseConfig, ClickHouseDatabaseOperations). Rename to "ClickHouseConstants" for consistency across the module.
```suggestion
public class ClickHouseConstants {
```
##########
catalogs/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * 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.catalog.clickhouse.operations;
+
+import com.google.common.collect.ImmutableSet;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import javax.sql.DataSource;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.StringIdentifier;
+import org.apache.gravitino.catalog.clickhouse.ClickHouseConfig;
+import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
+import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
+import org.apache.gravitino.exceptions.SchemaAlreadyExistsException;
+
+public class ClickHouseDatabaseOperations extends JdbcDatabaseOperations {
+
+ private boolean onCluster = false;
+ private String clusterName = null;
+
+ @Override
+ public void initialize(
+ DataSource dataSource, JdbcExceptionConverter exceptionMapper, Map<String, String> conf) {
+ super.initialize(dataSource, exceptionMapper, conf);
+
+ final String cn = conf.get(ClickHouseConfig.CK_CLUSTER_NAME.getKey());
+ if (StringUtils.isNoneBlank(cn)) {
+ clusterName = cn;
+ }
+
+ final String oc = conf.getOrDefault(ClickHouseConfig.CK_ON_CLUSTER.getKey(), "false");
+ onCluster = Boolean.parseBoolean(oc);
+ }
+
+ @Override
+ protected boolean supportSchemaComment() {
+ return true;
+ }
+
+ @Override
+ protected Set<String> createSysDatabaseNameSet() {
+ return ImmutableSet.of("information_schema", "INFORMATION_SCHEMA", "default", "system");
+ }
+
+ @Override
+ public List<String> listDatabases() {
+ List<String> databaseNames = new ArrayList<>();
+ try (final Connection connection = getConnection()) {
+ // It is possible that other catalogs have been deleted,
+ // causing the following statement to error,
+ // so here we manually set a system catalog
+ connection.setCatalog(createSysDatabaseNameSet().iterator().next());
+ try (Statement statement = connection.createStatement();
+ ResultSet resultSet = statement.executeQuery("SHOW DATABASES")) {
+ while (resultSet.next()) {
+ String databaseName = resultSet.getString(1);
+ if (!isSystemDatabase(databaseName)) {
+ databaseNames.add(databaseName);
+ }
+ }
+ }
+ return databaseNames;
+ } catch (final SQLException se) {
+ throw this.exceptionMapper.toGravitinoException(se);
+ }
+ }
+
+ @Override
+ public void create(String databaseName, String comment, Map<String, String> properties)
+ throws SchemaAlreadyExistsException {
+ super.create(databaseName, comment, properties);
+ }
+
+ @Override
Review Comment:
This override of create() method serves no purpose as it only calls super.create() with the same parameters. Remove this unnecessary override to reduce code complexity and improve maintainability.
```suggestion
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9754] feat(clickhouse): Add schema operations for ClickHouse catalog [gravitino]
Posted by "diqiu50 (via GitHub)" <gi...@apache.org>.
diqiu50 commented on code in PR #9761:
URL: https://github.com/apache/gravitino/pull/9761#discussion_r2740623106
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -18,19 +18,106 @@
*/
package org.apache.gravitino.catalog.clickhouse.operations;
-import com.google.common.collect.Sets;
+import static org.apache.gravitino.catalog.clickhouse.ClickHouseConfig.DEFAULT_CK_ON_CLUSTER;
+
+import com.google.common.collect.ImmutableSet;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.sql.DataSource;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.StringIdentifier;
+import org.apache.gravitino.catalog.clickhouse.ClickHouseConfig;
+import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
public class ClickHouseDatabaseOperations extends JdbcDatabaseOperations {
+ // TODO: handle ClickHouse cluster properly when creating/dropping databases/tables
+ // use https://github.com/apache/gravitino/issues/9820 to track it.
+ @SuppressWarnings("unused")
+ private boolean onCluster = false;
Review Comment:
How is this designed on your side? Since it’s on-cluster, it’s related to SQL and not the catalog.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9754] feat(clickhouse): Add schema operations for ClickHouse catalog [gravitino]
Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #9761:
URL: https://github.com/apache/gravitino/pull/9761#issuecomment-3776171651
We will need some structural level changes for more and more catalog support, I will sync with you offline, please work on that beforehand.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9754] feat(clickhouse): Add schema operations for ClickHouse catalog [gravitino]
Posted by "diqiu50 (via GitHub)" <gi...@apache.org>.
diqiu50 commented on code in PR #9761:
URL: https://github.com/apache/gravitino/pull/9761#discussion_r2740958911
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -18,19 +18,106 @@
*/
package org.apache.gravitino.catalog.clickhouse.operations;
-import com.google.common.collect.Sets;
+import static org.apache.gravitino.catalog.clickhouse.ClickHouseConfig.DEFAULT_CK_ON_CLUSTER;
+
+import com.google.common.collect.ImmutableSet;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.sql.DataSource;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.StringIdentifier;
+import org.apache.gravitino.catalog.clickhouse.ClickHouseConfig;
+import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
public class ClickHouseDatabaseOperations extends JdbcDatabaseOperations {
+ // TODO: handle ClickHouse cluster properly when creating/dropping databases/tables
+ // use https://github.com/apache/gravitino/issues/9820 to track it.
+ @SuppressWarnings("unused")
+ private boolean onCluster = false;
+
+ @SuppressWarnings("unused")
+ private String clusterName = null;
+
+ @Override
+ public void initialize(
+ DataSource dataSource, JdbcExceptionConverter exceptionMapper, Map<String, String> conf) {
+ super.initialize(dataSource, exceptionMapper, conf);
+
+ final String cn = conf.get(ClickHouseConfig.CK_CLUSTER_NAME.getKey());
+ if (StringUtils.isNotBlank(cn)) {
+ clusterName = cn;
+ }
+
+ final String oc =
+ conf.getOrDefault(
+ ClickHouseConfig.CK_ON_CLUSTER.getKey(), String.valueOf(DEFAULT_CK_ON_CLUSTER));
+ onCluster = Boolean.parseBoolean(oc);
+
+ if (onCluster && StringUtils.isBlank(clusterName)) {
+ throw new IllegalArgumentException(
+ "ClickHouse 'ON CLUSTER' is enabled, but cluster name is not provided.");
+ }
+ }
+
@Override
protected boolean supportSchemaComment() {
- return false;
+ return true;
}
@Override
protected Set<String> createSysDatabaseNameSet() {
- return Sets.newHashSet();
+ return ImmutableSet.of("information_schema", "default", "system");
+ }
+
+ @Override
+ public List<String> listDatabases() {
+ List<String> databaseNames = new ArrayList<>();
+ try (final Connection connection = getConnection()) {
+ // It is possible that other catalogs have been deleted,
+ // causing the following statement to error,
+ // so here we manually set a system catalog
+ connection.setCatalog(createSysDatabaseNameSet().iterator().next());
+ try (Statement statement = connection.createStatement();
+ ResultSet resultSet = statement.executeQuery("SHOW DATABASES")) {
+ while (resultSet.next()) {
+ String databaseName = resultSet.getString(1);
+ if (!isSystemDatabase(databaseName)) {
+ databaseNames.add(databaseName);
+ }
+ }
+ }
+ return databaseNames;
+ } catch (final SQLException se) {
+ throw this.exceptionMapper.toGravitinoException(se);
+ }
+ }
+
+ @Override
+ protected String generateCreateDatabaseSql(
+ String databaseName, String comment, Map<String, String> properties) {
+
+ String originComment = StringIdentifier.removeIdFromComment(comment);
+ if (!supportSchemaComment() && StringUtils.isNotEmpty(originComment)) {
Review Comment:
This code is redundant.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9754] feat(clickhouse): Add schema operations for ClickHouse catalog [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #9761:
URL: https://github.com/apache/gravitino/pull/9761#discussion_r2741116758
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -18,19 +18,106 @@
*/
package org.apache.gravitino.catalog.clickhouse.operations;
-import com.google.common.collect.Sets;
+import static org.apache.gravitino.catalog.clickhouse.ClickHouseConfig.DEFAULT_CK_ON_CLUSTER;
+
+import com.google.common.collect.ImmutableSet;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.sql.DataSource;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.StringIdentifier;
+import org.apache.gravitino.catalog.clickhouse.ClickHouseConfig;
+import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
public class ClickHouseDatabaseOperations extends JdbcDatabaseOperations {
+ // TODO: handle ClickHouse cluster properly when creating/dropping databases/tables
+ // use https://github.com/apache/gravitino/issues/9820 to track it.
+ @SuppressWarnings("unused")
+ private boolean onCluster = false;
Review Comment:
Okay, I'm not so sure about putting it as a catalog property, but your suggestion is valuable, and I will accept it.
By the way, I will still keep `cluster-name` in the catalogs level
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9754] feat(clickhouse): Add schema operations for ClickHouse catalog [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #9761:
URL: https://github.com/apache/gravitino/pull/9761#discussion_r2735692000
##########
catalogs/catalog-jdbc-clickhouse/src/test/java/org/apache/gravitino/catalog/clickhouse/operations/TestClickHouseDatabaseOperations.java:
##########
@@ -0,0 +1,79 @@
+/*
+ * 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.catalog.clickhouse.operations;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import org.apache.gravitino.catalog.clickhouse.ClickHouseConfig;
+import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestClickHouseDatabaseOperations {
+
+ private static class TestableClickHouseDatabaseOperations extends ClickHouseDatabaseOperations {
+ String buildCreateSql(String databaseName, String comment, Map<String, String> properties) {
+ return generateCreateDatabaseSql(databaseName, comment, properties);
+ }
+ }
+
+ private TestableClickHouseDatabaseOperations newOps(Map<String, String> conf) {
+ TestableClickHouseDatabaseOperations ops = new TestableClickHouseDatabaseOperations();
+ ops.initialize(null, new JdbcExceptionConverter(), conf);
+ return ops;
+ }
+
+ @Test
+ void testGenerateCreateDatabaseSqlWithoutCluster() {
+ Map<String, String> conf = new HashMap<>();
+ String sql = newOps(conf).buildCreateSql("db_name", null, Collections.emptyMap());
+ Assertions.assertEquals("CREATE DATABASE `db_name`", sql);
+ }
+
+ @Test
+ void testGenerateCreateDatabaseSqlWithCluster() {
+ Map<String, String> conf = new HashMap<>();
+ conf.put(ClickHouseConfig.CK_CLUSTER_NAME.getKey(), "ck_cluster");
+ conf.put(ClickHouseConfig.CK_ON_CLUSTER.getKey(), "true");
+
+ String sql = newOps(conf).buildCreateSql("db_name", "comment", Collections.emptyMap());
+ Assertions.assertEquals(
+ "CREATE DATABASE `db_name` ON CLUSTER ck_cluster COMMENT 'comment'", sql);
+ }
+
+ @Test
+ void testGenerateCreateDatabaseSqlWithClusterNameButDisabled() {
+ Map<String, String> conf = new HashMap<>();
+ conf.put(ClickHouseConfig.CK_CLUSTER_NAME.getKey(), "ck_cluster");
+
+ String sql = newOps(conf).buildCreateSql("db_name", "comment", Collections.emptyMap());
+ Assertions.assertEquals("CREATE DATABASE `db_name` COMMENT 'comment'", sql);
+ }
+
+ @Test
+ void testGenerateCreateDatabaseSqlWithPropertiesThrows() {
+ Map<String, String> conf = new HashMap<>();
+ TestableClickHouseDatabaseOperations ops = newOps(conf);
+
+ Assertions.assertEquals(
+ "CREATE DATABASE `db_name` COMMENT 'comment'",
+ ops.buildCreateSql("db_name", "comment", Collections.emptyMap()));
+ }
Review Comment:
fixed
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9754] feat(clickhouse): Add schema operations for ClickHouse catalog [gravitino]
Posted by "diqiu50 (via GitHub)" <gi...@apache.org>.
diqiu50 commented on code in PR #9761:
URL: https://github.com/apache/gravitino/pull/9761#discussion_r2740446898
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -18,19 +18,106 @@
*/
package org.apache.gravitino.catalog.clickhouse.operations;
-import com.google.common.collect.Sets;
+import static org.apache.gravitino.catalog.clickhouse.ClickHouseConfig.DEFAULT_CK_ON_CLUSTER;
+
+import com.google.common.collect.ImmutableSet;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.sql.DataSource;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.StringIdentifier;
+import org.apache.gravitino.catalog.clickhouse.ClickHouseConfig;
+import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
public class ClickHouseDatabaseOperations extends JdbcDatabaseOperations {
+ // TODO: handle ClickHouse cluster properly when creating/dropping databases/tables
+ // use https://github.com/apache/gravitino/issues/9820 to track it.
+ @SuppressWarnings("unused")
+ private boolean onCluster = false;
+
+ @SuppressWarnings("unused")
+ private String clusterName = null;
+
+ @Override
+ public void initialize(
+ DataSource dataSource, JdbcExceptionConverter exceptionMapper, Map<String, String> conf) {
+ super.initialize(dataSource, exceptionMapper, conf);
+
+ final String cn = conf.get(ClickHouseConfig.CK_CLUSTER_NAME.getKey());
+ if (StringUtils.isNotBlank(cn)) {
+ clusterName = cn;
+ }
+
+ final String oc =
+ conf.getOrDefault(
+ ClickHouseConfig.CK_ON_CLUSTER.getKey(), String.valueOf(DEFAULT_CK_ON_CLUSTER));
+ onCluster = Boolean.parseBoolean(oc);
+
+ if (onCluster && StringUtils.isBlank(clusterName)) {
+ throw new IllegalArgumentException(
+ "ClickHouse 'ON CLUSTER' is enabled, but cluster name is not provided.");
+ }
+ }
+
@Override
protected boolean supportSchemaComment() {
- return false;
+ return true;
}
@Override
protected Set<String> createSysDatabaseNameSet() {
- return Sets.newHashSet();
+ return ImmutableSet.of("information_schema", "default", "system");
+ }
Review Comment:
Make it const variable
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/converter/ClickHouseExceptionConverter.java:
##########
@@ -18,8 +18,36 @@
*/
package org.apache.gravitino.catalog.clickhouse.converter;
+import java.sql.SQLException;
import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.apache.gravitino.exceptions.NoSuchSchemaException;
+import org.apache.gravitino.exceptions.NoSuchTableException;
+import org.apache.gravitino.exceptions.SchemaAlreadyExistsException;
+import org.apache.gravitino.exceptions.TableAlreadyExistsException;
public class ClickHouseExceptionConverter extends JdbcExceptionConverter {
- // Implement ClickHouse specific exception conversions if needed
+ static final int UNKNOWN_DATABASE = 81;
+ static final int DATABASE_ALREADY_EXISTS = 82;
+
+ static final int TABLE_ALREADY_EXISTS = 57;
+ static final int TABLE_IS_DROPPED = 218;
Review Comment:
ERROR_CODE_XXX is better
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -18,19 +18,106 @@
*/
package org.apache.gravitino.catalog.clickhouse.operations;
-import com.google.common.collect.Sets;
+import static org.apache.gravitino.catalog.clickhouse.ClickHouseConfig.DEFAULT_CK_ON_CLUSTER;
+
+import com.google.common.collect.ImmutableSet;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.sql.DataSource;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.StringIdentifier;
+import org.apache.gravitino.catalog.clickhouse.ClickHouseConfig;
+import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
public class ClickHouseDatabaseOperations extends JdbcDatabaseOperations {
+ // TODO: handle ClickHouse cluster properly when creating/dropping databases/tables
+ // use https://github.com/apache/gravitino/issues/9820 to track it.
+ @SuppressWarnings("unused")
+ private boolean onCluster = false;
+
+ @SuppressWarnings("unused")
+ private String clusterName = null;
+
+ @Override
+ public void initialize(
+ DataSource dataSource, JdbcExceptionConverter exceptionMapper, Map<String, String> conf) {
+ super.initialize(dataSource, exceptionMapper, conf);
+
+ final String cn = conf.get(ClickHouseConfig.CK_CLUSTER_NAME.getKey());
+ if (StringUtils.isNotBlank(cn)) {
+ clusterName = cn;
+ }
+
+ final String oc =
+ conf.getOrDefault(
+ ClickHouseConfig.CK_ON_CLUSTER.getKey(), String.valueOf(DEFAULT_CK_ON_CLUSTER));
+ onCluster = Boolean.parseBoolean(oc);
+
+ if (onCluster && StringUtils.isBlank(clusterName)) {
+ throw new IllegalArgumentException(
+ "ClickHouse 'ON CLUSTER' is enabled, but cluster name is not provided.");
+ }
+ }
+
@Override
protected boolean supportSchemaComment() {
- return false;
+ return true;
}
@Override
protected Set<String> createSysDatabaseNameSet() {
- return Sets.newHashSet();
+ return ImmutableSet.of("information_schema", "default", "system");
+ }
+
+ @Override
+ public List<String> listDatabases() {
+ List<String> databaseNames = new ArrayList<>();
+ try (final Connection connection = getConnection()) {
+ // It is possible that other catalogs have been deleted,
+ // causing the following statement to error,
+ // so here we manually set a system catalog
+ connection.setCatalog(createSysDatabaseNameSet().iterator().next());
+ try (Statement statement = connection.createStatement();
+ ResultSet resultSet = statement.executeQuery("SHOW DATABASES")) {
+ while (resultSet.next()) {
+ String databaseName = resultSet.getString(1);
+ if (!isSystemDatabase(databaseName)) {
+ databaseNames.add(databaseName);
+ }
+ }
+ }
+ return databaseNames;
+ } catch (final SQLException se) {
+ throw this.exceptionMapper.toGravitinoException(se);
+ }
+ }
+
+ @Override
+ protected String generateCreateDatabaseSql(
+ String databaseName, String comment, Map<String, String> properties) {
+
+ String originComment = StringIdentifier.removeIdFromComment(comment);
+ if (!supportSchemaComment() && StringUtils.isNotEmpty(originComment)) {
Review Comment:
Is supportSchemaComment always return true?
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -18,19 +18,106 @@
*/
package org.apache.gravitino.catalog.clickhouse.operations;
-import com.google.common.collect.Sets;
+import static org.apache.gravitino.catalog.clickhouse.ClickHouseConfig.DEFAULT_CK_ON_CLUSTER;
+
+import com.google.common.collect.ImmutableSet;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.sql.DataSource;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.StringIdentifier;
+import org.apache.gravitino.catalog.clickhouse.ClickHouseConfig;
+import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
public class ClickHouseDatabaseOperations extends JdbcDatabaseOperations {
+ // TODO: handle ClickHouse cluster properly when creating/dropping databases/tables
+ // use https://github.com/apache/gravitino/issues/9820 to track it.
+ @SuppressWarnings("unused")
+ private boolean onCluster = false;
Review Comment:
This is related to on-cluster and SQL logic, not the catalog. How is this designed on your side?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9754] feat(clickhouse): Add schema operations for ClickHouse catalog [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #9761:
URL: https://github.com/apache/gravitino/pull/9761#issuecomment-3822354405
@diqiu50
All fixed, please help to take a look again, thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9754] feat(clickhouse): Add schema operations for ClickHouse catalog [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #9761:
URL: https://github.com/apache/gravitino/pull/9761#discussion_r2740678668
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -18,19 +18,106 @@
*/
package org.apache.gravitino.catalog.clickhouse.operations;
-import com.google.common.collect.Sets;
+import static org.apache.gravitino.catalog.clickhouse.ClickHouseConfig.DEFAULT_CK_ON_CLUSTER;
+
+import com.google.common.collect.ImmutableSet;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.sql.DataSource;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.StringIdentifier;
+import org.apache.gravitino.catalog.clickhouse.ClickHouseConfig;
+import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
public class ClickHouseDatabaseOperations extends JdbcDatabaseOperations {
+ // TODO: handle ClickHouse cluster properly when creating/dropping databases/tables
+ // use https://github.com/apache/gravitino/issues/9820 to track it.
+ @SuppressWarnings("unused")
+ private boolean onCluster = false;
Review Comment:
My initial thoughts are that we can add `cluster-name` and `on-cluster`(default is false) in the catalog level, and schema or table can overwrite `on-cluster` configuration.
For example
```
create database xxxx on cluster xxxx;
create table xxx on cluster xxxx
```
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -18,19 +18,106 @@
*/
package org.apache.gravitino.catalog.clickhouse.operations;
-import com.google.common.collect.Sets;
+import static org.apache.gravitino.catalog.clickhouse.ClickHouseConfig.DEFAULT_CK_ON_CLUSTER;
+
+import com.google.common.collect.ImmutableSet;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.sql.DataSource;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.StringIdentifier;
+import org.apache.gravitino.catalog.clickhouse.ClickHouseConfig;
+import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
public class ClickHouseDatabaseOperations extends JdbcDatabaseOperations {
+ // TODO: handle ClickHouse cluster properly when creating/dropping databases/tables
+ // use https://github.com/apache/gravitino/issues/9820 to track it.
+ @SuppressWarnings("unused")
+ private boolean onCluster = false;
+
+ @SuppressWarnings("unused")
+ private String clusterName = null;
+
+ @Override
+ public void initialize(
+ DataSource dataSource, JdbcExceptionConverter exceptionMapper, Map<String, String> conf) {
+ super.initialize(dataSource, exceptionMapper, conf);
+
+ final String cn = conf.get(ClickHouseConfig.CK_CLUSTER_NAME.getKey());
+ if (StringUtils.isNotBlank(cn)) {
+ clusterName = cn;
+ }
+
+ final String oc =
+ conf.getOrDefault(
+ ClickHouseConfig.CK_ON_CLUSTER.getKey(), String.valueOf(DEFAULT_CK_ON_CLUSTER));
+ onCluster = Boolean.parseBoolean(oc);
+
+ if (onCluster && StringUtils.isBlank(clusterName)) {
+ throw new IllegalArgumentException(
+ "ClickHouse 'ON CLUSTER' is enabled, but cluster name is not provided.");
+ }
+ }
+
@Override
protected boolean supportSchemaComment() {
- return false;
+ return true;
}
@Override
protected Set<String> createSysDatabaseNameSet() {
- return Sets.newHashSet();
+ return ImmutableSet.of("information_schema", "default", "system");
+ }
+
+ @Override
+ public List<String> listDatabases() {
+ List<String> databaseNames = new ArrayList<>();
+ try (final Connection connection = getConnection()) {
+ // It is possible that other catalogs have been deleted,
+ // causing the following statement to error,
+ // so here we manually set a system catalog
+ connection.setCatalog(createSysDatabaseNameSet().iterator().next());
+ try (Statement statement = connection.createStatement();
+ ResultSet resultSet = statement.executeQuery("SHOW DATABASES")) {
+ while (resultSet.next()) {
+ String databaseName = resultSet.getString(1);
+ if (!isSystemDatabase(databaseName)) {
+ databaseNames.add(databaseName);
+ }
+ }
+ }
+ return databaseNames;
+ } catch (final SQLException se) {
+ throw this.exceptionMapper.toGravitinoException(se);
+ }
+ }
+
+ @Override
+ protected String generateCreateDatabaseSql(
+ String databaseName, String comment, Map<String, String> properties) {
+
+ String originComment = StringIdentifier.removeIdFromComment(comment);
+ if (!supportSchemaComment() && StringUtils.isNotEmpty(originComment)) {
Review Comment:
YES
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9754] feat(clickhouse): Add schema operations for ClickHouse catalog [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #9761:
URL: https://github.com/apache/gravitino/pull/9761#discussion_r2736753538
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/converter/ClickHouseExceptionConverter.java:
##########
@@ -18,8 +18,36 @@
*/
package org.apache.gravitino.catalog.clickhouse.converter;
+import java.sql.SQLException;
import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
+import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.apache.gravitino.exceptions.NoSuchSchemaException;
+import org.apache.gravitino.exceptions.NoSuchTableException;
+import org.apache.gravitino.exceptions.SchemaAlreadyExistsException;
+import org.apache.gravitino.exceptions.TableAlreadyExistsException;
public class ClickHouseExceptionConverter extends JdbcExceptionConverter {
- // Implement ClickHouse specific exception conversions if needed
+ static final int UNKNOWN_DATABASE = 81;
+ static final int DATABASE_ALREADY_EXISTS = 82;
+
+ static final int TABLE_ALREADY_EXISTS = 57;
+ static final int TABLE_IS_DROPPED = 218;
+
+ @SuppressWarnings("FormatStringAnnotation")
+ @Override
+ public GravitinoRuntimeException toGravitinoException(SQLException sqlException) {
+ int errorCode = sqlException.getErrorCode();
+ switch (errorCode) {
+ case DATABASE_ALREADY_EXISTS:
+ return new SchemaAlreadyExistsException(sqlException, sqlException.getMessage());
+ case TABLE_ALREADY_EXISTS:
+ return new TableAlreadyExistsException(sqlException, sqlException.getMessage());
+ case UNKNOWN_DATABASE:
+ return new NoSuchSchemaException(sqlException, sqlException.getMessage());
+ case TABLE_IS_DROPPED:
+ return new NoSuchTableException(sqlException, sqlException.getMessage());
+ default:
+ return new GravitinoRuntimeException(sqlException, sqlException.getMessage());
Review Comment:
You are wrong.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9754] feat(clickhouse): Add schema operations for ClickHouse catalog [gravitino]
Posted by "diqiu50 (via GitHub)" <gi...@apache.org>.
diqiu50 commented on code in PR #9761:
URL: https://github.com/apache/gravitino/pull/9761#discussion_r2740971974
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -18,19 +18,106 @@
*/
package org.apache.gravitino.catalog.clickhouse.operations;
-import com.google.common.collect.Sets;
+import static org.apache.gravitino.catalog.clickhouse.ClickHouseConfig.DEFAULT_CK_ON_CLUSTER;
+
+import com.google.common.collect.ImmutableSet;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
import java.util.Set;
+import javax.sql.DataSource;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.gravitino.StringIdentifier;
+import org.apache.gravitino.catalog.clickhouse.ClickHouseConfig;
+import org.apache.gravitino.catalog.jdbc.converter.JdbcExceptionConverter;
import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
public class ClickHouseDatabaseOperations extends JdbcDatabaseOperations {
+ // TODO: handle ClickHouse cluster properly when creating/dropping databases/tables
+ // use https://github.com/apache/gravitino/issues/9820 to track it.
+ @SuppressWarnings("unused")
+ private boolean onCluster = false;
Review Comment:
I think on-cluster should not be a catalog property.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] [#9754] feat(clickhouse): Add schema operations for ClickHouse catalog [gravitino]
Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on PR #9761:
URL: https://github.com/apache/gravitino/pull/9761#issuecomment-3771776909
Convert to draft as #9742 has not been merged.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org