Skip to content

Commit 07ee732

Browse files
sarutakHyukjinKwon
authored andcommitted
[SPARK-34747][SQL][DOCS] Add virtual operators to the built-in function document
### What changes were proposed in this pull request? This PR fix an issue that virtual operators (`||`, `!=`, `<>`, `between` and `case`) are absent from the Spark SQL Built-in functions document. ### Why are the changes needed? The document should explain about all the supported built-in operators. ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? Built the document with `SKIP_SCALADOC=1 SKIP_RDOC=1 SKIP_PYTHONDOC=1 bundler exec jekyll build` and then, confirmed the document. ![neq1](https://user-images.githubusercontent.com/4736016/111192859-e2e76380-85fc-11eb-89c9-75916a5e856a.png) ![neq2](https://user-images.githubusercontent.com/4736016/111192874-e7ac1780-85fc-11eb-9a9b-c504265b373f.png) ![between](https://user-images.githubusercontent.com/4736016/111192898-eda1f880-85fc-11eb-992d-cf80c544ec27.png) ![case](https://user-images.githubusercontent.com/4736016/111192918-f266ac80-85fc-11eb-9306-5dbc413a0cdb.png) ![double_pipe](https://user-images.githubusercontent.com/4736016/111192952-fb577e00-85fc-11eb-932e-385e5c2a5205.png) Closes apache#31841 from sarutak/builtin-op-doc. Authored-by: Kousuke Saruta <[email protected]> Signed-off-by: HyukjinKwon <[email protected]>
1 parent 8207e2f commit 07ee732

File tree

2 files changed

+105
-3
lines changed

2 files changed

+105
-3
lines changed

