在 BQ 中嵌套 table 时如何避免数组 uf NULLS

How to avoid an array uf NULLS when making nested table in BQ

我正在加入 2 tables,连接在左边,第二个 table 没有第一个的所有键,所以它在右边产生 NULL。将其分组到数组中时如何避免它们?

例如:

with 
  t1 AS (select 1 AS c1, 2 AS c2 UNION ALL select 5, 6),
  t2 AS (select 3 AS c1, 4 AS c4 UNION ALL select 3, 5, UNION ALL select 3,4, UNION ALL select 5,6)
SELECT t2.c1, ARRAY_AGG(DISTINCT t2.c4), ARRAY_AGG((SELECT AS STRUCT t1.*))
FROM t2 LEFT JOIN t1 ON t1.c1=t2.c1
GROUP BY t2.c1

结果是:

我期望的是第一行第二行只有一行 NULL table,类似(抱歉画得不好):

是否可以删除所有空语句?

然后在 array_agg

中使用 if 语句
with 
  t1 AS (select 1 AS c1, 2 AS c2 UNION ALL select 5, 6),
  t2 AS (select 3 AS c1, 4 AS c4 UNION ALL select 3, 5, UNION ALL select 3,4, UNION ALL select 5,6)
SELECT t2.c1, ARRAY_AGG(DISTINCT t2.c4), ARRAY_AGG( if(t1.c1 is null   , null, STRUCT(t1) ) ignore nulls  ), 
FROM t2 LEFT JOIN 
t1 
 ON t1.c1=t2.c1

GROUP BY t2.c1