一.临时添加UDF函数
1.上传jar包至hive服务器
2.hive shell执行如下命令:
1
2
3
4
5
6
|
add jar /home/hive/hivejar/billing-on-hive-1.0.jar
create temporary function strip as 'com.tsingzone.bigdata.billing.GetOperator';
注:
strip:自定义函数名
com.tsingzone.bigdata.billing.GetOperator:类名
仅对当前shell生效
|
3.使用方法:
1
|
select
strip(dest_termi_id)
from
huadan201601 limit 10;
|
二.永久添加UDF函数
1.上传jar包至hdfs中
1
|
hdfs dfs -put hivejar/billing-
on
-hive-1.0.jar /
user
/hive/hive_jar
|
2.创建函数
1
|
create
function
billing
as
'com.tsingzone.bigdata.billing.GetOperator'
using jar
'hdfs:///user/hive/hive_jar/billing-on-hive-1.0.jar'
|
3.使用
1
|
hive -S -e
"select billing(dest_termi_id) from huadan201601 limit 10;"
|
参考文档:http://blog.csdn.net/liam08/article/details/51311772
本文转自 穿越防火墙 51CTO博客,原文链接:http://blog.51cto.com/sjitwant/1932990