-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-28793][DOC][SQL] Document CREATE FUNCTION in SQL Reference #25894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Test build #111168 has finished for PR 25894 at commit
|
| <dt><code><em>TEMPORARY</em></code></dt> | ||
| <dd> | ||
| Indicates the scope of function being created. When TEMPORARY is specified, the | ||
| created function is valid in the current session. No persistent entry is made |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
valid -> valid and visible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gatorsmile thanks.. fixed.
|
|
||
| ### Examples | ||
| {% highlight sql %} | ||
| -- 1. Create a simple UDF `SimpleUdf` that adds the supplied integet value by 10. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
integet -> integral
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gatorsmile fixed.
| <dt><code><em>class_name</em></code></dt> | ||
| <dd> | ||
| Specifies the name of the class that provides the implementation for function to be created. | ||
| The implementing class should extend from one of the base classes in `Hive` as follows: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UserDefinedAggregateFunction. We also support this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also we can extend org.apache.spark.sql.api.java.UDF0,... UDF22. see https://github.com/apache/spark/blob/master/sql/core/src/test/java/test/org/apache/spark/sql/JavaStringLength.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gatorsmile I have created a place holder link for custom scalar functions. There is already a place holder for aggregate functions and a lot of content is already in place.
| 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to explain we can create/register temporary SQL functions via Python/Scala/Java APIs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gatorsmile I have created a place holder link for custom scalar functions. There is already a place holder for aggregate functions and a lot of content is already in place.
|
Test build #111187 has finished for PR 25894 at commit
|
|
Test build #111860 has finished for PR 25894 at commit
|
| ### Related statements | ||
| - [SHOW FUNCTIONS](sql-ref-syntax-aux-show-functions.html) | ||
| - [DESCRIBE FUNCTION](sql-ref-syntax-aux-describe-function.html) | ||
| - [DESCRIBE FUNCTION](sql-ref-syntax-aux-describe-function.html) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
duplicate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gatorsmile oops.. thanks for catching it. Will fix.
| </div> | ||
|
|
||
| ## Scalar Functions | ||
| (to be filled soon) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a JIRA?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gatorsmile created here
gatorsmile
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM except two comments.
|
Test build #112005 has finished for PR 25894 at commit
|
|
cc @gatorsmile |
| <dt><code><em>IF NOT EXISTS</em></code></dt> | ||
| <dd> | ||
| 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: remove comma
| </dd> | ||
| <dt><code><em>TEMPORARY</em></code></dt> | ||
| <dd> | ||
| Indicates the scope of function being created. When TEMPORARY is specified, the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: code-format TEMPORARY?
| <dl> | ||
| <dt><code><em>OR REPLACE</em></code></dt> | ||
| <dd> | ||
| If specified, the resources for function are reloaded. This is mainly useful |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for the function
| <dt><code><em>class_name</em></code></dt> | ||
| <dd> | ||
| Specifies the name of the class that provides the implementation for function to be created. | ||
| The implementing class should extend from one of the base classes as follows: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove 'from'
|
|
||
| ### Examples | ||
| {% highlight sql %} | ||
| -- 1. Create a simple UDF `SimpleUdf` that adds the supplied integral value by 10. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"increments" rather than "adds"?
| -- import org.apache.hadoop.hive.ql.exec.UDF; | ||
| -- public class SimpleUdf extends UDF { | ||
| -- public int evaluate(int value) { | ||
| -- return value + 10; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: indent this more
| -- return value + 10; | ||
| -- } | ||
| -- } | ||
| -- 2. Compile and place it in a jar file called `SimpleUdf.jar` in /tmp. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: jar -> JAR
| | simple_temp_udf| | ||
| +------------------+ | ||
|
|
||
| -- 1. Mofify `SimpleUdf`'s implementation to add supplied integral value by 20. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mofify -> Modify
|
|
||
| -- public class SimpleUdfR extends UDF { | ||
| -- public int evaluate(int value) { | ||
| -- return value + 20; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indent here
|
Test build #112408 has finished for PR 25894 at commit
|
|
Merged to master |
|
Thanks a lot @srowen @gatorsmile |
What changes were proposed in this pull request?
Document CREATE FUNCTION 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.




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