Add permanent UDF in hive

Source: Internet
Author: User
Permanent custom hive function 1: the reason for doing this:

There are some functions that are relatively basic and common. It is troublesome to create a temporary function every time. Such basic functions need to be directly integrated into hive to avoid creation every time.

2: Steps

I own an account zb_test

The custom function is ready.


Log on to the Linux Account and modify the. bashrc file in the home directory of the Account:

Change classpath to the following:

Export classpath = $ java_home/lib: $ java_home/JRE/lib: $ sqoop_home/lib:/opt/boh-2.0.0/hadoop/share/hadoop/

Tools/lib/*:/opt/boh-2.0.0/hadoop/share/hadoop/common/lib /*: /opt/boh-2.0.0/hadoop/share/hadoop/common/*:/opt/boh-2.0.0/hive/Li

B/*: $ classpath (used for self-compilation)

Obtain the source code of hive-0.12.0-cdh5.0.0-src.tar.gz.

Unzip, find the hive-exec-0.12.0-cdh5.0.0.jar package (hive function is related to this), and then unzip.

Jar-xvf XXX. Jar

Compile the Java file of the UDF, for example, put it under UTF.

Javac./UTF /*

Generate the. Class file and put it in the ABC directory.

Compress the. Class file into a jar package.

Jar-CVF./Hello. Jar./ABC /*

Generate a jar package named hello. Jar

Put the jar package in the/data/zb_test/directory.

Then modify the/data/zb_test/. bashrc file:

Export classpath =/data/zb_test/hello. jar: $ java_home/lib: $ java_home/JRE/lib: $ sqoop_home/lib:/opt/boh-2.0.0/hadoop/share/hadoop/tools/lib /*: /opt/boh-2.0.0/hadoop/share/hadoop/common/lib/*:/opt/boh-2.0.0/hadoop/share/hadoop/common /*: /opt/boh-2.0.0/hive/lib/*: $ classpath (for testing)

Register the test function to the hive function list.
Modify the $ hive_home/src/QL/src/Java/org/Apache/hadoop/hive/QL/exec/functionregistry. Java File
Import org. Apache. hadoop. hive. QL. UDF. udftest;

Registerudf ("test", udftest. Class, false );

Important steps:

1: Put all the generated. class files under the change $ hive_home/src/QL/src/Java/org/Apache/hadoop/hive/QL/UDF

2: Compile functionregistry. java file: After compilation, we find $ hive_home/src/QL/src/Java/org/Apache/hadoop/hive/QL/exec/functionregistry in the hive-exec-0.12.0-cdh5.0.0.jar. class file. We replaced it.

These paths are all under the org path after hive-exec-0.12.0-cdh5.0.0.jar decompression.

In fact, after the two steps are done, re-extract the hive-exec-0.12.0-cdh5.0.0.jar into a jar package, replace the hive in, you can.

Add permanent UDF in hive

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.