在配置单元中使用数组和集合

时间:2017-02-20 14:12:31

标签: sql hive hiveql

我有一张桌子。其中一列的类型为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>,但我该怎么做?

commentarray<string>

类型的列

这就是我运行它的方式。

hive -f CALC_FILE.sql > 20170220.txt

1 个答案:

答案 0 :(得分:2)

使用concat_wscomment数组转换为字符串,连接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
;