Using Apache Hive
Also available as:

Register 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 chose to configure the cluster so Hive can find 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 another method, 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 or HiveServer Interactive as a user who has UDF access.
    • HiveServer, for example:
      beeline -u jdbc:hive2:// -n hive -p
    • HiveServer Interactive, for example:
      beeline -n hive -u jdbc:hive2://;transportMode=binary
  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 'hdfs:///warehouse/tablespace/managed/TypeOf01-1.0-SNAPSHOT.jar';
    • Reloadable aux JAR:
      CREATE FUNCTION udftypeof AS 'com.mycompany.hiveudf.Typeof01';
    • Hive aux library directory:
      1. Set up a symbolic link on the command line of the local file system. HDFS is not supported. For example:
        ln -s /local-apps/hive-udf-aux /usr/hdp/<version>/hive/auxlib
      2. In Beeline, run the command to register the UDF.
        CREATE FUNCTION udftypeof AS 'com.mycompany.hiveudf.Typeof01';
      3. Restart HiveServer.
  4. Check that the UDF is registered.
    You scroll through the output and find default.typeof.