我想创造一个 array<struct>
类型。我的代码似乎返回了我想要的,但是当我打开json文件时,数组只包含1个struct。
select idCol,
collect_list(
named_struct("name", "apple", "amount", named_struct("value", apple_amount, "currency", currency),
"name", "orange", "amount", named_struct("value", orange_amount, "currency", currency),
"name", "banana", "amount", named_struct("value", banana_amount, "currency", currency))) as categories
from (
select
1 as idCol,
'usd' as currency,
20 as apple_amount,
30 as orange_amount,
40 as banana_amount)
group by 1
退货
{
"idCol": 1,
"categories": [
{
"name": "apple",
"amount": {
"value": 20,
"currency": "usd"
},
"name": "orange",
"amount": {
"value": 30,
"currency": "usd"
},
"name": "banana",
"amount": {
"value": 40,
"currency": "usd"
}
}
]
}
我怎样才能让它变成这样?
{
"idCol": 1,
"categories": [
{
"name": "apple",
"amount": {
"value": 20,
"currency": "usd"
}
},
{
"name": "orange",
"amount": {
"value": 30,
"currency": "usd"
}
},
{
"name": "banana",
"amount": {
"value": 40,
"currency": "usd"
}
}
]
}
1条答案
按热度按时间lf5gs5x21#
我应该有一个狭隘的问题。