Skip to content

Commit

Permalink
[SPARK-28808][DOCS][SQL] Document SHOW FUNCTIONS in SQL Reference
Browse files Browse the repository at this point in the history
### What changes were proposed in this pull request?
Document SHOW FUNCTIONS statement in SQL Reference Guide.

### Why are the changes needed?
Currently Spark lacks documentation on the supported SQL constructs causing
confusion among users who sometimes have to look at the code to understand the
usage. This is aimed at addressing this issue.

### Does this PR introduce any user-facing change?
Yes.

**Before:**
There was no documentation for this.

**After.**

![image](https://user-images.githubusercontent.com/11567269/64281840-e3cc0f00-cf08-11e9-9784-f01392276130.png)

<img width="589" alt="Screen Shot 2019-09-04 at 11 41 44 AM" src="https://user-images.githubusercontent.com/11567269/64281911-0fe79000-cf09-11e9-955f-21b44590707c.png">

<img width="572" alt="Screen Shot 2019-09-04 at 11 41 54 AM" src="https://user-images.githubusercontent.com/11567269/64281916-12e28080-cf09-11e9-9187-688c2c751559.png">

### How was this patch tested?
Tested using jykyll build --serve

Closes #25539 from dilipbiswal/ref-doc-show-functions.

Lead-authored-by: Dilip Biswal <dbiswal@us.ibm.com>
Co-authored-by: Xiao Li <gatorsmile@gmail.com>
Signed-off-by: Xiao Li <gatorsmile@gmail.com>
  • Loading branch information
dilipbiswal and gatorsmile committed Sep 4, 2019
1 parent b992160 commit f96486b
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/sql-ref-syntax-aux-describe-function.md
Expand Up @@ -34,7 +34,7 @@ metadata information is returned along with the extended usage information.
<dl>
<dt><code><em>function_name</em></code></dt>
<dd>
Specifies a name of an existing function in the syetem. The function name may be
Specifies a name of an existing function in the system. The function name may be
optionally qualified with a database name. If `function_name` is qualified with
a database then the function is resolved from the user specified database, otherwise
it is resolved from the current database.<br><br>
Expand Down
119 changes: 118 additions & 1 deletion docs/sql-ref-syntax-aux-show-functions.md
Expand Up @@ -19,4 +19,121 @@ license: |
limitations under the License.
---

**This page is under construction**
### Description
Returns the list of functions after applying an optional regex pattern.
Given number of functions supported by Spark is quite large, this statement
in conjuction with [describe function](sql-ref-syntax-aux-describe-function.html)
may be used to quickly find the function and understand its usage. The `LIKE`
clause is optional and supported only for compatibility with other systems.

### Syntax
{% highlight sql %}
SHOW [ function_kind ] FUNCTIONS ([LIKE] function_name | regex_pattern)
{% endhighlight %}

### Parameters
<dl>
<dt><code><em>function_kind</em></code></dt>
<dd>
Specifies the name space of the function to be searched upon. The valid name spaces are :
<ul>
<li><b>USER</b> - Looks up the function(s) among the user defined functions.</li>
<li><b>SYSTEM</b> - Looks up the function(s) among the system defined functions.</li>
<li><b>ALL</b> - Looks up the function(s) among both user and system defined functions.</li>
</ul>
</dd>
<dt><code><em>function_name</em></code></dt>
<dd>
Specifies a name of an existing function in the system. The function name may be
optionally qualified with a database name. If `function_name` is qualified with
a database then the function is resolved from the user specified database, otherwise
it is resolved from the current database.<br><br>
<b>Syntax:</b>
<code>
[database_name.]function_name
</code>
</dd>
<dt><code><em>regex_pattern</em></code></dt>
<dd>
Specifies a regular expression pattern that is used to limit the results of the
statement.
<ul>
<li>Only `*` and `|` are allowed as wildcard pattern.</li>
<li>Excluding `*` and `|` the remaining pattern follows the regex semantics.</li>
<li>The leading and trailing blanks are trimmed in the input pattern before processing.</li>
</ul>
</dd>
</dl>

### Examples
{% highlight sql %}
-- List a system function `trim` by searching both user defined and system
-- defined functions.
SHOW FUNCTIONS trim;
+--------+
|function|
+--------+
|trim |
+--------+

-- List a system function `concat` by searching system defined functions.
SHOW SYSTEM FUNCTIONS concat;
+--------+
|function|
+--------+
|concat |
+--------+

-- List a qualified function `max` from database `salesdb`.
SHOW SYSTEM FUNCTIONS salesdb.max;
+--------+
|function|
+--------+
|max |
+--------+

-- List all functions starting with `t`
SHOW FUNCTIONS LIKE 't*';
+-----------------+
|function |
+-----------------+
|tan |
|tanh |
|timestamp |
|tinyint |
|to_csv |
|to_date |
|to_json |
|to_timestamp |
|to_unix_timestamp|
|to_utc_timestamp |
|transform |
|transform_keys |
|transform_values |
|translate |
|trim |
|trunc |
+-----------------+

-- List all functions starting with `yea` or `windo`
SHOW FUNCTIONS LIKE 'yea*|windo*';
+--------+
|function|
+--------+
|window |
|year |
+--------+

-- Use normal regex pattern to list function names that has 4 characters
-- with `t` as the starting character.
SHOW FUNCTIONS LIKE 't[a-z][a-z][a-z]';
+--------+
|function|
+--------+
|tanh |
|trim |
+--------+
{% endhighlight %}

### Related statements
- [DESCRIBE FUNCTION](sql-ref-syntax-aux-describe-function.html)

0 comments on commit f96486b

Please sign in to comment.