Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

How to declare UDF globaly( without having to do add jar/ create temp function as....)

How to declare UDF globaly( without having to do add jar/ create temp function as....)

New Contributor

Hi,

we have created UDF, when we use below lines it works fine

ADD JAR hdfs:///tmp/xxx-1.jar;

CREATE TEMPORARY FUNCTION rate as 'com.hive.udf.XXX';

how/where we can save that UDF so we don't need to add above lines every time we do query.

we tried to put into /apps/hive/lib but it didn't work

Thanks

3 REPLIES 3

Re: How to declare UDF globaly( without having to do add jar/ create temp function as....)

Super Collaborator

Hi @krima,

Add Jar can be eliminated by passing "hive.aux.jars.path" in hive-site.xml(must have hive-server restart after the change),

on the other hand, you can use the permanent function fecility to have the function defined permanently.

Hope this helps!!

Re: How to declare UDF globaly( without having to do add jar/ create temp function as....)

Super Collaborator

Hi @krima,

Add Jar can be eliminated by passing "hive.aux.jars.path" in hive-site.xml(must have hive-server restart after the change),

on the other hand, you can use the permanent function fecility to have the function defined permanently.

Hope this helps!!

Re: How to declare UDF globaly( without having to do add jar/ create temp function as....)

New Contributor
@krima

you would still have to add the JAR to have it accessed globally.

I was trying to add a sequential row ID to a set of tables in Hive.

The JAR i used is available here: https://mvnrepository.com/artifact/org.apache.hive/hive-contrib/1.1.0 and the function name was row_sequence(). This JAR has tons of other functions available as well.

Here's what worked for me:

-- Download the JAR and drop it into a location in HDFS (ex: /tmp/JAR)

-- in Hive CLI or Beeline, enter the following:

- ADD JAR hdfs:///tmp/JAR/<nameofJAR>;

- CREATE FUNCTION row_sequence as 'org.apache.hadoop.hive.contrib.udf.UDFRowSequence' USING JAR '

hdfs:///tmp/JAR/<nameofJAR>';

- run your query against the table with the UDF function defined: select row_sequence(), plants from projectnova.sh_plants;

credit for the finding goes to Ranjith Pulluru. @rpulluru

Cheers.