pythonsqlsnowflake-cloud-data-platformdata-warehouse

Snowflake how to call External Function in Snowpark


I want to call an External Function defined in Snowflake from Snowpark python code. For example, I am trying to manipulate the dataframe like this:

dataframe = dataframe.with_column('name', sql_expr("select test_ext(3,4)"))

However the input to the function sql_expr is not getting recognized by the python interpretor. (Here, test_ext() is an External Function which integrates with Azure.)

syntax error line 1 at position 85 unexpected 'select'.
syntax error line 1 at position 103 unexpected '4'.

Am I using the syntax correctly? The official docs do not give any examples for sql_expr


Solution

  • I could not reproduce the same error, but it should work like below:

    1. You need to use the module function:
    from snowflake.snowpark.functions import function 
    
    1. Create a function object from your ext function:
    test_ext = function("test_ext")
    
    1. Then you should be able to call it like:
    dataframe = dataframe.with_column('name', test_ext(3,4))