snowflake.snowpark.Session.table_function¶
- Session.table_function(func_name: Union[str, List[str], Callable[[...], Any], TableFunctionCall], *func_arguments: Union[snowflake.snowpark.column.Column, str], **func_named_arguments: Union[snowflake.snowpark.column.Column, str]) DataFrame [source]¶
Creates a new DataFrame from the given snowflake SQL table function.
References: Snowflake SQL functions.
- Example 1
Query a table function by function name:
>>> from snowflake.snowpark.functions import lit >>> session.table_function("split_to_table", lit("split words to table"), lit(" ")).collect() [Row(SEQ=1, INDEX=1, VALUE='split'), Row(SEQ=1, INDEX=2, VALUE='words'), Row(SEQ=1, INDEX=3, VALUE='to'), Row(SEQ=1, INDEX=4, VALUE='table')]
- Example 2
Define a table function variable and query it:
>>> from snowflake.snowpark.functions import table_function, lit >>> split_to_table = table_function("split_to_table") >>> session.table_function(split_to_table(lit("split words to table"), lit(" "))).collect() [Row(SEQ=1, INDEX=1, VALUE='split'), Row(SEQ=1, INDEX=2, VALUE='words'), Row(SEQ=1, INDEX=3, VALUE='to'), Row(SEQ=1, INDEX=4, VALUE='table')]
- Example 3
If you want to call a UDTF right after it’s registered, the returned
UserDefinedTableFunction
is callable:>>> from snowflake.snowpark.types import IntegerType, StructField, StructType >>> from snowflake.snowpark.functions import udtf, lit >>> class GeneratorUDTF: ... def process(self, n): ... for i in range(n): ... yield (i, ) >>> generator_udtf = udtf(GeneratorUDTF, output_schema=StructType([StructField("number", IntegerType())]), input_types=[IntegerType()]) >>> session.table_function(generator_udtf(lit(3))).collect() [Row(NUMBER=0), Row(NUMBER=1), Row(NUMBER=2)]
- Parameters:
func_name – The SQL function name.
func_arguments – The positional arguments for the SQL function.
func_named_arguments – The named arguments for the SQL function, if it accepts named arguments.
- Returns:
A new
DataFrame
with data from calling the table function.
See also
DataFrame.join_table_function()
, which lateral joins an existingDataFrame
and a SQL function.Session.generator()
, which is used to instantiate aDataFrame
using Generator table function.Generator functions are not supported with
Session.table_function()
.