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