Java - Create an Impala UDF

Github Project : Impala-UDF

Subject

Impala get many functions but sometime you must make your own function.

An UDF is an User Define Function.

Common part

Maven Dependencies

<dependency>
  <groupId>org.apache.hive</groupId>
  <artifactId>hive-exec</artifactId>
  <version>1.1.0</version>
</dependency>

Java code

import org.apache.hadoop.hive.ql.exec.UDF;
/**
 * This class returns the hashcode for an input string.
 */
public class Ascii  extends UDF {
    public Ascii(){
    }
    public int evaluate(String str /** Parameter(s) of the function **/ ) {
        /** Your code here **/
        return str.hashCode();
    }
}

Hdfs

Copy the .jar file with dependancies in your HDFS.

Impala code

Impala function
DROP FUNCTION IF EXISTS MyFunction(STRING);
CREATE FUNCTION IF NOT EXISTS MyFunction(String) RETURNS INT LOCATION 'hdfs:///user/hdfs/UDF/hive-udf-samples-1.0-jar-with-dependencies.jar' SYMBOL='Ascii';