gpt4 book ai didi

hadoop - Hive中的数据解析

转载 作者:行者123 更新时间:2023-12-02 22:06:45 24 4
gpt4 key购买 nike

我有类似的数据

state:us,gallery:45,fin:UN,mode:normal,rate:3346 

作为配置单元表之一中的字符串数据类型。我想提取数据像
state gallery fin mode    rate
------------------------------
us 45 UN normal 3346

作为目标表的行。我如何使用 hive 做到这一点

需要一个通用的方法来代替逗号,有时#可能会来
那是
状态?我们的图库?45#fin?UN#mode?normal#rate?3346

最佳答案

with t as (select 'state:us,gallery:45,fin:UN,mode:normal,rate:3346' as mycol)

select mycol_map['state'] as state
,mycol_map['gallery'] as gallery
,mycol_map['fin'] as fin
,mycol_map['mode'] as mode
,mycol_map['rate'] as rate

from (select str_to_map(mycol) as mycol_map
from t
) t
+-------+---------+-----+--------+------+
| state | gallery | fin | mode | rate |
+-------+---------+-----+--------+------+
| us | 45 | UN | normal | 3346 |
+-------+---------+-----+--------+------+

关于hadoop - Hive中的数据解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43594035/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com