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.
-
Using Beeline, login to HiveServer or HiveServer Interactive as a user who has UDF access.
-
At the Hive prompt, select a database for use.
USE default;
-
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:
RELOAD;
CREATE FUNCTION udftypeof AS 'com.mycompany.hiveudf.Typeof01';
- Hive aux library directory:
- 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
- In Beeline, run the command to register the
UDF.
CREATE FUNCTION udftypeof AS 'com.mycompany.hiveudf.Typeof01';
- Restart HiveServer.
-
Check that the UDF is registered.
You scroll through the output and find
default.typeof
.