dataworks----解析json数据格式


select 
    a._id,
    b.*
    from (
    SELECT 
        _id,
        a.coupon_detail_list
    FROM ikunchi_bi.src_thirdhub_tradesold_jingdong_normal 
    LATERAL VIEW 
    explode(
            split(
                regexp_replace(
                    regexp_extract(
                        get_json_object(trade, '$.trade.couponDetailList') -- 获取data数组,格式[{json},{json}]
                        ,'^\\[(.*?)\\]$'
                        ,1
                    ) -- 删除字符串前后的[],格式{json},{json}
                    ,'\\},\\{'
                    , '}||{'
                    , 0
                ) -- 将josn字符串中的分隔符代换成||,格式{json}||{json}
                ,'\\|\\|'
            )  -- 按||分隔符切割成一个hive数组
        ) a as coupon_detail_list
    )a
lateral view 
    json_tuple(a.coupon_detail_list, 
    'couponPrice',
    'couponType',
    'orderId',
    'skuId'
    
    )b AS 

    coupon_price       --优惠金额
    ,coupon_type        --优惠类型
    ,order_id           --订单编号
    ,sku_id             --京东sku编号
;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM