Skip to content

Commit

Permalink
Move SQL UDF content
Browse files Browse the repository at this point in the history
Into the separate page, and adjust the generic content to be suitable
for any UDF language.
  • Loading branch information
mosabua committed Dec 16, 2024
1 parent a1fcbce commit bcb9f6f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 22 deletions.
29 changes: 7 additions & 22 deletions docs/src/main/sphinx/udf/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ value, similar to [built-in functions](/functions).
UDFs are defined and written using the [SQL routine language](/udf/sql).

:::{note}
User-defined functions can alternatively be written in Java and deployed as a
Custom functions can alternatively be written in Java and deployed as a
plugin. Details are available in the [developer guide](/develop/functions).
:::

(udf-declaration)=
## UDF declaration

Declare the UDF with a [](/udf/function) keyword using the supported statements
for [](/udf/sql).

A UDF can be declared and used as an [inline UDF](udf-inline) or declared as a
[catalog UDF](udf-catalog) and used repeatedly.
A UDF can be declared as an [inline UDF](udf-inline) to be used in the current
query, or declared as a [catalog UDF](udf-catalog) to be used in any future
query.

(udf-inline)=
## Inline user-defined functions
Expand Down Expand Up @@ -111,9 +109,9 @@ Processing UDFs can potentially be resource intensive on the cluster in
terms of memory and processing. Take the following considerations into account
when writing and running UDFs:

* Some checks for the runtime behavior of UDF are in place. For example,
UDFs that take longer to process than a hardcoded threshold are
automatically terminated.
* Some checks for the runtime behavior of queries, and therefore UDF processing,
are in place. For example, if a query takes longer to process than a hardcoded
threshold, processing is automatically terminated.
* Avoid creation of arrays in a looping construct. Each iteration creates a
separate new array with all items and copies the data for each modification,
leaving the prior array in memory for automated clean up later. Use a [lambda
Expand All @@ -126,16 +124,3 @@ when writing and running UDFs:
unless the code has some special handling for null values. You must declare
this explicitly since `CALLED ON NULL INPUT` is the default characteristic.

## Limitations

The following limitations apply to UDFs.

* UDFs must be declared before they are referenced.
* Recursion cannot be declared or processed.
* Mutual recursion can not be declared or processed.
* Queries cannot be processed in a UDF.

Specifically this means that UDFs can not use `SELECT` queries to retrieve
data or any other queries to process data within the UDF. Instead queries can
use UDFs to process data. UDFs only work on data provided as input values and
only provide output data from the `RETURN` statement.
14 changes: 14 additions & 0 deletions docs/src/main/sphinx/udf/sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,17 @@ END REPEAT;
Labels can be used with the `ITERATE` and `LEAVE` statements to continue
processing the block or leave the block. This flow control is also supported for
nested blocks and labels.

## Limitations

The following limitations apply to SQL UDFs.

* UDFs must be declared before they are referenced.
* Recursion cannot be declared or processed.
* Mutual recursion can not be declared or processed.
* Queries cannot be processed in a UDF.

Specifically this means that UDFs can not use `SELECT` queries to retrieve
data or any other queries to process data within the UDF. Instead queries can
use UDFs to process data. UDFs only work on data provided as input values and
only provide output data from the `RETURN` statement.

0 comments on commit bcb9f6f

Please sign in to comment.