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

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

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

  1. CREATE TABLE if not exists tbl1
  2. (
  3. sess_id STRING
  4. , source_start_ts STRING
  5. , source_end_ts STRING
  6. ,Node_String STRUCT < Node: STRING, Time_Spent:STRING,
  7. Txn_Type: STRING, Txn_Status: STRING, Call_Status: STRING >
  8. )
  9. STORED AS ORC

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

  1. CREATE TABLE if not exists tbl2
  2. (
  3. sess_id STRING
  4. ,Col2 Array<STRUCT < Node: STRING,
  5. Time_Spent:STRING, Txn_Type: STRING, Txn_Status: STRING,
  6. Call_Status: STRING >>
  7. ) STORED AS ORC

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

  1. insert into table tbl2
  2. select sess_id
  3. , collect_set(Node_String) as Col2
  4. from tbl1
  5. where sess_id = 'abc'
  6. group by sess_id

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

  1. id, source_start_dt, source_end_dt, Node_string
  2. 1,'2019-01-01','2019-01-02' , {"node1","10s","activation", "123", "failed"}
  3. 1,'2019-01-01','2019-01-02', {"node2","120s","activation", "123", "Logged"}
  4. 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。看看这个答案。

相关问题