You can create User Defined Functions (UDF) using Java after manually adding the UDF
function JAR file that contains the UDF class to the Flink connectors. After creating the
function in the SQL window, you can select Java as a language for the UDFs.
-
Create a Java UDF function JAR file based on the following example:
package udf;
import org.apache.flink.table.functions.ScalarFunction;
public class UdfTest extends ScalarFunction {
public String eval(String input){
return "Hello World " + input;
}
}
-
Copy the JAR file to the flink connectors folder:
scp <jar_location>/<jar_filename> <workload_username>@<datahub_hostname>:/usr/share/flink-connectors
-
Navigate to the Streaming SQL Console.
-
Navigate to , and select the environment where you have created your
cluster.
-
Select the Streaming Analytics cluster from the list of
Data Hub clusters.
-
Select Streaming SQL Console from the list of
services.
The Streaming SQL Console opens in a new window.
-
Run the following query to create the function:
CREATE FUNCTION myFunction AS 'udf.UdfTest’ LANGUAGE java;
-
Test the function by running a
SELECT
query.
SELECT myFunction('test');