1. User Defined Function (UDF) in Hive using Java.
2. Download hive-0.4.1.jar and add it to lib-> Buil Path -> Add jar to libraries
3. Q:Find the Cube of number passed:
import org.apache.hadoop.hive.ql.exec.UDF;
public class Cube extends UDF{
public int evaluate (int number)
{
return number*number*number;
}
}
4. Create jar file and copy to HDFS
terminal > sudo hadoop fs -put /home/cloudera/Desktop/Cube.jar /user/cloudera/
5. ADD JAR EXPORTED_FILE_NAME.jar;
hive> ADD JAR hdfs://quickstart.cloudera:8020/user/cloudera/Cube.jar;
6. hive> list jars;
7. Create Temperory function:
CREATE temporary function func_name as ‘absolute_class_name’.
hive> CREATE temporary function Cube as ‘Cube’;
8. hive> select Cube(marks) from student;
9. Create Permenent Function:
hive> CREATE function Cube as ‘Cube’ using jar ‘hdfs://quickstart.cloudera:8020/user/cloudera/Cube.jar’;
10. hive> select Cube(marks) from student;