Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

4/29/24, 3:05 PM Calling functions and stored procedures in Snowpark Java | Snowflake Documentation

Developer Snowpark API Java Calling Functions and Stored Procedures


Calling functions and stored procedures in
Snowpark Java
To process data in a DataFrame, you can call system-defined SQL functions, user-
defined functions, and stored procedures. This topic explains how to call these in
Snowpark.
Calling system-defined functions
If you need to call system-defined SQL functions, use the equivalent static methods
in the Functions class.
The following example calls the upper static method in the Functions class (the
equivalent of the system-defined UPPER function) to return the values in the name
column with the letters in uppercase:
DataFrame df = session.table("sample_product_data");
df.select(Functions.upper(Functions.col("name"))).show();

If a system-defined SQL function is not available in the Functions class, you can
use the Functions.callUDF static method to call the system-defined function.
For callUDF , pass the name of the system-defined function as the first argument.
If you need to pass the values of columns to the system-defined function, define
and pass Column objects as additional arguments to the callUDF method.
The following example calls the system-defined function RADIANS, passing in the
value from the column degrees :
// Call the system-defined function RADIANS() on degrees.
DataFrame dfDegrees = session.range(0, 360, 45).rename("degrees", Fun
dfDegrees.select(Functions.col("degrees"), Functions.callUDF("radians

The callUDF method returns a Column , which you can pass to the DataFrame
transformation methods (e.g. filter, select, etc.).
Calling scalar user-defined functions (UDFs)
https://docs.snowflake.com/en/developer-guide/snowpark/java/calling-functions 1/1

You might also like