【发布时间】:2021-12-27 10:35:57
【问题描述】:
我有一个带有 json 列的配置单元表。是orc格式,只有一列有json字符串。
- json_column
{
"type":"REGULAR",
"period":[
"ONCE_PER_FOUR_WEEK",
"ONCE_PER_SIX_WEEK",
"ONCE_PER_ONE_MONTH",
"ONCE_PER_TWO_MONTH",
"ONCE_PER_THREE_MONTH"
],
"count":[
"4",
"8",
"12"
],
"day":[
"SATURDAY",
"SUNDAY"
],
"content":[
{
"count":"2",
"value":5,
"unit":"PERCENT"
},
{
"count":"3",
"value":10,
"unit":"PERCENT"
}
]
}
我想将此栏分为五栏。
type string,
period array<string>,
count array<string>,
day array<string>,
content array<struct<count :string, value :int, unit :string>>
首先,我用json_tuple将此栏分为四栏。
SELECT b.type as type,
b.period as period,
b.count as count,
b.deliveryImpossibleDay as day,
b.content as content
FROM sample_table a
LATERAL VIEW JSON_TUPLE(a.content, 'type', 'period', 'count', 'day',
'content') b
AS type, period, count, day, content
我需要将content 列更改为结构数组,但如果返回字符串值。
[{"count":"2","value":5,"unit":"PERCENT"},{"count":"3","value":10,"unit":"PERCENT"}]
如何将其从 string 转换为 array<struct<count :string, value :int, unit :string>>?
有什么想法吗?
【问题讨论】:
标签: sql arrays json hive hiveql