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.
-
Go to your cluster in Cloudera Manager.
-
Select SQL Stream Builder from the list of services.
-
Click .
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.