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

snowflake.snowpark.functions.call_udf

snowflake.snowpark.functions.call_udf(udf_name: str, *args: ColumnOrLiteral) Column[source]

Calls a user-defined function (UDF) by name.

Parameters:
  • udf_name – The name of UDF in Snowflake.

  • args

    Arguments can be in two types:

    • Column, or

    • Basic Python types, which are converted to Snowpark literals.

Example::
>>> from snowflake.snowpark.types import IntegerType
>>> udf_def = session.udf.register(lambda x, y: x + y, name="add_columns", input_types=[IntegerType(), IntegerType()], return_type=IntegerType(), replace=True)
>>> df = session.create_dataframe([[1, 2]], schema=["a", "b"])
>>> df.select(call_udf("add_columns", col("a"), col("b"))).show()
-------------------------------
|"ADD_COLUMNS(""A"", ""B"")"  |
-------------------------------
|3                            |
-------------------------------
Copy