yuqi1129 commented on code in PR #10383:
URL: https://github.com/apache/gravitino/pull/10383#discussion_r2959796576
##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -124,12 +127,65 @@ public void create(String databaseName, String comment,
Map<String, String> prop
protected void dropDatabase(String databaseName, boolean cascade) {
try (final Connection connection = getConnection()) {
connection.setCatalog(createSysDatabaseNameSet().iterator().next());
- JdbcConnectorUtils.executeUpdate(connection,
generateDropDatabaseSql(databaseName, cascade));
+ if (!cascade) {
+ try (Statement stmt = connection.createStatement();
+ ResultSet rs = stmt.executeQuery(String.format("SHOW TABLES IN
`%s`", databaseName))) {
+ if (rs.next()) {
+ throw new IllegalStateException(
+ String.format(
+ "Database %s is not empty, the value of cascade should be
true.",
+ databaseName));
+ }
+ }
+ }
+ String clusterName = getDatabaseClusterName(connection, databaseName);
+ JdbcConnectorUtils.executeUpdate(
+ connection, generateDropDatabaseSql(databaseName, clusterName));
} catch (final SQLException se) {
throw this.exceptionMapper.toGravitinoException(se);
}
}
+ /**
+ * Generates the SQL statement to drop a ClickHouse database. If the
database was created with ON
+ * CLUSTER, the DROP statement includes {@code ON CLUSTER `clusterName`
SYNC} to propagate the
+ * operation across all cluster nodes synchronously.
+ *
+ * @param databaseName The name of the database to drop.
+ * @param clusterName The cluster name extracted from the database's CREATE
SQL, or {@code null}
+ * if the database is not on a cluster.
+ * @return The DROP DATABASE SQL statement.
+ */
+ @VisibleForTesting
+ String generateDropDatabaseSql(String databaseName, String clusterName) {
+ StringBuilder sql = new StringBuilder(String.format("DROP DATABASE `%s`",
databaseName));
+ if (StringUtils.isNotBlank(clusterName)) {
+ sql.append(String.format(" ON CLUSTER `%s` SYNC", clusterName));
Review Comment:
remove SYNC
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]