snowflake.snowpark.udtf.UDTFRegistration¶
- class snowflake.snowpark.udtf.UDTFRegistration(session: Session)[source]¶
Bases:
objectProvides methods to register classes as UDTFs in the Snowflake database. For more information about Snowflake Python UDTFs, see Python UDTFs.
session.udtfreturns an object of this class. You can use this object to register UDTFs that you plan to use in the current session or permanently. The methods that register a UDTF return aUserDefinedTableFunctionobject, which you can also use to call the UDTF.Registering a UDTF is like registering a scalar UDF, you can use
register()orsnowflake.snowpark.functions.udtf()to explicitly register it. You can also use the decorator @udtf. They all usecloudpickleto transfer the code from the client to the server. Another way is to useregister_from_file(). Refer to modulesnowflake.snowpark.udtf.UDTFRegistrationfor when to use them.To query a registered UDTF is the same as to query other table functions. Refer to
table_function()andjoin_table_function(). If you want to query a UDTF right after it’s created, you can call the createdUserDefinedTableFunctioninstance like in Example 1 below.- Example 1
Create a temporary UDTF and call it:
- Example 2
Create a UDTF with type hints and
@udtfdecorator and query it:- Example 3
Create a permanent UDTF with a name and call it in SQL:
- Example 4
Create a UDTF with type hints:
- Example 5
Create a UDTF with type hints by using
...for multiple columns of the same type:- Example 6
Create a UDTF with UDF-level imports and type hints:
- Example 7
Create a UDTF with UDF-level packages and type hints:
- Example 8
Creating a UDTF with the constructor and
end_partitionmethod.- Example 9
Creating a UDTF from a local Python file:
- Example 10
Creating a UDTF from a Python file on an internal stage:
See also
Methods
register(handler, output_schema[, ...])Registers a Python class as a Snowflake Python UDTF and returns the UDTF.
register_from_file(file_path, handler_name, ...)Registers a Python class as a Snowflake Python UDTF from a Python or zip file, and returns the UDTF.