You have already understood the in-built functions in the SQL module. Hive also supports a variety of in-built functions. Along with the in-built functions, Hive also supports a dynamic feature of user-defined functions(UDF).
Hive allows you to custom functions to process records and groups of records. In many industries, it is necessary to do various jobs using UDFs which are highly extensible than already existing functions.
Let’s listen to Vishwa to understand how you can create the UDFs in Hive.
So, in order to create user-defined functions, you have to follow these steps:
- Create a Java program.
- Save the Java file as ‘jar’ file.
- Add the ‘jar’ file into Hive.
- Create a function of the ‘jar’ file added.
- Use those functions in the Hive query.
Let’s understand these steps through a demonstration by watching the video.
As you saw in the video, Vishwa created a Java program to return the absolute value of any integer. Note that you should not worry about the java program here. You should focus on the steps that are being followed after the Java program has been created.
- Once you have your Java program ready, you need to export it as a ‘jar’ file.
- Now, you need to bring the ‘jar’ file in Hive and add it. You can add the jar file using the following command: add jar /home/hadoop/udfDemo.jar ;
- Once the jar file has been added, you have to create a function and use it for querying.
This is how you create your own functions and apply them in your queries.
Please take reference from below files for creating UDFs.
Report an error