twalthr commented on code in PR #25115: URL: https://github.com/apache/flink/pull/25115#discussion_r1799621489
########## flink-table/flink-sql-client/src/test/resources/sql/function.q: ########## @@ -346,3 +346,159 @@ show user functions; SHOW JARS; Empty set !ok + +# ========================================================================== +# test describe function +# ========================================================================== + +ADD JAR '$VAR_UDF_JAR_PATH'; +[INFO] Execute statement succeeded. +!info + +describe function `SUM`; ++-----------------+------------+ +| info name | info value | ++-----------------+------------+ +| system function | true | +| temporary | false | ++-----------------+------------+ +2 rows in set +!ok + +describe function extended `SUM`; ++------------------+----------------+ +| info name | info value | ++------------------+----------------+ +| system function | true | +| temporary | false | +| kind | AGGREGATE | +| requirements | [] | +| deterministic | true | +| constant folding | true | +| signature | SUM(<NUMERIC>) | ++------------------+----------------+ +7 rows in set +!ok + +describe function temp_upperudf; ++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+ +| info name | $VAR_UDF_JAR_PATH_SPACE info value | ++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+ +| system function | $VAR_UDF_JAR_PATH_SPACE false | +| temporary | $VAR_UDF_JAR_PATH_SPACE true | +| class name | $VAR_UDF_JAR_PATH_SPACE UpperUDF | +| function language | $VAR_UDF_JAR_PATH_SPACE JAVA | +| resource uris | [ResourceUri{resourceType=JAR, uri='$VAR_UDF_JAR_PATH'}] | ++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+ +5 rows in set +!ok + +describe function extended temp_upperudf; ++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+ +| info name | $VAR_UDF_JAR_PATH_SPACE info value | ++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+ +| system function | $VAR_UDF_JAR_PATH_SPACE false | +| temporary | $VAR_UDF_JAR_PATH_SPACE true | +| class name | $VAR_UDF_JAR_PATH_SPACE UpperUDF | +| function language | $VAR_UDF_JAR_PATH_SPACE JAVA | +| resource uris | [ResourceUri{resourceType=JAR, uri='$VAR_UDF_JAR_PATH'}] | +| kind | $VAR_UDF_JAR_PATH_SPACE SCALAR | +| requirements | $VAR_UDF_JAR_PATH_SPACE [] | +| deterministic | $VAR_UDF_JAR_PATH_SPACE true | +| constant folding | $VAR_UDF_JAR_PATH_SPACE true | +| signature | $VAR_UDF_JAR_PATH_SPACE c1.db.temp_upperudf(STRING) | ++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+ +10 rows in set +!ok + +desc function temp_upperudf; ++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+ +| info name | $VAR_UDF_JAR_PATH_SPACE info value | ++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+ +| system function | $VAR_UDF_JAR_PATH_SPACE false | +| temporary | $VAR_UDF_JAR_PATH_SPACE true | +| class name | $VAR_UDF_JAR_PATH_SPACE UpperUDF | +| function language | $VAR_UDF_JAR_PATH_SPACE JAVA | +| resource uris | [ResourceUri{resourceType=JAR, uri='$VAR_UDF_JAR_PATH'}] | ++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+ +5 rows in set +!ok + +desc function extended temp_upperudf; ++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+ +| info name | $VAR_UDF_JAR_PATH_SPACE info value | Review Comment: ```suggestion | attribute name | $VAR_UDF_JAR_PATH_SPACE attribute value | ``` ########## flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/operations/DescribeFunctionOperation.java: ########## @@ -0,0 +1,125 @@ +/* + * 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.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 UnresolvedIdentifier sqlIdentifier; + private final boolean isExtended; + + public DescribeFunctionOperation(UnresolvedIdentifier sqlIdentifier, boolean isExtended) { + this.sqlIdentifier = sqlIdentifier; + this.isExtended = isExtended; + } + + public UnresolvedIdentifier 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(sqlIdentifier); + if (!functionOpt.isPresent()) { + throw new ValidationException( + String.format( + "Function with the identifier '%s' doesn't exist.", + sqlIdentifier.asSummaryString())); + } + final ContextResolvedFunction function = functionOpt.get(); + final CatalogFunction catalogFunction = function.getCatalogFunction(); + + List<List<Object>> rows = new ArrayList<>(); + rows.add(Arrays.asList("system function", String.valueOf(catalogFunction == null))); + rows.add(Arrays.asList("temporary", String.valueOf(function.isTemporary()))); + 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())); + } + + if (isExtended) { + final 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", String.valueOf(definition.isDeterministic()))); Review Comment: can we use `is determinstic`, `is temporary` and `supports constant folding`, `is system function`? reads nicer. ########## flink-table/flink-sql-client/src/test/resources/sql/function.q: ########## @@ -346,3 +346,159 @@ show user functions; SHOW JARS; Empty set !ok + +# ========================================================================== +# test describe function +# ========================================================================== + +ADD JAR '$VAR_UDF_JAR_PATH'; +[INFO] Execute statement succeeded. +!info + +describe function `SUM`; ++-----------------+------------+ +| info name | info value | ++-----------------+------------+ +| system function | true | +| temporary | false | ++-----------------+------------+ +2 rows in set +!ok + +describe function extended `SUM`; ++------------------+----------------+ +| info name | info value | ++------------------+----------------+ +| system function | true | +| temporary | false | +| kind | AGGREGATE | +| requirements | [] | +| deterministic | true | +| constant folding | true | +| signature | SUM(<NUMERIC>) | ++------------------+----------------+ +7 rows in set +!ok + +describe function temp_upperudf; ++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+ +| info name | $VAR_UDF_JAR_PATH_SPACE info value | ++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+ +| system function | $VAR_UDF_JAR_PATH_SPACE false | +| temporary | $VAR_UDF_JAR_PATH_SPACE true | +| class name | $VAR_UDF_JAR_PATH_SPACE UpperUDF | +| function language | $VAR_UDF_JAR_PATH_SPACE JAVA | +| resource uris | [ResourceUri{resourceType=JAR, uri='$VAR_UDF_JAR_PATH'}] | ++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+ +5 rows in set +!ok + +describe function extended temp_upperudf; ++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+ +| info name | $VAR_UDF_JAR_PATH_SPACE info value | ++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+ +| system function | $VAR_UDF_JAR_PATH_SPACE false | +| temporary | $VAR_UDF_JAR_PATH_SPACE true | +| class name | $VAR_UDF_JAR_PATH_SPACE UpperUDF | +| function language | $VAR_UDF_JAR_PATH_SPACE JAVA | +| resource uris | [ResourceUri{resourceType=JAR, uri='$VAR_UDF_JAR_PATH'}] | +| kind | $VAR_UDF_JAR_PATH_SPACE SCALAR | +| requirements | $VAR_UDF_JAR_PATH_SPACE [] | +| deterministic | $VAR_UDF_JAR_PATH_SPACE true | +| constant folding | $VAR_UDF_JAR_PATH_SPACE true | +| signature | $VAR_UDF_JAR_PATH_SPACE c1.db.temp_upperudf(STRING) | ++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+ +10 rows in set +!ok + +desc function temp_upperudf; ++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+ +| info name | $VAR_UDF_JAR_PATH_SPACE info value | ++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+ +| system function | $VAR_UDF_JAR_PATH_SPACE false | +| temporary | $VAR_UDF_JAR_PATH_SPACE true | +| class name | $VAR_UDF_JAR_PATH_SPACE UpperUDF | +| function language | $VAR_UDF_JAR_PATH_SPACE JAVA | +| resource uris | [ResourceUri{resourceType=JAR, uri='$VAR_UDF_JAR_PATH'}] | ++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+ +5 rows in set +!ok + +desc function extended temp_upperudf; ++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+ +| info name | $VAR_UDF_JAR_PATH_SPACE info value | ++-------------------+---------------------------------------------$VAR_UDF_JAR_PATH_DASH+ +| system function | $VAR_UDF_JAR_PATH_SPACE false | Review Comment: make order determistic i.e. sort by first column -- 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-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org