hive自定义函数udf,hiveserver2的使用

先在idea中编写自定义函数,继承udf类,实现execut,打包程序。

在hive的shell中,添加jar包---add jar /opt/hive/xxx.jar

注册函数:create temporary function xxx  as “com.bigdata.hive.udf.xxxUDF” ;

使用show functions;可以查看所有的函数。

hive最新可以直接使用指令创建自定义函数:

create function xxx as “com.bigdata.hive.udf.xxxUDF” using jar ‘hdfs:///warehouse/user/hive/xxx.jar’

jar包需要放在hdfs上。

使用beeline模式:

在hiveServer2开启的情况下,进入bin目录,开启beeline---./beeline;

链接数据库:

!connect jdbc:hive2://name2:10000 hive

hostname填写hiveserver2的地址

用户名默认为hive,密码为空。

压缩格式(保存为orc格式,同时用snappy压缩):

stored as orc tblproperties("orc.compress"="SNAPPY")

hive的transform的使用:

针对直接在hive的shell操作的,也可以不用写UDF,可以通过transform算子实现运行脚本来进行函数运算。

1.编写Python脚本:

import sys
import datetime
for line in sys.stdin:
    value=line.split('\001')
    for word in value:
        print (word.upper())//将字段都转为小写

2.进入hive的shell后,添加脚本文件:

add file /root/hive/lower.py

3.调用transform算子做预算出来:

select transform(ykd018) using 'python lower.py' 

猜你喜欢

转载自my.oschina.net/shea1992/blog/1620477
今日推荐