Hive compiled source code supports custom UDF functions
In our work, we need to use the custom UDF function:
1. You can create persistent functions
two。 You can also compile it in the source code
This document is used in source code compilation. Here are the compilation steps
Download the source package
Wget http://archive.cloudera.com/cdh6/cdh/5/hive-1.1.0-cdh6.7.0-src.tar.gztar xf hive-1.1.0-cdh6.7.0-src.tar.gzcd hive-1.1.0-cdh6.7.0/
Enter the directory of the UDF code
Cd ql/src/java/org/apache/hadoop/hive/ql/udf/- We can see a lot of UDF code here, starting with UDFXXX.java
Put the UDF code in the directory above
HelloUDF.javapackage com.ruozedata.hadoop.udf;import org.apache.hadoop.hive.ql.exec.UDF;public class HelloUDF extends UDF {public String evaluate (String input) {/ / TODO... Here is the return "Hello:" + input;} / / the following is the test code public static void main (String [] args) {HelloUDF udf = new HelloUDF (); String output = udf.evaluate ("test data"); System.out.println (output);}}
Register a custom UDF function in the source code
Cd ql/src/java/org/apache/hadoop/hive/ql/exec/#vim FunctionRegistry.javaimport org.apache.hadoop.hive.ql.udf.HelloUDF
Add the following to line 176
System.registerUDF ("HelloUDF", HelloUDF.class,false)
Compile hive
[root@hadoop001 exec] # pwd/opt/sourcecode/hive-1.1.0-cdh6.7.0 [root@hadoop001 hive-1.1.0-cdh6.7.0] # mvn clean package-DskipTests-Phadoop-2-Pdist
The compiled file is:
1.packaging/target/apache-hive-1.1.0-cdh6.7.0-bin.tar.gz
2.. / lib/hive-exec-1.1.0-cdh6.7.0.jar
Mode of use
Method 1: redeploy apache-hive-1.1.0-cdh6.7.0-bin.tar.gz
Method 2: copy the compiled / lib/hive-exec-1.1.0-cdh6.7.0.jar to the ${HIVE_HOME} / lib/ directory