Creating custom User-Defined Functions (UDF)

Built-in functions in Hive sometimes do not fit the requirements of a business use case or when data analytics required some custom manipulation of data based on certain conditions. For such cases, the user needs to define custom logic as a UDF and run it over the data.

How to do it…

For writing a custom function in Hive, you will have to extend a Hive class: org.apache.hadoop.hive.ql.exec.UDF.

Let's understand the concept of creating a custom UDF with the example of creating a function to reverse a string.

The following are the steps to create a custom UDF:

  1. Create a new Java project using any IDE, such as Eclipse. Give this any name; let's say "HiveUDF".
  2. When writing a custom UDF, there should be two libraries ...

Get Apache Hive Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.