我有一张桌子。其中一列的类型为array<string>
。我尝试在此表上运行查询,然后将数据加载到文件中。
这是查询
Select concat(key, '|'
, code, '|'
, round(sum(amt), 4), '|'
, count(*)
, collect_set(comment))
from test_agg
where TIME_KEY = '2017-02-19'
group by key, code;
但是收到错误
FAILED: UDFArgumentTypeException Only primitive type arguments are accepted but array<string> was passed as parameter 1.
我知道我无法传递函数array<string>
,但我该怎么做?
comment
是array<string>
这就是我运行它的方式。
hive -f CALC_FILE.sql > 20170220.txt
答案 0 :(得分:2)
使用concat_ws
将comment
数组转换为字符串,连接collect_set
结果,然后将其连接到其余列
select concat_ws
(
'|'
,key
,code
,round(sum(amt),4)
,count(*)
,concat_ws('<<<>>>',collect_set(ws_concat('~~~',comment)))
)
from test_agg
where time_key = '2017-02-19'
group by key
,code
;