You are viewing documentation about an older version (1.12.1). View latest version

User-Defined Functions

User-defined functions (UDFs) in Snowpark. Please see Python UDFs for details. Furthermore, there is vectorized UDF (Please see Python UDF Batch API for details). Compared to the default row-by-row processing pattern of a normal UDF, which sometimes is inefficient, a vectorized UDF allows vectorized operations on a dataframe, with the input as a Pandas DataFrame or Pandas Series. In a vectorized UDF, you can operate on a batches of rows by handling Pandas DataFrame or Pandas Series.

In brief, the advantages of a vectorized UDF include
  • The potential for better performance if your Python code operates efficiently on batches of rows.

  • Less transformation logic is required if you are calling into libraries that operate on Pandas DataFrames or Pandas arrays.

Refer to UDFRegistration for sample code on how to create and use regular and vectorized UDF’s using Snowpark Python API.

Classes

UserDefinedFunction(func, return_type, ...)

Encapsulates a user defined lambda or function that is returned by udf(), UDFRegistration.register() or UDFRegistration.register_from_file().

UDFRegistration(session)

Provides methods to register lambdas and functions as UDFs in the Snowflake database.

Methods

describe(udf_obj)

Returns a DataFrame that describes the properties of a UDF.

register(func[, return_type, input_types, ...])

Registers a Python function as a Snowflake Python UDF and returns the UDF.

register_from_file(file_path, func_name[, ...])

Registers a Python function as a Snowflake Python UDF from a Python or zip file, and returns the UDF.

Attributes

func

The Python function or a tuple containing the Python file path and the function name.

name

The UDF name.