sql/core/src/main/scala/org/apache/spark/sql/execution/command/functions.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,10 @@ case class ShowFunctionsCommand(
229229
case (f, "USER") if showUserFunctions => f.unquotedString
230230
case (f, "SYSTEM") if showSystemFunctions => f.unquotedString
231231
}
232-
// Hard code "<>", "!=", "between", and "case" for now as there is no corresponding functions.
233-
// "<>", "!=", "between", and "case" is SystemFunctions, only show when showSystemFunctions=true
232+
// Hard code "<>", "!=", "between", "case", and "||"
233+
// for now as there is no corresponding functions.
234+
// "<>", "!=", "between", "case", and "||" is SystemFunctions,
235+
// only show when showSystemFunctions=true
234236
if (showSystemFunctions) {
235237
(functionNames ++
236238
StringUtils.filterPattern(FunctionsCommand.virtualOperators, pattern.getOrElse("*")))

sql/gen-sql-api-docs.py

+101-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,106 @@
2424
ExpressionInfo = namedtuple(
2525
"ExpressionInfo", "className name usage arguments examples note since deprecated")
2626

27+
_virtual_operator_infos = [
28+
ExpressionInfo(
29+
className="",
30+
name="!=",
31+
usage="expr1 != expr2 - Returns true if `expr1` is not equal to `expr2`, " +
32+
"or false otherwise.",
33+
arguments="\n Arguments:\n " +
34+
"""* expr1, expr2 - the two expressions must be same type or can be casted to
35+
a common type, and must be a type that can be used in equality comparison.
36+
Map type is not supported. For complex types such array/struct,
37+
the data types of fields must be orderable.""",
38+
examples="\n Examples:\n " +
39+
"> SELECT 1 != 2;\n " +
40+
" true\n " +
41+
"> SELECT 1 != '2';\n " +
42+
" true\n " +
43+
"> SELECT true != NULL;\n " +
44+
" NULL\n " +
45+
"> SELECT NULL != NULL;\n " +
46+
" NULL",
47+
note="",
48+
since="1.0.0",
49+
deprecated=""),
50+
ExpressionInfo(
51+
className="",
52+
name="<>",
53+
usage="expr1 != expr2 - Returns true if `expr1` is not equal to `expr2`, " +
54+
"or false otherwise.",
55+
arguments="\n Arguments:\n " +
56+
"""* expr1, expr2 - the two expressions must be same type or can be casted to
57+
a common type, and must be a type that can be used in equality comparison.
58+
Map type is not supported. For complex types such array/struct,
59+
the data types of fields must be orderable.""",
60+
examples="\n Examples:\n " +
61+
"> SELECT 1 != 2;\n " +
62+
" true\n " +
63+
"> SELECT 1 != '2';\n " +
64+
" true\n " +
65+
"> SELECT true != NULL;\n " +
66+
" NULL\n " +
67+
"> SELECT NULL != NULL;\n " +
68+
" NULL",
69+
note="",
70+
since="1.0.0",
71+
deprecated=""),
72+
ExpressionInfo(
73+
className="",
74+
name="between",
75+
usage="expr1 [NOT] BETWEEN expr2 AND expr3 - " +
76+
"evaluate if `expr1` is [not] in between `expr2` and `expr3`.",
77+
arguments="",
78+
examples="\n Examples:\n " +
79+
"> SELECT col1 FROM VALUES 1, 3, 5, 7 WHERE col1 BETWEEN 2 AND 5;\n " +
80+
" 3\n " +
81+
" 5",
82+
note="",
83+
since="1.0.0",
84+
deprecated=""),
85+
ExpressionInfo(
86+
className="",
87+
name="case",
88+
usage="CASE expr1 WHEN expr2 THEN expr3 " +
89+
"[WHEN expr4 THEN expr5]* [ELSE expr6] END - " +
90+
"When `expr1` = `expr2`, returns `expr3`; " +
91+
"when `expr1` = `expr4`, return `expr5`; else return `expr6`.",
92+
arguments="\n Arguments:\n " +
93+
"* expr1 - the expression which is one operand of comparison.\n " +
94+
"* expr2, expr4 - the expressions each of which is the other " +
95+
" operand of comparison.\n " +
96+
"* expr3, expr5, expr6 - the branch value expressions and else value expression" +
97+
" should all be same type or coercible to a common type.",
98+
examples="\n Examples:\n " +
99+
"> SELECT CASE col1 WHEN 1 THEN 'one' " +
100+
"WHEN 2 THEN 'two' ELSE '?' END FROM VALUES 1, 2, 3;\n " +
101+
" one\n " +
102+
" two\n " +
103+
" ?\n " +
104+
"> SELECT CASE col1 WHEN 1 THEN 'one' " +
105+
"WHEN 2 THEN 'two' END FROM VALUES 1, 2, 3;\n " +
106+
" one\n " +
107+
" two\n " +
108+
" NULL",
109+
note="",
110+
since="1.0.1",
111+
deprecated=""),
112+
ExpressionInfo(
113+
className="",
114+
name="||",
115+
usage="expr1 || expr2 - Returns the concatenation of `expr1` and `expr2`.",
116+
arguments="",
117+
examples="\n Examples:\n " +
118+
"> SELECT 'Spark' || 'SQL';\n " +
119+
" SparkSQL\n " +
120+
"> SELECT array(1, 2, 3) || array(4, 5) || array(6);\n " +
121+
" [1,2,3,4,5,6]",
122+
note="\n || for arrays is available since 2.4.0.\n",
123+
since="2.3.0",
124+
deprecated="")
125+
]
126+
27127

28128
def _list_function_infos(jvm):
29129
"""
@@ -32,7 +132,7 @@ def _list_function_infos(jvm):
32132
"""
33133

34134
jinfos = jvm.org.apache.spark.sql.api.python.PythonSQLUtils.listBuiltinFunctionInfos()
35-
infos = []
135+
infos = _virtual_operator_infos
36136
for jinfo in jinfos:
37137
name = jinfo.getName()
38138
usage = jinfo.getUsage()

0 commit comments

Comments
 (0)