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


##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/DescribeCatalogOperation.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * 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;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.api.internal.TableResultInternal;
+import org.apache.flink.table.catalog.CatalogDescriptor;
+import org.apache.flink.table.catalog.CommonCatalogOptions;
+import org.apache.flink.table.types.DataType;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static 
org.apache.flink.table.api.internal.TableResultUtils.buildTableResult;
+
+/** Operation to describe a DESCRIBE CATALOG catalog_name statement. */
+@Internal
+public class DescribeCatalogOperation implements Operation, 
ExecutableOperation {
+
+    private final String catalogName;
+    private final boolean isExtended;
+
+    public DescribeCatalogOperation(String catalogName, boolean isExtended) {
+        this.catalogName = catalogName;
+        this.isExtended = isExtended;
+    }
+
+    public String getCatalogName() {
+        return catalogName;
+    }
+
+    public boolean isExtended() {
+        return isExtended;
+    }
+
+    @Override
+    public String asSummaryString() {
+        Map<String, Object> params = new LinkedHashMap<>();
+        params.put("identifier", catalogName);
+        params.put("isExtended", isExtended);
+        return OperationUtils.formatWithChildren(
+                "DESCRIBE CATALOG", params, Collections.emptyList(), 
Operation::asSummaryString);
+    }
+
+    @Override
+    public TableResultInternal execute(Context ctx) {
+        CatalogDescriptor catalogDescriptor =
+                ctx.getCatalogManager()
+                        .getCatalogDescriptor(catalogName)
+                        .orElseThrow(
+                                () ->
+                                        new ValidationException(
+                                                String.format(
+                                                        "Cannot obtain 
metadata information from Catalog %s.",
+                                                        catalogName)));
+        Map<String, String> properties = 
catalogDescriptor.getConfiguration().toMap();
+        List<List<Object>> rows =
+                new ArrayList<>(
+                        Arrays.asList(
+                                Arrays.asList("name", catalogName),
+                                Arrays.asList(
+                                        "type",
+                                        properties.getOrDefault(
+                                                
CommonCatalogOptions.CATALOG_TYPE.key(), "")),
+                                Arrays.asList("comment", "") // TODO: retain 
for future needs

Review Comment:
   Nit: add JIRA task id



##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/DescribeCatalogOperation.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * 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;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.api.internal.TableResultInternal;
+import org.apache.flink.table.catalog.CatalogDescriptor;
+import org.apache.flink.table.catalog.CommonCatalogOptions;
+import org.apache.flink.table.types.DataType;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static 
org.apache.flink.table.api.internal.TableResultUtils.buildTableResult;
+
+/** Operation to describe a DESCRIBE CATALOG catalog_name statement. */
+@Internal
+public class DescribeCatalogOperation implements Operation, 
ExecutableOperation {
+
+    private final String catalogName;
+    private final boolean isExtended;
+
+    public DescribeCatalogOperation(String catalogName, boolean isExtended) {
+        this.catalogName = catalogName;
+        this.isExtended = isExtended;
+    }
+
+    public String getCatalogName() {
+        return catalogName;
+    }
+
+    public boolean isExtended() {
+        return isExtended;
+    }
+
+    @Override
+    public String asSummaryString() {
+        Map<String, Object> params = new LinkedHashMap<>();
+        params.put("identifier", catalogName);
+        params.put("isExtended", isExtended);
+        return OperationUtils.formatWithChildren(
+                "DESCRIBE CATALOG", params, Collections.emptyList(), 
Operation::asSummaryString);
+    }
+
+    @Override
+    public TableResultInternal execute(Context ctx) {
+        CatalogDescriptor catalogDescriptor =
+                ctx.getCatalogManager()
+                        .getCatalogDescriptor(catalogName)
+                        .orElseThrow(
+                                () ->
+                                        new ValidationException(
+                                                String.format(
+                                                        "Cannot obtain 
metadata information from Catalog %s.",
+                                                        catalogName)));
+        Map<String, String> properties = 
catalogDescriptor.getConfiguration().toMap();
+        List<List<Object>> rows =
+                new ArrayList<>(
+                        Arrays.asList(
+                                Arrays.asList("name", catalogName),
+                                Arrays.asList(
+                                        "type",
+                                        properties.getOrDefault(
+                                                
CommonCatalogOptions.CATALOG_TYPE.key(), "")),
+                                Arrays.asList("comment", "") // TODO: retain 
for future needs
+                                ));
+        if (isExtended) {
+            properties.forEach((key, value) -> 
rows.add(Arrays.asList("option:" + key, value)));

Review Comment:
   This might be a little bit verbose
   ```sql
   desc catalog extended cat2;
   +-------------------------+-------------------+
   |               info name |        info value |
   +-------------------------+-------------------+
   |                    name |              cat2 |
   |                    type | generic_in_memory |
   |                 comment |                   |
   | option:default-database |                db |
   |             option:type | generic_in_memory |
   +-------------------------+-------------------+
   5 rows in set
   !ok
   ```
   
   what about
   ```sql
   desc catalog extended cat2;
   +-------------------------+-------------------+
   |               info name |        info value |
   +-------------------------+-------------------+
   |                    name |              cat2 |
   |                    type | generic_in_memory |
   |                 comment |                   |
   | option:default-database |                db |
   +-------------------------+-------------------+
   4 rows in set
   !ok
   ```
   or
   
   ```sql
   desc catalog extended cat2;
   +-------------------------+-------------------+
   |               info name |        info value |
   +-------------------------+-------------------+
   |                    name |              cat2 |
   |                 comment |                   |
   | option:default-database |                db |
   |             option:type | generic_in_memory |
   +-------------------------+-------------------+
   4 rows in set
   !ok
   ```
   
   ```java
           if (isExtended) {
               properties.entrySet().stream()
                       .filter(entry -> !"type".equals(entry.getKey()))
                       .sorted(Map.Entry.comparingByKey())
                       .forEach(
                               entry ->
                                       rows.add(
                                               Arrays.asList(
                                                       
String.format("option:%s", entry.getKey()),
                                                       entry.getValue())));
           }
   ```
   



##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/DescribeCatalogOperation.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * 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;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.api.internal.TableResultInternal;
+import org.apache.flink.table.catalog.CatalogDescriptor;
+import org.apache.flink.table.catalog.CommonCatalogOptions;
+import org.apache.flink.table.types.DataType;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static 
org.apache.flink.table.api.internal.TableResultUtils.buildTableResult;
+
+/** Operation to describe a DESCRIBE CATALOG catalog_name statement. */
+@Internal
+public class DescribeCatalogOperation implements Operation, 
ExecutableOperation {
+
+    private final String catalogName;
+    private final boolean isExtended;
+
+    public DescribeCatalogOperation(String catalogName, boolean isExtended) {
+        this.catalogName = catalogName;
+        this.isExtended = isExtended;
+    }
+
+    public String getCatalogName() {
+        return catalogName;
+    }
+
+    public boolean isExtended() {
+        return isExtended;
+    }
+
+    @Override
+    public String asSummaryString() {
+        Map<String, Object> params = new LinkedHashMap<>();
+        params.put("identifier", catalogName);
+        params.put("isExtended", isExtended);
+        return OperationUtils.formatWithChildren(
+                "DESCRIBE CATALOG", params, Collections.emptyList(), 
Operation::asSummaryString);
+    }
+
+    @Override
+    public TableResultInternal execute(Context ctx) {
+        CatalogDescriptor catalogDescriptor =
+                ctx.getCatalogManager()
+                        .getCatalogDescriptor(catalogName)
+                        .orElseThrow(
+                                () ->
+                                        new ValidationException(
+                                                String.format(
+                                                        "Cannot obtain 
metadata information from Catalog %s.",
+                                                        catalogName)));
+        Map<String, String> properties = 
catalogDescriptor.getConfiguration().toMap();
+        List<List<Object>> rows =
+                new ArrayList<>(
+                        Arrays.asList(
+                                Arrays.asList("name", catalogName),
+                                Arrays.asList(
+                                        "type",
+                                        properties.getOrDefault(
+                                                
CommonCatalogOptions.CATALOG_TYPE.key(), "")),
+                                Arrays.asList("comment", "") // TODO: retain 
for future needs
+                                ));
+        if (isExtended) {
+            properties.forEach((key, value) -> 
rows.add(Arrays.asList("option:" + key, value)));
+        }
+
+        return buildTableResult(
+                Arrays.asList("info name", "info value").toArray(new 
String[0]),
+                Arrays.asList(DataTypes.STRING(), 
DataTypes.STRING()).toArray(new DataType[0]),

Review Comment:
   ```suggestion
                   new DataType[] {DataTypes.STRING(), DataTypes.STRING()},
   ```



##########
flink-table/flink-table-planner/src/test/java/org/apache/flink/table/planner/operations/SqlOtherOperationConverterTest.java:
##########
@@ -71,6 +72,41 @@ void testUseCatalog() {
         assertThat(operation.asSummaryString()).isEqualTo("USE CATALOG cat1");
     }
 
+    @Test

Review Comment:
   The test can be simplified as 
   
   ```java
       @ParameterizedTest
       void testDescribeCatalog(boolean abbr, boolean extended) {
           final String catalogName = "cat1";
           final String sql =
                   String.format(
                           "%s CATALOG %s %s",
                           abbr ? "DESC" : "DESCRIBE", extended ? "EXTENDED" : 
"", catalogName);
           Operation operation = parse(sql);
           assertThat(operation)
                   .isInstanceOf(DescribeCatalogOperation.class)
                   .asInstanceOf(type(DescribeCatalogOperation.class))
                   .extracting(
                           DescribeCatalogOperation::getCatalogName,
                           DescribeCatalogOperation::isExtended,
                           DescribeCatalogOperation::asSummaryString)
                   .containsExactly(
                           catalogName,
                           extended,
                           String.format(
                                   "DESCRIBE CATALOG: (identifier: [%s], 
isExtended: [%b])",
                                   catalogName, extended));
       }
   ```



##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/DescribeCatalogOperation.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * 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;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.api.internal.TableResultInternal;
+import org.apache.flink.table.catalog.CatalogDescriptor;
+import org.apache.flink.table.catalog.CommonCatalogOptions;
+import org.apache.flink.table.types.DataType;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static 
org.apache.flink.table.api.internal.TableResultUtils.buildTableResult;
+
+/** Operation to describe a DESCRIBE CATALOG catalog_name statement. */
+@Internal
+public class DescribeCatalogOperation implements Operation, 
ExecutableOperation {
+
+    private final String catalogName;
+    private final boolean isExtended;
+
+    public DescribeCatalogOperation(String catalogName, boolean isExtended) {
+        this.catalogName = catalogName;
+        this.isExtended = isExtended;
+    }
+
+    public String getCatalogName() {
+        return catalogName;
+    }
+
+    public boolean isExtended() {
+        return isExtended;
+    }
+
+    @Override
+    public String asSummaryString() {
+        Map<String, Object> params = new LinkedHashMap<>();
+        params.put("identifier", catalogName);
+        params.put("isExtended", isExtended);
+        return OperationUtils.formatWithChildren(
+                "DESCRIBE CATALOG", params, Collections.emptyList(), 
Operation::asSummaryString);
+    }
+
+    @Override
+    public TableResultInternal execute(Context ctx) {
+        CatalogDescriptor catalogDescriptor =
+                ctx.getCatalogManager()
+                        .getCatalogDescriptor(catalogName)
+                        .orElseThrow(
+                                () ->
+                                        new ValidationException(
+                                                String.format(
+                                                        "Cannot obtain 
metadata information from Catalog %s.",
+                                                        catalogName)));
+        Map<String, String> properties = 
catalogDescriptor.getConfiguration().toMap();
+        List<List<Object>> rows =
+                new ArrayList<>(
+                        Arrays.asList(
+                                Arrays.asList("name", catalogName),
+                                Arrays.asList(
+                                        "type",
+                                        properties.getOrDefault(
+                                                
CommonCatalogOptions.CATALOG_TYPE.key(), "")),
+                                Arrays.asList("comment", "") // TODO: retain 
for future needs
+                                ));
+        if (isExtended) {
+            properties.forEach((key, value) -> 
rows.add(Arrays.asList("option:" + key, value)));
+        }
+
+        return buildTableResult(
+                Arrays.asList("info name", "info value").toArray(new 
String[0]),

Review Comment:
   ```suggestion
                   new String[] {"info name", "info value"},
   ```



##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/DescribeCatalogOperation.java:
##########
@@ -0,0 +1,98 @@
+/*
+ * 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;
+import org.apache.flink.table.api.DataTypes;
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.api.internal.TableResultInternal;
+import org.apache.flink.table.catalog.CatalogDescriptor;
+import org.apache.flink.table.catalog.CommonCatalogOptions;
+import org.apache.flink.table.types.DataType;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+import static 
org.apache.flink.table.api.internal.TableResultUtils.buildTableResult;
+
+/** Operation to describe a DESCRIBE CATALOG catalog_name statement. */
+@Internal
+public class DescribeCatalogOperation implements Operation, 
ExecutableOperation {
+
+    private final String catalogName;
+    private final boolean isExtended;
+
+    public DescribeCatalogOperation(String catalogName, boolean isExtended) {
+        this.catalogName = catalogName;
+        this.isExtended = isExtended;
+    }
+
+    public String getCatalogName() {
+        return catalogName;
+    }
+
+    public boolean isExtended() {
+        return isExtended;
+    }
+
+    @Override
+    public String asSummaryString() {
+        Map<String, Object> params = new LinkedHashMap<>();
+        params.put("identifier", catalogName);
+        params.put("isExtended", isExtended);
+        return OperationUtils.formatWithChildren(
+                "DESCRIBE CATALOG", params, Collections.emptyList(), 
Operation::asSummaryString);
+    }
+
+    @Override
+    public TableResultInternal execute(Context ctx) {
+        CatalogDescriptor catalogDescriptor =
+                ctx.getCatalogManager()
+                        .getCatalogDescriptor(catalogName)
+                        .orElseThrow(
+                                () ->
+                                        new ValidationException(
+                                                String.format(
+                                                        "Cannot obtain 
metadata information from Catalog %s.",
+                                                        catalogName)));
+        Map<String, String> properties = 
catalogDescriptor.getConfiguration().toMap();
+        List<List<Object>> rows =
+                new ArrayList<>(
+                        Arrays.asList(
+                                Arrays.asList("name", catalogName),
+                                Arrays.asList(
+                                        "type",
+                                        properties.getOrDefault(
+                                                
CommonCatalogOptions.CATALOG_TYPE.key(), "")),
+                                Arrays.asList("comment", "") // TODO: retain 
for future needs
+                                ));
+        if (isExtended) {
+            properties.forEach((key, value) -> 
rows.add(Arrays.asList("option:" + key, value)));

Review Comment:
   Nit: sort by map key to achieve a consistent result order across different 
JDK versions



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