You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by "LadyForest (via GitHub)" <gi...@apache.org> on 2024/03/04 02:22:59 UTC

Re: [PR] [FLINK-34372][table-api] Support DESCRIBE CATALOG [flink]

LadyForest commented on code in PR #24275:
URL: https://github.com/apache/flink/pull/24275#discussion_r1510519137


##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/catalog/Catalog.java:
##########
@@ -781,4 +781,13 @@ void alterPartitionColumnStatistics(
             CatalogColumnStatistics columnStatistics,
             boolean ignoreIfNotExists)
             throws PartitionNotExistException, CatalogException;
+
+    /**
+     * Get a user defined catalog description.
+     *
+     * @return a user-implement catalog detailed explanation
+     */
+    default String explainCatalog() {

Review Comment:
   Nit: I know that even though the `explainCatalog` method was proposed by FLIP, I still want to point out that the Catalog itself is the subject that performs the explain action, so there's no need to overemphasize with `explainCatalog`. Simply using `explain` is enough. If we consider other interfaces, like `Table`, it's just use `explain`, not `explainTable`.



##########
flink-table/flink-table-common/src/main/java/org/apache/flink/table/catalog/AbstractCatalog.java:
##########
@@ -47,4 +51,31 @@ public String getName() {
     public String getDefaultDatabase() {
         return defaultDatabase;
     }
+
+    @Override
+    public String explainCatalog() {
+        StringBuilder sb = new StringBuilder();
+        Map<String, String> extraExplainInfo = extraExplainInfo();
+        sb.append("default database: ").append(defaultDatabase);
+        if (!extraExplainInfo.isEmpty()) {
+            sb.append("\n");
+            sb.append(
+                    extraExplainInfo.entrySet().stream()
+                            .map(entry -> entry.getKey() + ": " + entry.getValue())
+                            .collect(Collectors.joining("\n")));
+        }
+
+        // put the class name at the end
+        sb.append("\n").append(Catalog.super.explainCatalog());
+        return sb.toString();
+    }
+
+    /**
+     * Extra explain information used to print by DESCRIBE CATALOG catalogName statement.
+     *
+     * <p>Note: The class name and default database name of this catalog are no need to be added.
+     */
+    protected Map<String, String> extraExplainInfo() {
+        return new HashMap<>();

Review Comment:
   Nit: `return Collections.emptyMap<>();`



##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/DescribeOperator.java:
##########
@@ -0,0 +1,29 @@
+/*
+ * 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.flink.table.operations;
+
+import org.apache.flink.annotation.Internal;
+
+/**
+ * An {@link Operation} that describes the catalog, database and table, e.g. DESCRIBE CATALOG
+ * catalogName, DESCRIBE DATABASE [catalogName.]dataBaseName and DESCRIBE TABLE [[catalogName.]
+ * dataBaseName.]tableName.
+ */
+@Internal
+public interface DescribeOperator extends Operation, ExecutableOperation {}

Review Comment:
   Nit: I think the naming `DescribeOperator` needs to be reconsidered. All the rest Operations are named with `XXOperation`.



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org