snowflake.snowpark.udaf.UDAFRegistration¶
- class snowflake.snowpark.udaf.UDAFRegistration(session: Optional[Session])[source]¶
Bases:
objectProvides methods to register lambdas and functions as UDAFs in the Snowflake database. For more information about Snowflake Python UDAFs, see Python UDAFs.
session.udafreturns an object of this class. You can use this object to register UDAFs that you plan to use in the current session or permanently. The methods that register a UDAF return aUserDefinedAggregateFunctionobject, which you can also use inColumnexpressions.Registering a UDAF is like registering a scalar UDF, you can use
register()orsnowflake.snowpark.functions.udaf()to explicitly register it. You can also use the decorator @udaf. They all usecloudpickleto transfer the code from the client to the server. Another way is to useregister_from_file(). Refer to modulesnowflake.snowpark.udaf.UDAFRegistrationfor when to use them.To query a registered UDAF is the same as to query other aggregate functions. Refer to
agg(). If you want to query a UDAF right after it’s created, you can call the createdUserDefinedAggregateFunctioninstance like in Example 1 below.- Example 1
Create a temporary UDAF and call it:
- Example 2
Create a UDAF with type hints and
@udafdecorator and query it:- Example 3
Create a permanent UDAF with a name and call it in SQL:
- Example 4
Create a UDAF with UDF-level imports and type hints:
- Example 5
Create a UDAF with UDF-level packages and type hints:
- Example 6
Creating a UDAF from a local Python file:
- Example 7
Creating a UDAF from a Python file on an internal stage:
See also
Methods
describe(udaf_obj)Returns a
DataFramethat describes the properties of a UDAF.register(handler[, return_type, ...])Registers a Python function as a Snowflake Python UDAF and returns the UDAF.
register_from_file(file_path, handler_name)Registers a Python class as a Snowflake Python UDAF from a Python or zip file, and returns the UDAF.