maropu commented on a change in pull request #28224: URL: https://github.com/apache/spark/pull/28224#discussion_r411336738
########## File path: sql/gen-sql-functions-docs.py ########## @@ -0,0 +1,228 @@ +# +# 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. +# + +import itertools +import os +import re +from collections import namedtuple + +# To avoid adding a new direct dependency, we import markdown from within mkdocs. +from mkdocs.structure.pages import markdown + +from pyspark.java_gateway import launch_gateway + + +ExpressionInfo = namedtuple("ExpressionInfo", "name usage examples group") + +groups = { + "agg_funcs", "array_funcs", "datetime_funcs", + "json_funcs", "map_funcs", "window_funcs", +} + + +def _list_grouped_function_infos(jvm): + """ + Returns a list of function information grouped by each group value via JVM. + Sorts wrapped expression infos in each group by name and returns them. + """ + + jinfos = jvm.org.apache.spark.sql.api.python.PythonSQLUtils.listBuiltinFunctionInfos() + infos = [] + + for jinfo in filter(lambda x: x.getGroup() in groups, jinfos): + name = jinfo.getName() + usage = jinfo.getUsage() + usage = usage.replace("_FUNC_", name) if usage is not None else usage + infos.append(ExpressionInfo( + name=name, + usage=usage, + examples=jinfo.getExamples().replace("_FUNC_", name), + group=jinfo.getGroup())) + + # Groups expression info by each group value + grouped_infos = itertools.groupby(sorted(infos, key=lambda x: x.group), key=lambda x: x.group) + # Then, sort expression infos in each group by name + return [(k, sorted(g, key=lambda x: x.name)) for k, g in grouped_infos] + + +# TODO(SPARK-XXXXX): Needs to add a column to describe arguments and their types Review comment: Yea, I think we can improve function list tables by adding more columns, e.g., input types, arguments, .... So, I've filed jira for that (https://issues.apache.org/jira/browse/SPARK-31499). But, that target should be at 3.1+. ########## File path: docs/.gitignore ########## @@ -1 +1,12 @@ -sql-configs.html +generated-agg-funcs-examples.html +generated-agg-funcs-table.html +generated-array-funcs-examples.html +generated-array-funcs-table.html +generated-datetime-funcs-examples.html +generated-datetime-funcs-table.html +generated-json-funcs-examples.html +generated-json-funcs-table.html +generated-map-funcs-examples.html +generated-map-funcs-table.html +generated-sql-configuration-table.html +generated-window-funcs-table.html Review comment: Every time we add a function group, adding a new entry here is a bit annoying , so how about having the same prefix in common and putting a single entry here like `generated-builtin-*.html`? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
