Adding Java to the Functions language option

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.

  1. 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;
  2. Copy the JAR file to the flink connectors folder:
    scp <jar_location>/<jar_filename> <your_hostname>:/usr/share/flink-connectors
  3. 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.
  4. Run the following query to create the function:
    CREATE FUNCTION myFunction AS 'udf.UdfTest’ LANGUAGE java;
  5. Test the function by running a SELECT query.
    SELECT myFunction('test');