Skip to content

Commit

Permalink
[SPARK-49641][DOCS] Include table_funcs and variant_funcs in the …
Browse files Browse the repository at this point in the history
…built-in function list doc

### What changes were proposed in this pull request?
The pr aims to include `table_funcs` and `variant_funcs` in the built-in function list doc.

### Why are the changes needed?
I found that some functions were not involved in our docs, such as `sql_keywords()`, `variant_explode`, etc.
Let's include them to improve the user experience for end-users.

### Does this PR introduce _any_ user-facing change?
Yes, only for sql api docs.

### How was this patch tested?
- Pass GA
- Manually check.

### Was this patch authored or co-authored using generative AI tooling?
No.

Closes apache#48106 from panbingkun/SPARK-49641.

Authored-by: panbingkun <panbingkun@baidu.com>
Signed-off-by: Hyukjin Kwon <gurwls223@apache.org>
  • Loading branch information
panbingkun authored and HyukjinKwon committed Sep 21, 2024
1 parent bdea091 commit 70bd606
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
10 changes: 10 additions & 0 deletions docs/sql-ref-functions-builtin.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,13 @@ license: |
{% include_api_gen generated-generator-funcs-table.html %}
#### Examples
{% include_api_gen generated-generator-funcs-examples.html %}

### Table Functions
{% include_api_gen generated-table-funcs-table.html %}
#### Examples
{% include_api_gen generated-table-funcs-examples.html %}

### Variant Functions
{% include_api_gen generated-variant-funcs-table.html %}
#### Examples
{% include_api_gen generated-variant-funcs-examples.html %}
Original file line number Diff line number Diff line change
Expand Up @@ -992,12 +992,18 @@ object Range {
castAndEval[Int](expression, IntegerType, paramIndex, paramName)
}

// scalastyle:off line.size.limit
@ExpressionDescription(
usage = """
_FUNC_(start: long, end: long, step: long, numSlices: integer)
_FUNC_(start: long, end: long, step: long)
_FUNC_(start: long, end: long)
_FUNC_(end: long)""",
_FUNC_(start[, end[, step[, numSlices]]]) / _FUNC_(end) - Returns a table of values within a specified range.
""",
arguments = """
Arguments:
* start - An optional BIGINT literal defaulted to 0, marking the first value generated.
* end - A BIGINT literal marking endpoint (exclusive) of the number generation.
* step - An optional BIGINT literal defaulted to 1, specifying the increment used when generating values.
* numParts - An optional INTEGER literal specifying how the production of rows is spread across partitions.
""",
examples = """
Examples:
> SELECT * FROM _FUNC_(1);
Expand All @@ -1023,6 +1029,7 @@ object Range {
""",
since = "2.0.0",
group = "table_funcs")
// scalastyle:on line.size.limit
case class Range(
start: Long,
end: Long,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.apache.spark.internal.LogKeys.CLASS_LOADER
import org.apache.spark.security.SocketAuthServer
import org.apache.spark.sql.{internal, Column, DataFrame, Row, SparkSession}
import org.apache.spark.sql.catalyst.{CatalystTypeConverters, InternalRow}
import org.apache.spark.sql.catalyst.analysis.FunctionRegistry
import org.apache.spark.sql.catalyst.analysis.{FunctionRegistry, TableFunctionRegistry}
import org.apache.spark.sql.catalyst.encoders.ExpressionEncoder
import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.parser.CatalystSqlParser
Expand Down Expand Up @@ -69,7 +69,10 @@ private[sql] object PythonSQLUtils extends Logging {

// This is needed when generating SQL documentation for built-in functions.
def listBuiltinFunctionInfos(): Array[ExpressionInfo] = {
FunctionRegistry.functionSet.flatMap(f => FunctionRegistry.builtin.lookupFunction(f)).toArray
(FunctionRegistry.functionSet.flatMap(f => FunctionRegistry.builtin.lookupFunction(f)) ++
TableFunctionRegistry.functionSet.flatMap(
f => TableFunctionRegistry.builtin.lookupFunction(f))).
groupBy(_.getName).map(v => v._2.head).toArray
}

private def listAllSQLConfigs(): Seq[(String, String, String, String)] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,13 @@ class SQLQuerySuite extends QueryTest with SharedSparkSession with AdaptiveSpark
}

test("SPARK-34678: describe functions for table-valued functions") {
sql("describe function range").show(false)
checkKeywordsExist(sql("describe function range"),
"Function: range",
"Class: org.apache.spark.sql.catalyst.plans.logical.Range",
"range(end: long)"
"range(start[, end[, step[, numSlices]]])",
"range(end)",
"Returns a table of values within a specified range."
)
}

Expand Down
1 change: 1 addition & 0 deletions sql/gen-sql-functions-docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"bitwise_funcs", "conversion_funcs", "csv_funcs",
"xml_funcs", "lambda_funcs", "collection_funcs",
"url_funcs", "hash_funcs", "struct_funcs",
"table_funcs", "variant_funcs"
}


Expand Down

0 comments on commit 70bd606

Please sign in to comment.