Update: Scala User-Defined Functions
We have a quick update for our Scala and Java users: you can now create Scala user-defined functions (UDFs) in-line or from a stage! Previously you could only create Scala UDFs using the Snowpark client SDK. Now you can create them in-line in SQL. Here’s a breakdown of the supported handler locations for each language:
Scala UDFs created in-line or from a stage are currently in Public Preview.
Here is an example of a Scala UDF handler written in-line:
CREATE OR REPLACE FUNCTION echo_varchar(x VARCHAR)
RETURNS VARCHAR
LANGUAGE SCALA
CALLED ON NULL INPUT
RUNTIME_VERSION = 2.12
HANDLER='Echo.echoVarchar'
AS
$$
class Echo {
def echoVarchar(x : String): String = {
return x
}
}
$$;
You can also create the above UDF by compiling your Scala code to a JAR, uploading that to a stage, and referring to it in the CREATE FUNCTION
statement as so:
CREATE OR REPLACE FUNCTION echo_varchar(x VARCHAR)
RETURNS VARCHAR
LANGUAGE SCALA
CALLED ON NULL INPUT
RUNTIME_VERSION = 2.12
IMPORTS = '@my_stage/scala_app.jar'
HANDLER='Echo.echoVarchar';
Our documentation has been updated, check the following articles to get started: