<!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-common -->
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.6.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.hive/hive-exec -->
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>1.1.0</version>
</dependency>
package com.njbdqn;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;
public class MyFunc extends UDF {
public Text evaluate(Text txt){
return new Text("Hello,"+txt.toString());
}
}
将包上传hdfs:
hdfs dfs -mkdir -p /func
hdfs dfs -put /opt/jar/myfun-1.0-SNAPSHOT.jar /func
hive> add jar hdfs://192.168.56.100:9000/func/myfun-1.0-SNAPSHOT.jar;
create function mytest as "com.njbdqn.MyFunc";
hive> select mytest(username) from userinfos limit 3;
OK
Hello,lhqye
Hello,gaqhq
Hello,thfqn
Time taken: 0.305 seconds, Fetched: 3 row(s)
hive> select username from userinfos limit 3;
OK
lhqye
gaqhq
thfqn
Time taken: 0.096 seconds, Fetched: 3 row(s)
免责申明:
本文系转载,版权归原作者所有,如若侵权请联系我们进行删除!
《数据治理行业实践白皮书》下载地址:https://fs80.cn/4w2atu
《数栈V6.0产品白皮书》下载地址:https://fs80.cn/cw0iw1
想了解或咨询更多有关袋鼠云大数据产品、行业解决方案、客户案例的朋友,浏览袋鼠云官网:https://www.dtstack.com/?src=bbs
同时,欢迎对大数据开源项目有兴趣的同学加入「袋鼠云开源框架钉钉技术群」,交流最新开源技术信息,群号码:30537511,项目地址:https://github.com/DTStack