hive Hive User Defined Functions (UDF's) Hive UDF creation


Example

To create a UDF, we need to extend UDF (org.apache.hadoop.hive.ql.exec.UDF) class and implement evaluate method.

Once UDF is complied and JAR is build, we need to add jar to hive context to create a temporary/permanent function.

import org.apache.hadoop.hive.ql.exec.UDF;    

class UDFExample extends UDF {
  
  public String evaluate(String input) {
    
    return new String("Hello " + input);
  }
}

hive> ADD JAR <JAR NAME>.jar;
hive> CREATE TEMPORARY FUNCTION helloworld as 'package.name.UDFExample';
hive> select helloworld(name) from test;