Registering the UDF

In the cluster, you log into Hive, and run a command from Beeline to make the UDF functional in Hive queries. The UDF persists between HiveServer restarts.

You need to set up UDF access, using a Ranger policy for example.
In this task, the registration command differs depending on the method you choose to configure the cluster for finding the JAR. If you use the Hive aux library directory method that involves a symbolic link, you need to restart HiveServer after registration. If you use the Direct JAR reference or Reloadable aux JAR methods, you do not need to restart HiveServer. You must recreate the symbolic link after any patch or maintenance upgrades that deploy a new version of Hive.
  1. Using Beeline, login to HiveServer as a user who has UDF access.
    HiveServer, for example:
    beeline -u jdbc:hive2:// -n hive -p
  2. At the Hive prompt, select a database for use.
    USE default;
  3. Run the registration command that corresponds to the way you configured the cluster to find the JAR.
    In the case of the direct JAR reference configuration method, you include the JAR location in the command. If you use another method, you do not include the JAR location. The classloader can find the JAR.
    • Direct JAR reference:
      CREATE FUNCTION udftypeof AS 'com.mycompany.hiveudf.TypeOf01' USING JAR 'S3:///warehouse/tablespace/managed/TypeOf01-1.0-SNAPSHOT.jar';
    • Hive aux library directory (CDP Private Cloud Base only):
      1. Set up a symbolic link on the command line of the local file system.
        ln -s /local-apps/hive-udf-aux <path to hive parcel>/hive/auxlib
      2. In Beeline, run the command to register the UDF.
        CREATE FUNCTION udftypeof AS 'com.mycompany.hiveudf.Typeof01';
      3. Restart HiveServer.
    • Reloadable aux JAR (CDP Private Cloud Base only):
      CREATE FUNCTION udftypeof AS 'com.mycompany.hiveudf.Typeof01';
  4. Check that the UDF is registered.
    You scroll through the output and find default.typeof.