hive中自定义函数

1、需求:
需要对json数据表中的json数据写一个自定义函数,用于传入一个json,返回一个数据值的数组
json原始数据表:
hive中自定义函数
需要做ETL操作,将json数据变成普通表数据,插入另一个表中:
hive中自定义函数
2、实现步骤:
step1、开发java的UDF类,继承UDF类并且重载方法
public C evaluate(A a,B b);
hive中自定义函数
step2、打jar包
step3、上传jar包到运行hive所在的linux机器
hive中自定义函数
step4、将此jar包添加到hive环境中
3:jdbc:hive2://localhost:10000>add jar /root/hivetest/hive-1.0-SNAPSHOT.jarhive中自定义函数
step5、用命令去创建一个函数关联自定义的java类
3:jdbc:hive2://localhost:10000>create temporary function myjson as ''com.ll.hive.MyJsonParser";
hive中自定义函数
step6、使用自定义的函数
create table t_rate
as
select myjson(json,1) as movie,
myjson(json,2) as rate,
myjson(json,3) as tS,
myjson(json,4) as uid
from t_ratting;hive中自定义函数