Hive UDF、UDAF、UDTF使用

1. 目录

[TOC]

2. UDF

注:UDF只能实现一进一出的操作,如果需要实现多进一出,则需要实现UDAF

3. UDAF

4. UDTF

5. 使用方法

以UDF的HelloUDF为例将该java文件编译成HelloUDF.jar

5.1. 临时函数

1、在hive shell里面添加临时Jar
add jar /home/zhaomin/HelloUDF.jar;
2、创建临时函数,指定路径
create temporary function helloworld as 'cn.com.edata.udf.HelloUDF';
3、测试
select helloworld(name) from t limit 10;
4、删除临时函数
drop temporary function helloworld;
5、删除临时Jar
deleteres jar /home/zhaomin/HelloUDF.jar;

永久函数

a)自定义UDF需要继承org.apache.hadoop.hive.ql.UDF。(注意该类的包名必须是org.apache.hadoop.hive.ql.udf)
b)需要实现evaluate函数,evaluate函数支持重载。
c)修改FunctionRegistry这个类,注册定义的udf
d) 把udf函数编译成class放到hive-exec-0.12.0-cdh5.0.0.jar中org\apache\hadoop\hive\ql\udf 路径下面
g) 将新的FunctionRegistry编译后的class文件替换hive-exec-0.12.0-cdh5.0.0.jar中的org.apache.hadoop.hive.ql.exec

原创文章,转载请注明: 转载自LoserZhao – 诗和远方[ http://www.loserzhao.com/ ]

本文链接地址: http://www.loserzhao.com/bigdata/hive-udf%e3%80%81udaf%e3%80%81udtf.html

文章的脚注信息由WordPress的wp-posturl插件自动生成

发表评论?

0 条评论。

发表评论


注意 - 你可以用以下 HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

使用新浪微博登陆