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> <workload_username>@<datahub_hostname>:/usr/share/flink-connectors
  3. Navigate to the Streaming SQL Console.
    1. Navigate to Management Console > Environments, and select the environment where you have created your cluster.
    2. Select the Streaming Analytics cluster from the list of Data Hub clusters.
    3. Select Streaming SQL Console from the list of services.
    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');