nateab commented on code in PR #25115:
URL: https://github.com/apache/flink/pull/25115#discussion_r1706084728


##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/DescribeFunctionOperation.java:
##########
@@ -0,0 +1,129 @@
+/*
+ * 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.CatalogFunction;
+import org.apache.flink.table.catalog.ContextResolvedFunction;
+import org.apache.flink.table.catalog.ObjectIdentifier;
+import org.apache.flink.table.catalog.UnresolvedIdentifier;
+import org.apache.flink.table.functions.FunctionDefinition;
+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 java.util.Optional;
+
+import static 
org.apache.flink.table.api.internal.TableResultUtils.buildTableResult;
+import static 
org.apache.flink.table.types.inference.TypeInferenceUtil.generateSignature;
+
+/**
+ * Operation to describe a DESCRIBE [EXTENDED] [[catalogName.] 
dataBasesName].sqlIdentifier
+ * statement.
+ */
+@Internal
+public class DescribeFunctionOperation implements Operation, 
ExecutableOperation {
+
+    private final ObjectIdentifier sqlIdentifier;
+    private final boolean isExtended;
+
+    public DescribeFunctionOperation(ObjectIdentifier sqlIdentifier, boolean 
isExtended) {
+        this.sqlIdentifier = sqlIdentifier;
+        this.isExtended = isExtended;
+    }
+
+    public ObjectIdentifier getSqlIdentifier() {
+        return sqlIdentifier;
+    }
+
+    public boolean isExtended() {
+        return isExtended;
+    }
+
+    @Override
+    public String asSummaryString() {
+        Map<String, Object> params = new LinkedHashMap<>();
+        params.put("identifier", sqlIdentifier);
+        params.put("isExtended", isExtended);
+        return OperationUtils.formatWithChildren(
+                "DESCRIBE FUNCTION", params, Collections.emptyList(), 
Operation::asSummaryString);
+    }
+
+    @Override
+    public TableResultInternal execute(Context ctx) {
+        // DESCRIBE FUNCTION <function> shows all the function properties.
+        Optional<ContextResolvedFunction> functionOpt =
+                
ctx.getFunctionCatalog().lookupFunction(UnresolvedIdentifier.of(sqlIdentifier));
+        if (!functionOpt.isPresent()) {
+            throw new ValidationException(
+                    String.format(
+                            "Function with the identifier '%s' doesn't exist.",
+                            sqlIdentifier.asSummaryString()));
+        }
+        ContextResolvedFunction function = functionOpt.get();
+        CatalogFunction catalogFunction = function.getCatalogFunction();
+
+        if (catalogFunction == null && !isExtended) {
+            throw new ValidationException(
+                    String.format(
+                            "Function with the identifier '%s' is a system 
function which can only be described by using the extended keyword. Use 
'DESCRIBE FUNCTION EXTENDED %s' to see its properties.",
+                            sqlIdentifier.asSummaryString(), 
sqlIdentifier.asSummaryString()));
+        }
+
+        List<List<Object>> rows = new ArrayList<>();
+        if (catalogFunction != null) {
+            rows.add(Arrays.asList("class name", 
catalogFunction.getClassName()));
+            rows.add(
+                    Arrays.asList(
+                            "function language", 
catalogFunction.getFunctionLanguage().toString()));
+            rows.add(
+                    Arrays.asList(
+                            "resource uris", 
catalogFunction.getFunctionResources().toString()));
+            rows.add(Arrays.asList("temporary", function.isTemporary()));
+        }
+
+        if (isExtended) {
+            FunctionDefinition definition = function.getDefinition();
+            rows.add(Arrays.asList("kind", definition.getKind().toString()));
+            rows.add(Arrays.asList("requirements", 
definition.getRequirements().toString()));
+            rows.add(Arrays.asList("deterministic", 
definition.isDeterministic()));
+            rows.add(Arrays.asList("constant folding", 
definition.supportsConstantFolding()));
+            rows.add(
+                    Arrays.asList(
+                            "signature",
+                            generateSignature(
+                                    definition.getTypeInference(
+                                            
ctx.getCatalogManager().getDataTypeFactory()),
+                                    function.toString(),
+                                    definition)));
+        }
+
+        return buildTableResult(
+                new String[] {"info name", "info value"},

Review Comment:
   I agree that info seems a bit redundant and informal, but this is consistent 
with what `DESCRIBE CATALOG` currently does 
https://nightlies.apache.org/flink/flink-docs-master/docs/dev/table/sql/describe/#describe-statements.
 I would be open to changing it, but preferably to change both to keep them 
consistent. Snowflake for example does `property` and `value` 
https://docs.snowflake.com/en/sql-reference/sql/desc-function



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