(注:hive的相关学习视频慕课网https://www.imooc.com/learn/387 和https://www.imooc.com/video/8030,hadoop的相关学习视频https://www.imooc.com/learn/391和 https://www.imooc.com/learn/890
1.编写类继承UDF类(需要导入hive的相关jar包)
2.重写evaluate()方法
package demo.udf;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;
public class ConcatString extends UDF {
public Text evaluate(Text a, Text b) {
return new Text(a.toString() + "****" + b.toString());
}
}
3.将上述代码生成jar包
4.将jar包上传至hive (需开启hadoop服务,开启hive --service metastore服务,开启hive服务)
add jar /D:/workspace/hiveDemo/out/artifacts/ConcatString/ConcatString.jar;

5.创建临时函数
create temporary function myconcat as ‘demo.udf.ConcatString’;
6.使用该函数
select myconcat(‘hello’,‘world’);

327

被折叠的 条评论
为什么被折叠?



