Managing User-Defined Functions (UDFs) with HiveServer2

Hive's query language (HiveQL) can be extended with Java-based user-defined functions (UDFs). See the Apache Hive Language Manual UDF page for information about Hive built-in UDFs. To create customized UDFs, see
the Apache Hive wiki. After creating a new Java class to extend
the com.example.hive.udf package, you must compile your code into a Java archive file (JAR), and add it to the Hive classpath with the ADD
JAR command. The ADD JAR command does not work with HiveServer2 and the Beeline client when Beeline runs on a different host. As an
alternative to ADD JAR, Hive's auxiliary paths functionality should be used.

Perform one of the following procedures depending on whether you want to create permanent or temporary functions.

User-Defined Functions (UDFs) with HiveServer2 Using Cloudera Manager

Creating Permanent Functions

Copy the JAR file to HDFS and make sure the hive user can access this JAR file.

Copy the JAR file to the host on which HiveServer2 is running. Save the JARs to any directory you choose, give the hive user read, write, and execute
access to this directory, and make a note of the path (for example, /opt/local/hive/lib/).
Note: If the Hive Metastore is running on a different host, create the same directory there that you created on the HiveServer2 host. You do not
need to copy the JAR file onto the Hive Metastore host, but the same directory must be there. For example, if you copied the JAR file to /opt/local/hive/lib/ on the
HiveServer2 host, you must create the same directory on the Hive Metastore host. If the same directory is not present on the Hive Metastore host, Hive Metastore service will not start.

In the Cloudera Manager Admin Console, go to the Hive service.

Click the Configuration tab.

Expand the Hive (Service-Wide) scope.

Click the Advanced category.

Configure the Hive Auxiliary JARs Directory property with the HiveServer2 host path and the Hive Metastore host path from Step 2, for example /opt/local/hive/lib/. Setting this property overwrites hive.aux.jars.path, even if this variable has been previously set in the HiveServer2 advanced
configuration snippet.

Creating Temporary Functions

Copy the JAR file to the host on which HiveServer2 is running. Save the JARs to any directory you choose, give the hive user read, write, and execute
access to this directory, and make a note of the path (for example, /opt/local/hive/lib/).
Note: If the Hive Metastore is running on a different host, create the same directory there that you created on the HiveServer2 host. You do not
need to copy the JAR file onto the Hive Metastore host, but the same directory must be there. For example, if you copied the JAR file to /opt/local/hive/lib/ on the
HiveServer2 host, you must create the same directory on the Hive Metastore host. If the same directory is not present on the Hive Metastore host, Hive Metastore service will not start.

In the Cloudera Manager Admin Console, go to the Hive service.

Click the Configuration tab.

Expand the Hive (Service-Wide) scope.

Click the Advanced category.

Configure the Hive Auxiliary JARs Directory property with the HiveServer2 host path and the Hive Metastore host path from Step 1, for example /opt/local/hive/lib/. Setting this property overwrites hive.aux.jars.path, even if this variable has been previously set in the HiveServer2 advanced
configuration snippet.

If this documentation includes code, including but not limited to, code examples, Cloudera makes this available to you under the terms of the Apache License, Version 2.0, including any required
notices. A copy of the Apache License Version 2.0 can be found here.