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. Open a project from the Projects page of Streaming SQL Console.
    1. Select an already existing project from the list by clicking the Open button or Switch button.
    2. Create a new project by clicking the New Project button.
    3. Import a project by clicking the Import button.
    You are redirected to the Explorer view of the project.
  4. Click next to Functions.
  5. Click Upload JAR.
  6. Click Choose File.
  7. Search and select the Java UDF function JAR file.
  8. Click Create.

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