[root@localhost hive-udf]$ export JAVA_HOME=/usr/java/jdk1.7.0_67-cloudera/ [root@localhost hive-udf]$ export PATH=$PATH:$JAVA_HOME/bin [root@localhost hive-udf]$ javac -cp `hadoop classpath`:"/opt/cloudera/parcels/CDH/lib/hive/lib/*" GenericUDFCurrentUser.java [root@localhost hive-udf]$ ls GenericUDFCurrentUser.class GenericUDFCurrentUser.java [root@localhost hive-udf]$ mkdir -p com/elin [root@localhost hive-udf]$ mv GenericUDFCurrentUser.class com/elin [root@localhost hive-udf]$ jar cvf elin-udf.jar com added manifest adding: com/(in = 0) (out= 0)(stored 0%) adding: com/elin/(in = 0) (out= 0)(stored 0%) adding: com/elin/GenericUDFCurrentUser.class(in = 2505) (out= 1145)(deflated 54%)Then I could access the UDF in Hive
ADD JAR /user/ericlin/hive-udf/elin-udf.jar; CREATE TEMPORARY FUNCTION get_user AS com.elin.GenericUDFCurrentUser'; SELECT get_user() from test;It is so simple without the need of any third party thingy.
Related articles