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 uploading the
JAR file on the Streaming SQL Console, you can use the Java UDFs for your SQL
jobs.
-
Create a Java UDF function JAR file.
You can use the following example as a
sample:
package udf;
import org.apache.flink.table.functions.ScalarFunction;
public class UdfTest extends ScalarFunction {
public String eval(String input){
return "Hello World " + input;
}
}
-
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.
-
Open a project from the Projects page of Streaming SQL
Console.
-
Select an already existing project from the list by clicking the
Open button or Switch button.
-
Create a new project by clicking the New Project
button.
-
Import a project by clicking the Import button.
You are redirected to the Explorer view of the project.
-
Click next to Functions.
-
Click Upload JAR.
-
Click Choose File.
-
Search and select the Java UDF function JAR file.
-
Click Create.
The selected JAR file is uploaded, and listed under Functions
and ready to be used in your SQL queries.