有关Hive中的collect_list UDAF的更多信息: https://cwiki.apache.org/confluence/display/Hive/LanguageManual+UDF#LanguageManualUDF-Built-inAggregateFunctions(UDAF)
select
'a' as A
,collect_list(struct(table1.item1,table1.item2,table1.item3)) --Array
||struct(table2.item1,table2.item2,table2.item3) --Struct 1
||struct(table3.item1,table3.item2,table3.item3) --Struct 2
as B
from
table1
join
table2
on
table1.thing = table2.thing
join
table3
on
table1.thing = table3.thing
group by
'a'
,table2.item1
,table2.item2
,table2.item3
,table3.item1
,table3.item2
,table3.item3
Array: (returned from collect_list)
[{table1.item1,table1.item2,table1.item3} --structA
,{table1.item1,table1.item2,table1.item3}] --structB
Struct 1:
{table2.item1,table2.item2,table2.item3}
Struct 2:
{table3.item1,table3.item2,table3.item3}
Desired result:
A B
'a' [{table1.item1,table1.item2,table1.item3},{table1.item1,table1.item2,table1.item3},{table2.item1,table2.item2,table2.item3},{table3.item1,table3.item2,table3.item3}]
在上面的查询中,我使用字符串连接运算符作为我的“将函数”结构追加到将从collect_list返回的结构数组的函数。