Syntax
Parameters
Configuration options
Supported data types
The following SQL data types are supported for UDF parameters and return values:
The following types are not supported in UDFs:
GEOGRAPHY, STRUCT.
Python code requirements
The Python code must contain either a single function definition or a function namedprocess. This function receives the SQL parameters as Python arguments and returns the result.
- Function naming: If your code contains multiple functions, the entry point must be named
process. If there is only one function, it can have any name. - Parameter names: Python parameter names do not need to match SQL parameter names, but they are passed positionally in the order defined.
- Return value: Return the computed value directly. Return
Noneto represent SQLNULL. - NULL handling: NULL SQL values are passed as Python
None. Your code should handleNonevalues appropriately.
Examples
Basic arithmetic function
The following example creates a function that adds two integers:8
Function with no parameters
Using external packages
The following example uses NumPy to compute the percentile of an array:12.9
Working with dates
2026-02-02
Setting memory limit and description
Vectorized UDFs
For improved performance when processing large datasets, you can write vectorized UDFs that process data in batches using PyArrow or Pandas. Vectorized UDFs receive entire columns of data at once instead of individual values. Unlike scalar UDFs, the Python function in a vectorized UDF must always have a single argument annotated with typepandas.DataFrame or pyarrow.RecordBatch.
This type annotation is what distinguishes vectorized UDFs from scalar UDFs.
Pandas vectorized UDF
A Pandas vectorized UDF receives apandas.DataFrame and must return a pandas.Series:
Column names and positions in the DataFrame match the parameter names and order from the SQL function declaration.
You can access columns by name (e.g., df['param_name']) or by position (e.g., df.iloc[:, 0]), where position 0 corresponds to the first parameter, position 1 to the second, and so on.
PyArrow vectorized UDF
A PyArrow vectorized UDF receives apyarrow.RecordBatch and must return a pyarrow.RecordBatch:
Vectorized UDFs automatically handle NULL values according to the library’s conventions.
Viewing user-defined functions
Queryinformation_schema.routines to view all user-defined functions:
Limitations
- Language: Only Python is supported. Other languages such as JavaScript or WebAssembly are not available.
- Unsupported types:
GEOGRAPHYandSTRUCTtypes cannot be used as parameters or return types. - Schema restriction: User-defined functions can only be created in the
publicschema. Custom schemas are not supported. - Name conflicts: Function names cannot match existing built-in function names.
- Overloading: Function overloading (multiple functions with the same name but different signatures) is not supported. Each function name must be unique.
- Package availability: Only packages available on PyPI can be installed. Private or custom packages are not supported.
- Execution context: UDFs run in isolated containers and cannot access external network resources, the file system, or other system resources.