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


##########
flink-table/flink-sql-client/src/test/resources/sql/function.q:
##########
@@ -346,3 +346,69 @@ show user functions;
 SHOW JARS;
 Empty set
 !ok
+
+# ==========================================================================
+# test describe function
+# ==========================================================================
+
+ADD JAR '$VAR_UDF_JAR_PATH';
+[INFO] Execute statement succeeded.
+!info
+
+describe function temp_upperudf;
++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+
+|         info name |                                 $VAR_UDF_JAR_PATH_SPACE 
info value |

Review Comment:
   What are these variables? `VAR_UDF_JAR_PATH_SPACE`. Seems some of the docs 
have them, and others don't but makes it hard to read the source file.



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

Review Comment:
   If we wanted to extend this to include return types, would that just be 
added to the signature I assume?  I don't think the format of these signatures 
is well defined, so maybe you're free to do that in the future.



##########
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:
   Nit: Maybe the columns can be just `name`, `value`? Info sounds a bit 
informal, but `metadata` sounds a bit much too.



##########
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) {

Review Comment:
   Not sure if it would be useful, but you could just output "System function": 
true if it's a system function, regardless, rather than throw an error.  Could 
be useful for seeing which function a name is bound to. 



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