Hive json 转array

工作中在进行Hive查询拼接URL时,遇到JSON串里有uri集合的情况,为解决此问题研究并写出了一个builder。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

工作的时候遇到hive 查询拼接url的情况,发现json串里有个uri的集合,这个就麻烦了,研究一下,写出了一个builder,如下:

url_builder as (
    select
        item_id,
        collect_set(
            concat(
                'http://www.google.com/',
                get_json_object(image_list, '$.uri'),
                '~args'
            )
        ) as image_urls
    from
        (
            select
                item_id,
                split(
                    regexp_replace(
                        concat(
                            '{',
                            regexp_extract(
                                image_list,
                                '[^\\[](.+)[^\\]]'
                            ),
                            '}'
                        ),
                        '\\}\\,\\{',
                        '\\}\\|\\|\\{'
                    ),
                    '\\|\\|'
                ) as image_array
            from
                item_table
        ) as test LATERAL VIEW explode(image_array) Ttable as image_list
    group by
        item_id
)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值