Professional Documents
Culture Documents
Hive User Defined Functions: Step 1: Code
Hive User Defined Functions: Step 1: Code
com
Step 1: Code
Example 1: Lower.java
Class Name
Package
:Lower.java
:com.zinnia.UDF
Right click on the project and click on Export->JAR file and select the Lower.java
JAR file:/home/hadoop/hadoop-0.20.2/hive-0.7.1-bin/Lower.jar
click on Finish
nagarjuna@outlook.com
nagarjuna@outlook.com
carry out the same steps of JAR creation and deploying to the Hive classpath.
Create a temporary function upper with command usage of
create temporary function upper as com.zinnia.UDF.Upper
Query the test1 table as below:
select upper(value) from test1 group by upper(value);
Output would be:
NAME1
NAME2
NAME3
NAME4
NAME5
nagarjuna@outlook.com
Example 3: LengthUDF.java
Steps mentioned for the above examples are carried out in a similar way for this and we can get the
length of the string.
nagarjuna@outlook.com
import com.zinnia.UDF.Upper;
Then add the following code after registerUDF("e", UDFE.class, false); line in the file
registerUDF("upper", Upper.class, false);
Step 5 : Compile the code
$cd /home/hadoop/hive-code/ql
$ant
Step 6 : Copy latest code into hive distribution
$cp /home/hadoop/hive-code/build/ql/
$HIVE_HOME/lib