Use missing functions in Snowpark

Snowpark is a Python API that allows creating Snowflake queries in a modular fashion. It is quite powerful and automatically solves a number of issues like escaping constants, and makes it easier to abstract common operations into functions. However, not all SQL functions available in Snowpark via their SQL interface are available via Snowpark. It is unclear to me why. Among the affected functions are JAROWINKLER_SIMILARITY and PARSE_URL.

Fortunately, it's relatively easy to define an inline UDF to be able to call these functions using Snowpark. For example:

import snowflake.snowpark.functions as F

session.sql('create or replace function'
+' my_udf(x string, y string)'
+' returns int language sql as'
+' $$JAROWINKLER_SIMILARITY(x, y)$$'
).show()

df = session.table('my_table')
df = df.select(
    F.call_udf('my_udf',
        df['column1'], 
        df['column2']
    )
)
df.show()

Popular Posts