第一步:在Elipse中建立函数,继承UDF(User Defined Function),重写evaluate函数,此函数支持重载
package com.demon;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;
public class ContactString extends UDF {
public Text evaluate(Text a,Text b){
return new Text(a.toString() + "****" + b.toString());
}
}
第二步:打成jar包:ContactString.jar
第三步:添加jar包
打开hive 的cli模式:
hive > add jar /usr/local/ContactString.jar;
第四步:使用函数
创建临时函数(周期仅限于当前会话)
hive > create temporary function myconcat as 'com.demon.ContactString';
使用函数
select myconcat('hello','world');