huangjiyong
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编号
;

 

分类:

技术点:

相关文章: