Github Project : Impala-UDF
Impala get many functions but sometime you must make your own function. An UDF is an User Define Function.
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 including dependencies in HDFS.
Impala
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';
Comments
0 comments
Article is closed for comments.