flaming-archer commented on code in PR #5819:
URL: https://github.com/apache/gravitino/pull/5819#discussion_r1879258818


##########
catalogs/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operation/ClickHouseDatabaseOperations.java:
##########
@@ -0,0 +1,95 @@
+/*
+ * 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.operation;
+
+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.Set;
+import org.apache.gravitino.catalog.jdbc.operation.JdbcDatabaseOperations;
+import org.apache.gravitino.exceptions.NoSuchSchemaException;
+
+/** Database operations for ClickHouse. */
+public class ClickHouseDatabaseOperations extends JdbcDatabaseOperations {
+
+  @Override
+  protected boolean supportSchemaComment() {
+    return false;
+  }
+
+  @Override
+  protected Set<String> createSysDatabaseNameSet() {
+    return ImmutableSet.of("information_schema", "INFORMATION_SCHEMA", 
"default", "system");
+  }
+
+  @Override
+  public boolean delete(String databaseName, boolean cascade) {
+    LOG.info("Beginning to drop database {}", databaseName);
+    try {
+      dropDatabase(databaseName, cascade);
+      LOG.info("Finished dropping database {}", databaseName);
+    } catch (NoSuchSchemaException e) {
+      return false;
+    } catch (Exception e) {
+      if (e.getMessage() != null
+          && (e.getMessage().contains("Database " + databaseName + " does not 
exist.")
+              || e.getMessage().contains("Database `" + databaseName + "` does 
not exist."))) {
+        return false;
+      }
+
+      if (e.getMessage() != null
+          && e.getMessage()
+              .contains(
+                  "Database "
+                      + databaseName
+                      + " is not empty, the value of cascade should be 
true.")) {
+        throw e;
+      }
+    }
+    return true;

Review Comment:
   > For methods like this, we may want to think twice about the exit 
condition. There are three possible outcomes:
   > 
   > * `true`: everything went smooth, great;
   > * `false`: something is bad, operation failed;
   > * Exception: this is the gotcha for the caller. This means ... well, 
something bad
   >   happened, the operation failed.
   > 
   > A caller has to handle two potential results, and the caller has to be 
aware of the exception. This logic is not maintainable. Maybe there are two 
alternatives here:
   > 
   > * Remove the Exception, let the function return ether `true` or `false`.
   >   That means we don't throw exceptions.
   > * Remove the return value, the function either succeed, or it throws an 
exception.
   >   The caller is supposed to do a `try ... catch`.
   > 
   > I'm leaning toward the first one, but it is up to your decision.
   
   
   I also lean towards the first option. The behavior of the test cases I 
tested at that time was very strange, so I will try to change 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to