Creating Java User-defined functions

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.

  1. 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;
  2. Navigate to the Streaming SQL Console.
    1. Go to your cluster in Cloudera Manager.
    2. Select SQL Stream Builder from the list of services.
    3. Click SQLStreamBuilder Console.
    The Streaming SQL Console opens in a new window.
  3. Select Functions from the main menu.
  4. Click Upload JAR.
  5. Click Choose File.
  6. Search and select the Java UDF function JAR file.
  7. Click Create.

The selected JAR file is uploaded, and listed on the Functions page and ready to be used in your SQL queries.