import org.apache.hadoop.hive.ql.exec.UDF;
public class helloUDF extends UDF {
public String evaluate(String str) {
try {
return "HelloWorld " + str;
} catch (Exception e) {
return null;
}
}
}
hive> create temporary function helloworld as 'com.hrj.hive.udf.helloUDF';
hive> select helloworld(t.col1) from t limit 10;
hive> drop temporary function helloworld;
- helloworld爲臨時的函數,所以每次進入hive都需要add jar以及create temporary操作
- UDF只能實現一進一出的操作,如果需要實現多進一出,則需要實現UDAF