如何在配置单元的结构数组中插入数据

inb24sb2  于 2021-06-27  发布在  Hive
关注(0)|答案(1)|浏览(355)

我需要在配置单元中创建一个struct数组,以便对于一个id,我可以在struct数组中放置多个struct。
我在下表中创建了

CREATE TABLE if not exists tbl1
(
sess_id STRING
, source_start_ts STRING
, source_end_ts STRING
,Node_String STRUCT < Node: STRING, Time_Spent:STRING, 
Txn_Type: STRING, Txn_Status: STRING, Call_Status: STRING >
)
 STORED AS ORC

然后创建了第二个表,上面有一个struct数组(我可以在第一个表上有一个struct数组,但是我也尝试了,但是失败了)

CREATE TABLE if not exists tbl2
(
 sess_id STRING
,Col2 Array<STRUCT < Node: STRING, 
Time_Spent:STRING, Txn_Type: STRING, Txn_Status: STRING, 
Call_Status: STRING >>
) STORED AS ORC

但是,当使用below collect\u set填充它时,我得到一个错误

insert into table tbl2
select sess_id
, collect_set(Node_String) as Col2
from tbl1
where sess_id = 'abc'
group by sess_id

这是错误
sql错误[40000][42000]:编译语句时出错:失败:udfargumenttypeexception仅接受基元类型参数,但结构作为参数1传递。
我猜collect\u set不接受结构类型。有什么功能可以做到这一点吗?
下面是一个例子

id, source_start_dt, source_end_dt, Node_string
1,'2019-01-01','2019-01-02' , {"node1","10s","activation", "123", "failed"}
1,'2019-01-01','2019-01-02', {"node2","120s","activation", "123", "Logged"}
1,'2019-01-01','2019-01-02', {"node3","450s","activation", "123", "completed"}

正如您在上面看到的,有多个节点\u字符串,每个id有不同的结构字段。id“1”有3行,为了将这三行汇总到一行中,我使用了collect \u set
谢谢

nnvyjq4y

nnvyjq4y1#

据我所知,brickhouse的collectudaf可以处理原始类型和复杂类型,比如structs。看看这个答案。

相关问题