I have a hive table with json column. It's orc format and only one column has a json string.
- 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"
}
]
}
I'd like to divide this column to five columns.
type string,
period array<string>,
count array<string>,
day array<string>,
content array<struct<count :string, value :int, unit :string>>
First, I divided this column to four columns with 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
And I need to change content column to struct array but if returns string value.
[{"count":"2","value":5,"unit":"PERCENT"},{"count":"3","value":10,"unit":"PERCENT"}]
How can I convert it from string to array<struct<count :string, value :int, unit :string>>?
Any ideas, please?