在Hive中添加函数

添加永久函数         

    1)在hive客户端机的安装目录下修改hive-env.sh中的:export HIVE_AUX_JARS_PATH=“hive udf jar目录”

    2)在安装目录下添加hive-function.properties文件

           文件内容为函数名与类名的映射关系           

domain=*.hive.udf.UDFDomain
decoder_url=org.apache.hadoop.hive.ql.udf.UDFDecoderUrl
makeself=*.hive.udf.IsMakeSelf
   启动hive命令,show fuctions即可验证是否添加成功。

添加临时函数

add jar $local_path/hive_ip_gap.jar;
create temporary function ip2city as 
        '*.tv.ad.hiveudf.Ip2City';
create temporary function sign2city as 
        '*.tv.ad.hiveudf.Sign2City';
create temporary function sign2ip as 
        '*.tv.ad.hiveudf.Sign2Ip';
select 
      dt,sign2ip(sign),sign2city(sign)
from pvlog where dt=$curDate and p='oad1' 
      and sign2city(sign) in($citys) 
      and ip2city(ip)!=sign2city(sign)
group by dt,sign2ip(sign),sign2city(sign)

你可能感兴趣的:(在Hive中添加函数)