其他分享
首页 > 其他分享> > trino / presto 列转行 取JSON

trino / presto 列转行 取JSON

作者:互联网


select
    id
    ,json_extract_scalar(json_item,'$.user_id') as user_id
    ,json_extract_scalar(json_item,'$.url')     as user_id
from (
    select
         A.id
        ,concat('{',replace(replace(B.json,'[{',''),'}]',''),'}') as json_item
    FROM (
        select
             t1.id
            ,t1.image_file
        from ods_zj_q_closed_water_test_photo_requirement t1
        where db_name in ('db_name')
        limit 2
    ) A
    cross join unnest(split(image_file, '},{')) as B(json)
) t1
;

select
     A.id
    ,try_cast(B.json as int) as json_item
FROM (
    select
         t1.id
        ,t1.str
    from (select 1 as id,'aa,1,2,cc,5' as str ) t1
) A
cross join unnest(split(str, ',')) as B(json)
;

select
     A.id
    ,max(cast(regexp_replace(B.json,'\D','0') as int)) as json_item
FROM (
    select
         t1.id
        ,t1.str
    from (select 1 as id,'aa,1,2,cc,5' as str ) t1
) A
cross join unnest(split(str, ',')) as B(json)
group by a.id
;

标签:presto,json,t1,item,JSON,str,id,select,trino
来源: https://www.cnblogs.com/chenzechao/p/16512926.html