【发布时间】:2017-04-22 06:26:37
【问题描述】:
我试图在我的查询中连接两个结构数组并不断收到签名错误。这两个结构是相同的(结构中的字段在类型和数量上匹配)。
select order_id, case when h.filled is not null and rf.new is not null then array_concat( h.filled, rf.new) else null end filled_and_new from....
它给出了错误:
Error: No matching signature for function ARRAY_CONCAT for argument types: ARRAY<STRUCT<r_id STRING, s_id STRING, b_id STRING, ...>>, ARRAY<STRUCT<r_id STRING, s_id STRING, b_id STRING, ...>>. Supported signature: ARRAY_CONCAT(ARRAY, [ARRAY, ...]) at [10:18]
是不是说array_concat不能合并两个Structs数组(布局完全相同)?
谢谢
以下是两个数组的定义:
reservations_filled RECORD REPEATED
reservations_filled.reservation_id STRING NULLABLE
reservations_filled.s1_order_id STRING NULLABLE
reservations_filled.s2_order_id STRING NULLABLE
reservations_filled.amount INTEGER NULLABLE
reservations_filled.created_time TIMESTAMP NULLABLE
reservations_filled.updated_time TIMESTAMP NULLABLE
reservations_filled.state STRING NULLABLE
reservations_filled.rate FLOAT NULLABLE
reservations_filled.u_amount INTEGER NULLABLE
reservations_filled.u_fees INTEGER NULLABLE
以及连接表中的数组:
rsrvtn_array RECORD REPEATED
rsrvtn_array.reservation_id STRING NULLABLE
rsrvtn_array.s1_order_id STRING NULLABLE
rsrvtn_array.s2_order_id STRING NULLABLE
rsrvtn_array.amount INTEGER NULLABLE
rsrvtn_array.created TIMESTAMP NULLABLE
rsrvtn_array.updated TIMESTAMP NULLABLE
rsrvtn_array.state STRING NULLABLE
rsrvtn_array.rate FLOAT NULLABLE
rsrvtn_array.u_amount INTEGER NULLABLE
rsrvtn_array.u_fees INTEGER NULLABLE
查询是:
select t1.rsrvtn_array a, t2.reservations_filled b , array_concat(t1.rsrvtn_array, t2.reservations_filled) c from temp.new_orders t1 join temp.order_history t2 on using(order_id)
【问题讨论】:
-
在 UI 中查看表的架构,因为 STRUCT 中的字段必须不同。错误消息会截断类型名称以避免过于冗长。在您的问题中包含两个 STRUCT 的字段会很有帮助。
标签: google-bigquery