A UDF (user-defined function) is a user-written function that can be called from Snowflake in the same way that a built-in function can be called.
Snowflake supports UDFs written in multiple languages, including Java.
For each row passed to a Java UDF, the UDF returns either a scalar (i.e. single) value or, if defined as a table function, a set of rows.
UDFs accept 0 or more parameters.
When a user calls a UDF, the user passes the name of the UDF and the parameters of the UDF to Snowflake. If the UDF is a Java UDF, Snowflake calls the appropriate Java code (called a handler method) in a JAR file. The handler method then returns the output to Snowflake, which passes it back to the client.
Deciding When to Use a Java UDF
This section describes advantages and limitations of Java UDFs.
For information about other potential languages in which to write UDFs, and for comparisons among those languages, see Overview of UDFs.
For information about other ways to extend Snowflake, see:
External Functions
Stored Procedures
Snowpark
Advantages of Java UDFs
Java UDFs are particularly appropriate when one or more of the following are true:
You already have Java code (source or compiled) that you can use.
Your code uses (or could use) functions that already exist in standard Java libraries.
You know Java as well as or better than the other languages that support UDFs.
Limitations on Java UDFs
General Limitations
Although your Java method can use classes and methods in the standard Java libraries, Snowflake security constraints disable some capabilities, such as writing to files. For details, see the section titled Following Good Security Practices.
Java UDFs are not sharable. Database objects that use Java UDFs are also not sharable. For example, you cannot:
Directly share a Java UDF.
Share a view that calls a Java UDF.
Share a function that calls a Java UDF.
Share a table with a masking or row access policy that calls a Java UDF.
If you try to create a Java UDF using the SECURE option (CREATE SECURE FUNCTION...), Snowflake returns an error. The SECURE option is not yet supported for Java UDFs.
Granting USAGE privilege on a Java UDF might allow the recipient to see the contents of files imported by that UDF. If you grant the USAGE privilege on a Java UDF to a role, and if that role executes a statement that calls that Java UDF, then any Java UDF in the same statement could read the contents of any files imported by the Java UDF on which you granted USAGE privilege.
Database replication does not include external or internal stages yet. When you promote a secondary database to serve as the primary database, you must recreate stage objects and re-import any files missing in internal stages. The files should have the same path and filenames as in the original primary database.