diqiu50 commented on code in PR #10088:
URL: https://github.com/apache/gravitino/pull/10088#discussion_r2875802789


##########
.github/workflows/backend-integration-test-action.yml:
##########
@@ -60,14 +65,26 @@ jobs:
 
       - name: Backend Integration Test (JDK${{ inputs.java-version }}-${{ 
inputs.test-mode }}-${{ inputs.backend }})
         id: integrationTest
-        run: >
-          ./gradlew test -PskipTests -PtestMode=${{ inputs.test-mode }} 
-PjdbcBackend=${{ inputs.backend }} -PskipDockerTests=false
-          -x :web:web:test -x :web:integration-test:test -x :web-v2:web:test 
-x :web-v2:integration-test:test -x :clients:client-python:test -x 
:flink-connector:flink:test -x :spark-connector:spark-common:test 
-          -x :spark-connector:spark-3.3:test -x 
:spark-connector:spark-3.4:test -x :spark-connector:spark-3.5:test 
-          -x :spark-connector:spark-runtime-3.3:test -x 
:spark-connector:spark-runtime-3.4:test -x 
:spark-connector:spark-runtime-3.5:test
-          -x :trino-connector:integration-test:test -x 
:trino-connector:trino-connector:test
-          -x :authorizations:authorization-chain:test -x 
:authorizations:authorization-ranger:test 
-          -x :catalogs-contrib:catalog-jdbc-oceanbase:test
+        run: |
+          ALL_CONTRIB_MODULES="$(find catalogs-contrib -mindepth 1 -maxdepth 1 
-type d -name 'catalog-*' -exec basename {} \; | sort)"
+          CHANGED_CONTRIB_MODULES="${{ inputs.changed-catalogs-contrib-modules 
}}"
+
+          EXCLUDE_CONTRIB_TESTS=""
+          if [ "$CHANGED_CONTRIB_MODULES" != "__all__" ]; then

Review Comment:
   If `CHANGED_CONTRIB_MODULES` is not set, all modules will be skipped. Is 
that we expected?



##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -90,11 +98,11 @@ protected String generateCreateDatabaseSql(
 
     if (onCluster(properties)) {
       String clusterName = properties.get(ClusterConstants.CLUSTER_NAME);
-      createDatabaseSql.append(String.format(" ON CLUSTER `%s`", clusterName));
+      createDatabaseSql.append(String.format(" ON CLUSTER `%s`", 
clusterName.replace("`", "``")));

Review Comment:
   You’d better provide methods such as escapeNameIdentifier / 
unescapeNameIdentifier and escapeComment / unescapeComment.



##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -142,4 +199,80 @@ private boolean onCluster(Map<String, String> 
dbProperties) {
 
     return 
Boolean.parseBoolean(dbProperties.getOrDefault(ClusterConstants.ON_CLUSTER, 
"false"));
   }
+
+  private String detectClusterName(Connection connection, String databaseName) 
throws SQLException {
+    List<String> clusterNames = new ArrayList<>();
+    String escapedDatabaseName = databaseName.replace("`", "``").replace("'", 
"''");
+    try (Statement statement = connection.createStatement();
+        ResultSet clusters =
+            statement.executeQuery("SELECT DISTINCT cluster FROM 
system.clusters")) {
+      while (clusters.next()) {
+        clusterNames.add(clusters.getString(1));
+      }
+    }
+
+    for (String clusterName : clusterNames) {
+      String escapedClusterName = clusterName.replace("'", "''");
+      int clusterHostCount;
+      try (Statement statement = connection.createStatement();
+          ResultSet hostCountResultSet =
+              statement.executeQuery(
+                  String.format(
+                      "SELECT countDistinct(host_name) FROM system.clusters 
WHERE cluster = '%s'",
+                      escapedClusterName))) {
+        if (!hostCountResultSet.next()) {
+          continue;
+        }
+        clusterHostCount = hostCountResultSet.getInt(1);
+      }
+      if (clusterHostCount <= 1) {
+        continue;
+      }
+
+      try (Statement statement = connection.createStatement();
+          ResultSet dbHostCountResultSet =
+              statement.executeQuery(
+                  String.format(
+                      "SELECT countDistinct(hostName()) FROM 
clusterAllReplicas('%s', system.databases) "
+                          + "WHERE name = '%s'",
+                      escapedClusterName, escapedDatabaseName))) {
+        if (dbHostCountResultSet.next() && dbHostCountResultSet.getInt(1) == 
clusterHostCount) {
+          return clusterName;
+        }
+      }
+    }
+    return null;
+  }
+
+  private String detectClusterNameFromQueryLog(Connection connection, String 
databaseName)
+      throws SQLException {
+    String escapedDatabaseName = databaseName.replace("`", "``").replace("'", 
"''");

Review Comment:
   The query log may be cleaned up by TTL, so it’s not reliable.



##########
catalogs-contrib/catalog-jdbc-clickhouse/src/main/java/org/apache/gravitino/catalog/clickhouse/operations/ClickHouseDatabaseOperations.java:
##########
@@ -130,6 +138,55 @@ protected void dropDatabase(String databaseName, boolean 
cascade) {
     }
   }
 
+  @Override
+  public JdbcSchema load(String databaseName) throws NoSuchSchemaException {
+    if (!exist(databaseName)) {
+      throw new NoSuchSchemaException("Database %s could not be found", 
databaseName);
+    }
+
+    Map<String, String> schemaProperties = new HashMap<>();
+    schemaProperties.put(ClusterConstants.ON_CLUSTER, String.valueOf(false));
+    String schemaComment = "";
+
+    try (Connection connection = getConnection();
+        Statement statement = connection.createStatement();
+        ResultSet resultSet =
+            statement.executeQuery(
+                String.format("SHOW CREATE DATABASE `%s`", 
databaseName.replace("`", "``")))) {

Review Comment:
   The SQL never contains ON CLUSTER.



-- 
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