如何使用 hive建立自己的函数在CLI界面上并使用

来源:互联网 发布:ubuntu pyqt5 安装 编辑:程序博客网 时间:2024/05/16 16:08

第一步:在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');





阅读全文
0 0