美文网首页
HIVE常用数据处理函数

HIVE常用数据处理函数

作者: 小八_居然被占用了 | 来源:发表于2017-12-07 13:29 被阅读12次

    1.获取Map数据:

    【data['key']】

    select substr(a.url,-6) ,a.usertag,b.name,b.store_type,a.ds from (

    select data['url'] as url,usertag,ds from  dwd_datacenter_trackmodel where typeid ='TANGECHE_SCAN_OUT' and ds >'2017-07-15' )a

    left join  dwd_centralized_authshop b on substr(a.url,-6) = b.code

    where substr(a.url,-6)!='store='

    2.Hive中处理String数据方法

    【get_json_object(data,'$.key')】

    select get_json_object(a.ext,'$.car_city_name'),count(1),to_date(a.date_create) from  dwd_angelia_clue_add_history a

    where a.tag like '%tangeche%'

    and a.clue_category in

    ('tangeche_woyaozixun_clue','tangeche_yixiang_chexing_clue','tangeche_niming_clue','pcauto_buyer_clue','cheyibai_seller_clue','cheyibai_buyer_clue','chexiang_buyer_clue')

    and  a.store_id ='null'

    group by get_json_object(a.ext,'$.car_city_name'),to_date(a.date_create)

    参考文章:http://blog.csdn.net/qq_31573519/article/details/55104822

    3.Hive中处理url的函数:

    parse_url

    select x.name,x.ds,count(x.usertag),count(distinct x.usertag) from (

    select parse_url(regexp_replace(a.url,'#/',''),'QUERY','modelCode') as url_model,b.name as name ,a.usertag usertag ,a.ds ds from (

    SELECT data['url'] as url,usertag,ds from dwd_datacenter_trackmodel

    where typeid ='TANGECHEAPP_TAB_LIST_DETAIL' and ds >'2017-08-01')a

    left join  dim_dictionary_element b on   parse_url(regexp_replace(a.url,'#/',''),'QUERY','modelCode') = b.code)x

    group by x.name,x.ds

    4.Hive中处理字符串分割函数:spilt

    a.基本用法

    例1:

    split('a,b,c,d',',')

    得到的结果:

    ["a","b","c","d"]

    b.截取字符串中的某个值:

    当然,我们也可以指定取结果数组中的某一项

    例2:

    split('a,b,c,d',',')[0]

    得到的结果:

    a

    c.特殊字符的处理:

    特殊分割符号

    regex 为字符串匹配的参数,所以遇到特殊字符的时候需要做特殊的处理

    split('192.168.0.1','\\.')

    得到的结果:

    ["192","168","0","1"]

    需要注意的是

    当然当split包含在 "" 之中时 需要加4个\

    如 hive -e "....  split('192.168.0.1','\\\\.') ... "  不然得到的值是null

    同样的 | 等特殊符号也需要做类似 处理。

    split文档:http://blog.csdn.net/lxpbs8851/article/details/18712407

    url截取数据逻辑:http://blog.sina.com.cn/s/blog_6676d74d0102vtp9.html

    时间戳转化工具:http://tool.chinaz.com/Tools/unixtime.aspx

    相关文章

      网友评论

          本文标题:HIVE常用数据处理函数

          本文链接:https://www.haomeiwen.com/subject/mgydixtx.html