2019-08-19 02:17:50 -04:00
|
|
|
---
|
|
|
|
layout: global
|
|
|
|
title: CREATE FUNCTION
|
|
|
|
displayTitle: CREATE FUNCTION
|
|
|
|
license: |
|
|
|
|
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.
|
|
|
|
---
|
|
|
|
|
2019-10-22 09:56:44 -04:00
|
|
|
### Description
|
[SPARK-31383][SQL][DOC] Clean up the SQL documents in docs/sql-ref*
### What changes were proposed in this pull request?
This PR intends to clean up the SQL documents in `doc/sql-ref*`.
Main changes are as follows;
- Fixes wrong syntaxes and capitalize sub-titles
- Adds some DDL queries in `Examples` so that users can run examples there
- Makes query output in `Examples` follows the `Dataset.showString` (right-aligned) format
- Adds/Removes spaces, Indents, or blank lines to follow the format below;
```
---
license...
---
### Description
Writes what's the syntax is.
### Syntax
{% highlight sql %}
SELECT...
WHERE... // 4 indents after the second line
...
{% endhighlight %}
### Parameters
<dl>
<dt><code><em>Param Name</em></code></dt>
<dd>
Param Description
</dd>
...
</dl>
### Examples
{% highlight sql %}
-- It is better that users are able to execute example queries here.
-- So, we prepare test data in the first section if possible.
CREATE TABLE t (key STRING, value DOUBLE);
INSERT INTO t VALUES
('a', 1.0), ('a', 2.0), ('b', 3.0), ('c', 4.0);
-- query output has 2 indents and it follows the `Dataset.showString`
-- format (right-aligned).
SELECT * FROM t;
+---+-----+
|key|value|
+---+-----+
| a| 1.0|
| a| 2.0|
| b| 3.0|
| c| 4.0|
+---+-----+
-- Query statements after the second line have 4 indents.
SELECT key, SUM(value)
FROM t
GROUP BY key;
+---+----------+
|key|sum(value)|
+---+----------+
| c| 4.0|
| b| 3.0|
| a| 3.0|
+---+----------+
...
{% endhighlight %}
### Related Statements
* [XXX](xxx.html)
* ...
```
### Why are the changes needed?
The most changes of this PR are pretty minor, but I think the consistent formats/rules to write documents are important for long-term maintenance in our community
### Does this PR introduce any user-facing change?
Yes.
### How was this patch tested?
Manually checked.
Closes #28151 from maropu/MakeRightAligned.
Authored-by: Takeshi Yamamuro <yamamuro@apache.org>
Signed-off-by: Sean Owen <srowen@gmail.com>
2020-04-13 00:40:36 -04:00
|
|
|
|
2019-10-22 09:56:44 -04:00
|
|
|
The `CREATE FUNCTION` statement is used to create a temporary or permanent function
|
|
|
|
in Spark. Temporary functions are scoped at a session level where as permanent
|
|
|
|
functions are created in the persistent catalog and are made available to
|
|
|
|
all sessions. The resources specified in the `USING` clause are made available
|
|
|
|
to all executors when they are executed for the first time. In addition to the
|
|
|
|
SQL interface, spark allows users to create custom user defined scalar and
|
|
|
|
aggregate functions using Scala, Python and Java APIs. Please refer to
|
2020-04-30 17:30:35 -04:00
|
|
|
[Scalar UDFs](sql-ref-functions-udf-scalar.html) and
|
|
|
|
[UDAFs](sql-ref-functions-udf-aggregate.html) for more information.
|
2019-10-22 09:56:44 -04:00
|
|
|
|
|
|
|
### Syntax
|
[SPARK-31383][SQL][DOC] Clean up the SQL documents in docs/sql-ref*
### What changes were proposed in this pull request?
This PR intends to clean up the SQL documents in `doc/sql-ref*`.
Main changes are as follows;
- Fixes wrong syntaxes and capitalize sub-titles
- Adds some DDL queries in `Examples` so that users can run examples there
- Makes query output in `Examples` follows the `Dataset.showString` (right-aligned) format
- Adds/Removes spaces, Indents, or blank lines to follow the format below;
```
---
license...
---
### Description
Writes what's the syntax is.
### Syntax
{% highlight sql %}
SELECT...
WHERE... // 4 indents after the second line
...
{% endhighlight %}
### Parameters
<dl>
<dt><code><em>Param Name</em></code></dt>
<dd>
Param Description
</dd>
...
</dl>
### Examples
{% highlight sql %}
-- It is better that users are able to execute example queries here.
-- So, we prepare test data in the first section if possible.
CREATE TABLE t (key STRING, value DOUBLE);
INSERT INTO t VALUES
('a', 1.0), ('a', 2.0), ('b', 3.0), ('c', 4.0);
-- query output has 2 indents and it follows the `Dataset.showString`
-- format (right-aligned).
SELECT * FROM t;
+---+-----+
|key|value|
+---+-----+
| a| 1.0|
| a| 2.0|
| b| 3.0|
| c| 4.0|
+---+-----+
-- Query statements after the second line have 4 indents.
SELECT key, SUM(value)
FROM t
GROUP BY key;
+---+----------+
|key|sum(value)|
+---+----------+
| c| 4.0|
| b| 3.0|
| a| 3.0|
+---+----------+
...
{% endhighlight %}
### Related Statements
* [XXX](xxx.html)
* ...
```
### Why are the changes needed?
The most changes of this PR are pretty minor, but I think the consistent formats/rules to write documents are important for long-term maintenance in our community
### Does this PR introduce any user-facing change?
Yes.
### How was this patch tested?
Manually checked.
Closes #28151 from maropu/MakeRightAligned.
Authored-by: Takeshi Yamamuro <yamamuro@apache.org>
Signed-off-by: Sean Owen <srowen@gmail.com>
2020-04-13 00:40:36 -04:00
|
|
|
|
2020-05-10 13:57:25 -04:00
|
|
|
```sql
|
2019-10-22 09:56:44 -04:00
|
|
|
CREATE [ OR REPLACE ] [ TEMPORARY ] FUNCTION [ IF NOT EXISTS ]
|
|
|
|
function_name AS class_name [ resource_locations ]
|
2020-05-10 13:57:25 -04:00
|
|
|
```
|
2019-10-22 09:56:44 -04:00
|
|
|
|
|
|
|
### Parameters
|
[SPARK-31383][SQL][DOC] Clean up the SQL documents in docs/sql-ref*
### What changes were proposed in this pull request?
This PR intends to clean up the SQL documents in `doc/sql-ref*`.
Main changes are as follows;
- Fixes wrong syntaxes and capitalize sub-titles
- Adds some DDL queries in `Examples` so that users can run examples there
- Makes query output in `Examples` follows the `Dataset.showString` (right-aligned) format
- Adds/Removes spaces, Indents, or blank lines to follow the format below;
```
---
license...
---
### Description
Writes what's the syntax is.
### Syntax
{% highlight sql %}
SELECT...
WHERE... // 4 indents after the second line
...
{% endhighlight %}
### Parameters
<dl>
<dt><code><em>Param Name</em></code></dt>
<dd>
Param Description
</dd>
...
</dl>
### Examples
{% highlight sql %}
-- It is better that users are able to execute example queries here.
-- So, we prepare test data in the first section if possible.
CREATE TABLE t (key STRING, value DOUBLE);
INSERT INTO t VALUES
('a', 1.0), ('a', 2.0), ('b', 3.0), ('c', 4.0);
-- query output has 2 indents and it follows the `Dataset.showString`
-- format (right-aligned).
SELECT * FROM t;
+---+-----+
|key|value|
+---+-----+
| a| 1.0|
| a| 2.0|
| b| 3.0|
| c| 4.0|
+---+-----+
-- Query statements after the second line have 4 indents.
SELECT key, SUM(value)
FROM t
GROUP BY key;
+---+----------+
|key|sum(value)|
+---+----------+
| c| 4.0|
| b| 3.0|
| a| 3.0|
+---+----------+
...
{% endhighlight %}
### Related Statements
* [XXX](xxx.html)
* ...
```
### Why are the changes needed?
The most changes of this PR are pretty minor, but I think the consistent formats/rules to write documents are important for long-term maintenance in our community
### Does this PR introduce any user-facing change?
Yes.
### How was this patch tested?
Manually checked.
Closes #28151 from maropu/MakeRightAligned.
Authored-by: Takeshi Yamamuro <yamamuro@apache.org>
Signed-off-by: Sean Owen <srowen@gmail.com>
2020-04-13 00:40:36 -04:00
|
|
|
|
2020-05-10 13:57:25 -04:00
|
|
|
* **OR REPLACE**
|
|
|
|
|
2019-10-22 09:56:44 -04:00
|
|
|
If specified, the resources for the function are reloaded. This is mainly useful
|
|
|
|
to pick up any changes made to the implementation of the function. This
|
2020-05-10 13:57:25 -04:00
|
|
|
parameter is mutually exclusive to `IF NOT EXISTS` and can not
|
2019-10-22 09:56:44 -04:00
|
|
|
be specified together.
|
2020-05-10 13:57:25 -04:00
|
|
|
|
|
|
|
* **TEMPORARY**
|
|
|
|
|
|
|
|
Indicates the scope of function being created. When `TEMPORARY` is specified, the
|
2019-10-22 09:56:44 -04:00
|
|
|
created function is valid and visible in the current session. No persistent
|
|
|
|
entry is made in the catalog for these kind of functions.
|
2020-05-10 13:57:25 -04:00
|
|
|
|
|
|
|
* **IF NOT EXISTS**
|
|
|
|
|
2019-10-22 09:56:44 -04:00
|
|
|
If specified, creates the function only when it does not exist. The creation
|
|
|
|
of function succeeds (no error is thrown) if the specified function already
|
2020-05-10 13:57:25 -04:00
|
|
|
exists in the system. This parameter is mutually exclusive to `OR REPLACE`
|
2019-10-22 09:56:44 -04:00
|
|
|
and can not be specified together.
|
2020-05-10 13:57:25 -04:00
|
|
|
|
|
|
|
* **function_name**
|
|
|
|
|
|
|
|
Specifies a name of function to be created. The function name may be optionally qualified with a database name.
|
|
|
|
|
|
|
|
**Syntax:** `[ database_name. ] function_name`
|
|
|
|
|
|
|
|
* **class_name**
|
|
|
|
|
2019-10-22 09:56:44 -04:00
|
|
|
Specifies the name of the class that provides the implementation for function to be created.
|
|
|
|
The implementing class should extend one of the base classes as follows:
|
2020-05-10 13:57:25 -04:00
|
|
|
|
|
|
|
* Should extend `UDF` or `UDAF` in `org.apache.hadoop.hive.ql.exec` package.
|
|
|
|
* Should extend `AbstractGenericUDAFResolver`, `GenericUDF`, or
|
|
|
|
`GenericUDTF` in `org.apache.hadoop.hive.ql.udf.generic` package.
|
|
|
|
* Should extend `UserDefinedAggregateFunction` in `org.apache.spark.sql.expressions` package.
|
|
|
|
|
|
|
|
* **resource_locations**
|
|
|
|
|
2019-10-22 09:56:44 -04:00
|
|
|
Specifies the list of resources that contain the implementation of the function
|
2020-05-10 13:57:25 -04:00
|
|
|
along with its dependencies.
|
|
|
|
|
2021-08-24 21:04:53 -04:00
|
|
|
**Syntax:** `USING { { (JAR | FILE | ARCHIVE) resource_uri } , ... }`
|
2019-10-22 09:56:44 -04:00
|
|
|
|
|
|
|
### Examples
|
[SPARK-31383][SQL][DOC] Clean up the SQL documents in docs/sql-ref*
### What changes were proposed in this pull request?
This PR intends to clean up the SQL documents in `doc/sql-ref*`.
Main changes are as follows;
- Fixes wrong syntaxes and capitalize sub-titles
- Adds some DDL queries in `Examples` so that users can run examples there
- Makes query output in `Examples` follows the `Dataset.showString` (right-aligned) format
- Adds/Removes spaces, Indents, or blank lines to follow the format below;
```
---
license...
---
### Description
Writes what's the syntax is.
### Syntax
{% highlight sql %}
SELECT...
WHERE... // 4 indents after the second line
...
{% endhighlight %}
### Parameters
<dl>
<dt><code><em>Param Name</em></code></dt>
<dd>
Param Description
</dd>
...
</dl>
### Examples
{% highlight sql %}
-- It is better that users are able to execute example queries here.
-- So, we prepare test data in the first section if possible.
CREATE TABLE t (key STRING, value DOUBLE);
INSERT INTO t VALUES
('a', 1.0), ('a', 2.0), ('b', 3.0), ('c', 4.0);
-- query output has 2 indents and it follows the `Dataset.showString`
-- format (right-aligned).
SELECT * FROM t;
+---+-----+
|key|value|
+---+-----+
| a| 1.0|
| a| 2.0|
| b| 3.0|
| c| 4.0|
+---+-----+
-- Query statements after the second line have 4 indents.
SELECT key, SUM(value)
FROM t
GROUP BY key;
+---+----------+
|key|sum(value)|
+---+----------+
| c| 4.0|
| b| 3.0|
| a| 3.0|
+---+----------+
...
{% endhighlight %}
### Related Statements
* [XXX](xxx.html)
* ...
```
### Why are the changes needed?
The most changes of this PR are pretty minor, but I think the consistent formats/rules to write documents are important for long-term maintenance in our community
### Does this PR introduce any user-facing change?
Yes.
### How was this patch tested?
Manually checked.
Closes #28151 from maropu/MakeRightAligned.
Authored-by: Takeshi Yamamuro <yamamuro@apache.org>
Signed-off-by: Sean Owen <srowen@gmail.com>
2020-04-13 00:40:36 -04:00
|
|
|
|
2020-05-10 13:57:25 -04:00
|
|
|
```sql
|
2019-10-22 09:56:44 -04:00
|
|
|
-- 1. Create a simple UDF `SimpleUdf` that increments the supplied integral value by 10.
|
|
|
|
-- import org.apache.hadoop.hive.ql.exec.UDF;
|
|
|
|
-- public class SimpleUdf extends UDF {
|
|
|
|
-- public int evaluate(int value) {
|
|
|
|
-- return value + 10;
|
|
|
|
-- }
|
|
|
|
-- }
|
|
|
|
-- 2. Compile and place it in a JAR file called `SimpleUdf.jar` in /tmp.
|
|
|
|
|
|
|
|
-- Create a table called `test` and insert two rows.
|
|
|
|
CREATE TABLE test(c1 INT);
|
|
|
|
INSERT INTO test VALUES (1), (2);
|
|
|
|
|
|
|
|
-- Create a permanent function called `simple_udf`.
|
|
|
|
CREATE FUNCTION simple_udf AS 'SimpleUdf'
|
[SPARK-31383][SQL][DOC] Clean up the SQL documents in docs/sql-ref*
### What changes were proposed in this pull request?
This PR intends to clean up the SQL documents in `doc/sql-ref*`.
Main changes are as follows;
- Fixes wrong syntaxes and capitalize sub-titles
- Adds some DDL queries in `Examples` so that users can run examples there
- Makes query output in `Examples` follows the `Dataset.showString` (right-aligned) format
- Adds/Removes spaces, Indents, or blank lines to follow the format below;
```
---
license...
---
### Description
Writes what's the syntax is.
### Syntax
{% highlight sql %}
SELECT...
WHERE... // 4 indents after the second line
...
{% endhighlight %}
### Parameters
<dl>
<dt><code><em>Param Name</em></code></dt>
<dd>
Param Description
</dd>
...
</dl>
### Examples
{% highlight sql %}
-- It is better that users are able to execute example queries here.
-- So, we prepare test data in the first section if possible.
CREATE TABLE t (key STRING, value DOUBLE);
INSERT INTO t VALUES
('a', 1.0), ('a', 2.0), ('b', 3.0), ('c', 4.0);
-- query output has 2 indents and it follows the `Dataset.showString`
-- format (right-aligned).
SELECT * FROM t;
+---+-----+
|key|value|
+---+-----+
| a| 1.0|
| a| 2.0|
| b| 3.0|
| c| 4.0|
+---+-----+
-- Query statements after the second line have 4 indents.
SELECT key, SUM(value)
FROM t
GROUP BY key;
+---+----------+
|key|sum(value)|
+---+----------+
| c| 4.0|
| b| 3.0|
| a| 3.0|
+---+----------+
...
{% endhighlight %}
### Related Statements
* [XXX](xxx.html)
* ...
```
### Why are the changes needed?
The most changes of this PR are pretty minor, but I think the consistent formats/rules to write documents are important for long-term maintenance in our community
### Does this PR introduce any user-facing change?
Yes.
### How was this patch tested?
Manually checked.
Closes #28151 from maropu/MakeRightAligned.
Authored-by: Takeshi Yamamuro <yamamuro@apache.org>
Signed-off-by: Sean Owen <srowen@gmail.com>
2020-04-13 00:40:36 -04:00
|
|
|
USING JAR '/tmp/SimpleUdf.jar';
|
2019-10-22 09:56:44 -04:00
|
|
|
|
|
|
|
-- Verify that the function is in the registry.
|
|
|
|
SHOW USER FUNCTIONS;
|
2020-05-01 13:11:43 -04:00
|
|
|
+------------------+
|
|
|
|
| function|
|
|
|
|
+------------------+
|
|
|
|
|default.simple_udf|
|
|
|
|
+------------------+
|
2019-10-22 09:56:44 -04:00
|
|
|
|
|
|
|
-- Invoke the function. Every selected value should be incremented by 10.
|
2020-10-01 07:50:16 -04:00
|
|
|
SELECT simple_udf(c1) AS function_return_value FROM test;
|
2020-05-01 13:11:43 -04:00
|
|
|
+---------------------+
|
|
|
|
|function_return_value|
|
|
|
|
+---------------------+
|
|
|
|
| 11|
|
|
|
|
| 12|
|
|
|
|
+---------------------+
|
2019-10-22 09:56:44 -04:00
|
|
|
|
|
|
|
-- Created a temporary function.
|
|
|
|
CREATE TEMPORARY FUNCTION simple_temp_udf AS 'SimpleUdf'
|
[SPARK-31383][SQL][DOC] Clean up the SQL documents in docs/sql-ref*
### What changes were proposed in this pull request?
This PR intends to clean up the SQL documents in `doc/sql-ref*`.
Main changes are as follows;
- Fixes wrong syntaxes and capitalize sub-titles
- Adds some DDL queries in `Examples` so that users can run examples there
- Makes query output in `Examples` follows the `Dataset.showString` (right-aligned) format
- Adds/Removes spaces, Indents, or blank lines to follow the format below;
```
---
license...
---
### Description
Writes what's the syntax is.
### Syntax
{% highlight sql %}
SELECT...
WHERE... // 4 indents after the second line
...
{% endhighlight %}
### Parameters
<dl>
<dt><code><em>Param Name</em></code></dt>
<dd>
Param Description
</dd>
...
</dl>
### Examples
{% highlight sql %}
-- It is better that users are able to execute example queries here.
-- So, we prepare test data in the first section if possible.
CREATE TABLE t (key STRING, value DOUBLE);
INSERT INTO t VALUES
('a', 1.0), ('a', 2.0), ('b', 3.0), ('c', 4.0);
-- query output has 2 indents and it follows the `Dataset.showString`
-- format (right-aligned).
SELECT * FROM t;
+---+-----+
|key|value|
+---+-----+
| a| 1.0|
| a| 2.0|
| b| 3.0|
| c| 4.0|
+---+-----+
-- Query statements after the second line have 4 indents.
SELECT key, SUM(value)
FROM t
GROUP BY key;
+---+----------+
|key|sum(value)|
+---+----------+
| c| 4.0|
| b| 3.0|
| a| 3.0|
+---+----------+
...
{% endhighlight %}
### Related Statements
* [XXX](xxx.html)
* ...
```
### Why are the changes needed?
The most changes of this PR are pretty minor, but I think the consistent formats/rules to write documents are important for long-term maintenance in our community
### Does this PR introduce any user-facing change?
Yes.
### How was this patch tested?
Manually checked.
Closes #28151 from maropu/MakeRightAligned.
Authored-by: Takeshi Yamamuro <yamamuro@apache.org>
Signed-off-by: Sean Owen <srowen@gmail.com>
2020-04-13 00:40:36 -04:00
|
|
|
USING JAR '/tmp/SimpleUdf.jar';
|
2019-10-22 09:56:44 -04:00
|
|
|
|
|
|
|
-- Verify that the newly created temporary function is in the registry.
|
|
|
|
-- Please note that the temporary function does not have a qualified
|
|
|
|
-- database associated with it.
|
|
|
|
SHOW USER FUNCTIONS;
|
2020-05-01 13:11:43 -04:00
|
|
|
+------------------+
|
|
|
|
| function|
|
|
|
|
+------------------+
|
|
|
|
|default.simple_udf|
|
|
|
|
| simple_temp_udf|
|
|
|
|
+------------------+
|
2019-10-22 09:56:44 -04:00
|
|
|
|
|
|
|
-- 1. Modify `SimpleUdf`'s implementation to add supplied integral value by 20.
|
|
|
|
-- import org.apache.hadoop.hive.ql.exec.UDF;
|
|
|
|
|
|
|
|
-- public class SimpleUdfR extends UDF {
|
|
|
|
-- public int evaluate(int value) {
|
|
|
|
-- return value + 20;
|
|
|
|
-- }
|
|
|
|
-- }
|
|
|
|
-- 2. Compile and place it in a jar file called `SimpleUdfR.jar` in /tmp.
|
|
|
|
|
|
|
|
-- Replace the implementation of `simple_udf`
|
|
|
|
CREATE OR REPLACE FUNCTION simple_udf AS 'SimpleUdfR'
|
[SPARK-31383][SQL][DOC] Clean up the SQL documents in docs/sql-ref*
### What changes were proposed in this pull request?
This PR intends to clean up the SQL documents in `doc/sql-ref*`.
Main changes are as follows;
- Fixes wrong syntaxes and capitalize sub-titles
- Adds some DDL queries in `Examples` so that users can run examples there
- Makes query output in `Examples` follows the `Dataset.showString` (right-aligned) format
- Adds/Removes spaces, Indents, or blank lines to follow the format below;
```
---
license...
---
### Description
Writes what's the syntax is.
### Syntax
{% highlight sql %}
SELECT...
WHERE... // 4 indents after the second line
...
{% endhighlight %}
### Parameters
<dl>
<dt><code><em>Param Name</em></code></dt>
<dd>
Param Description
</dd>
...
</dl>
### Examples
{% highlight sql %}
-- It is better that users are able to execute example queries here.
-- So, we prepare test data in the first section if possible.
CREATE TABLE t (key STRING, value DOUBLE);
INSERT INTO t VALUES
('a', 1.0), ('a', 2.0), ('b', 3.0), ('c', 4.0);
-- query output has 2 indents and it follows the `Dataset.showString`
-- format (right-aligned).
SELECT * FROM t;
+---+-----+
|key|value|
+---+-----+
| a| 1.0|
| a| 2.0|
| b| 3.0|
| c| 4.0|
+---+-----+
-- Query statements after the second line have 4 indents.
SELECT key, SUM(value)
FROM t
GROUP BY key;
+---+----------+
|key|sum(value)|
+---+----------+
| c| 4.0|
| b| 3.0|
| a| 3.0|
+---+----------+
...
{% endhighlight %}
### Related Statements
* [XXX](xxx.html)
* ...
```
### Why are the changes needed?
The most changes of this PR are pretty minor, but I think the consistent formats/rules to write documents are important for long-term maintenance in our community
### Does this PR introduce any user-facing change?
Yes.
### How was this patch tested?
Manually checked.
Closes #28151 from maropu/MakeRightAligned.
Authored-by: Takeshi Yamamuro <yamamuro@apache.org>
Signed-off-by: Sean Owen <srowen@gmail.com>
2020-04-13 00:40:36 -04:00
|
|
|
USING JAR '/tmp/SimpleUdfR.jar';
|
2019-10-22 09:56:44 -04:00
|
|
|
|
|
|
|
-- Invoke the function. Every selected value should be incremented by 20.
|
2020-10-01 07:50:16 -04:00
|
|
|
SELECT simple_udf(c1) AS function_return_value FROM test;
|
2020-05-01 13:11:43 -04:00
|
|
|
+---------------------+
|
|
|
|
|function_return_value|
|
|
|
|
+---------------------+
|
|
|
|
| 21|
|
|
|
|
| 22|
|
|
|
|
+---------------------+
|
2020-05-10 13:57:25 -04:00
|
|
|
```
|
2019-10-22 09:56:44 -04:00
|
|
|
|
[SPARK-31383][SQL][DOC] Clean up the SQL documents in docs/sql-ref*
### What changes were proposed in this pull request?
This PR intends to clean up the SQL documents in `doc/sql-ref*`.
Main changes are as follows;
- Fixes wrong syntaxes and capitalize sub-titles
- Adds some DDL queries in `Examples` so that users can run examples there
- Makes query output in `Examples` follows the `Dataset.showString` (right-aligned) format
- Adds/Removes spaces, Indents, or blank lines to follow the format below;
```
---
license...
---
### Description
Writes what's the syntax is.
### Syntax
{% highlight sql %}
SELECT...
WHERE... // 4 indents after the second line
...
{% endhighlight %}
### Parameters
<dl>
<dt><code><em>Param Name</em></code></dt>
<dd>
Param Description
</dd>
...
</dl>
### Examples
{% highlight sql %}
-- It is better that users are able to execute example queries here.
-- So, we prepare test data in the first section if possible.
CREATE TABLE t (key STRING, value DOUBLE);
INSERT INTO t VALUES
('a', 1.0), ('a', 2.0), ('b', 3.0), ('c', 4.0);
-- query output has 2 indents and it follows the `Dataset.showString`
-- format (right-aligned).
SELECT * FROM t;
+---+-----+
|key|value|
+---+-----+
| a| 1.0|
| a| 2.0|
| b| 3.0|
| c| 4.0|
+---+-----+
-- Query statements after the second line have 4 indents.
SELECT key, SUM(value)
FROM t
GROUP BY key;
+---+----------+
|key|sum(value)|
+---+----------+
| c| 4.0|
| b| 3.0|
| a| 3.0|
+---+----------+
...
{% endhighlight %}
### Related Statements
* [XXX](xxx.html)
* ...
```
### Why are the changes needed?
The most changes of this PR are pretty minor, but I think the consistent formats/rules to write documents are important for long-term maintenance in our community
### Does this PR introduce any user-facing change?
Yes.
### How was this patch tested?
Manually checked.
Closes #28151 from maropu/MakeRightAligned.
Authored-by: Takeshi Yamamuro <yamamuro@apache.org>
Signed-off-by: Sean Owen <srowen@gmail.com>
2020-04-13 00:40:36 -04:00
|
|
|
### Related Statements
|
|
|
|
|
2020-05-10 13:57:25 -04:00
|
|
|
* [SHOW FUNCTIONS](sql-ref-syntax-aux-show-functions.html)
|
|
|
|
* [DESCRIBE FUNCTION](sql-ref-syntax-aux-describe-function.html)
|
|
|
|
* [DROP FUNCTION](sql-ref-syntax-ddl-drop-function.html)
|