Skip to main content
Creates a new UDF/UDTF with the given options. A UDTF is simply a UDF defined to return a single table, using the RETURNS TABLE clause.
CREATE FUNCTION Syntax

Parameters

OR REPLACE

Any existing UDF with the same name will be dropped before creating this one

<function name>

Name of the UDF, which can be referenced in subsequent commands

RETURNS TABLE

Specifies that the UDF returns a table after execution and defines the column names and types to which the function’s output data is expected to conform
This defines the UDF as a User-Defined Table Function (UDTF), which allows the function to be called within a SQL query; see Executing Functions for details.

MODE

Name of the execution mode for the UDF; the following modes are available:
ConstantDescription
DISTRIBUTEDThe function’s processing will be distributed among the nodes in the cluster
NONDISTRIBUTEDThe function’s processing will be completed on a single node in the cluster

RUN_COMMAND

The command used to execute the files associated with the UDF; e.g., python

RUN_COMMAND_ARGS

The arguments supplied alongside the given RUN_COMMAND; e.g.:

FILE PATHS

A comma-separated list of single-quoted file paths from which the function and any additional files will be loaded; the file paths should be KiFS locations and exist prior to the UDF/UDTF creation.

WITH OPTIONS

Optional indicator that a comma-delimited list of option/value assignments will follow
OptionDescription
max_concurrency_per_nodeThe maximum number of concurrent instances of the function that will be executed per node. Setting to 0 allows unlimited concurrency. The default value is 0.
set_environmentThe Python UDF environment to use for this Python UDF.

Examples

Before creating a UDF/UDTF, upload the function file, udf_st.py to a new directory, udf, in KiFS:
Create UDF Directory Example
UPLOAD UDF FILE Example
To create a distributed Python udf_st UDF that uses that file:
CREATE FUNCTION (UDF) Example
To create the same function as a UDTF that returns a result set instead:
CREATE FUNCTION (UDTF) Example