我想从公共BigQuery github_repos从以下两个记录中选择数据集中的所有内容:author.name 和 6 l% I% v) Q8 {: C9 B" ? ~difference.old_mode。基于我问过的类似问题,我想我想运行类似的问题! h" f- k, y1 m& |
#standardSQLSELECT * REPLACE ((SELECT AS STRUCT author.* EXCEPT (name)) AS author),REPLACE ((SELECT AS STRUCT difference.* EXCEPT (old_mode)) AS difference)FROM `bigquery-public-data.github_repos.commits`LIMIT 1000;如果我排除作者,效果很好:' m7 k" D+ J0 o+ l% O
#standardSQLSELECT * REPLACE ((SELECT AS STRUCT author.* EXCEPT (name)) AS author)FROM `bigquery-public-data.github_repos.commits`LIMIT 1000;然而,排除差异有一个错误:$ i! v( U, }4 z3 i# c2 p
#standardSQLSELECT * REPLACE ((SELECT AS STRUCT difference.* EXCEPT (old_mode)) AS difference)FROM `bigquery-public-data.github_repos.commits`LIMIT 1000;错误: % X# v; @8 h: |0 h/ n5 qDot-star is not supported for type ARRAY> at [2:41]谢谢你。 8 O3 t6 ^4 b# f+ `2 e , o# q: a; W' j$ O 解决方案: 2 k# I0 V. b& g( }( a$ e/ D 作为一个独立的例子,请考虑以下查询:1 F% L' t9 o2 m8 l
WITH T AS ( SELECT 10 AS a,ARRAY>(1)foo',true)] AS arr UNION ALL SELECT 11,ARRAY>(2)bar',false),(3,'baz',true)])SELECT * FROM T;它返回atypeINT64的列arr和type的列ARRAY>。如果要返回arr省略数组内部结构位置的修改y可以使用SELECT * REPLACEand的组合SELECT *EXCEPT:" W9 ^+ ?: a! B7 n* h1 a
WITH T AS ( SELECT 10 AS a,ARRAY>(1)foo',true)] AS arr UNION ALL SELECT 11,ARRAY>(2)bar',false),(3,'baz',true)])SELECT * REPLACE(ARRAY(SELECT AS STRUCT * EXCEPT (y) FROM UNNEST(arr)) AS arr)FROM T;这个想法是用新数组代替原始数组,然后我们使用和ARRAY子查询,SELECT AS STRUCT并使用*EXCEPT不包括字段struct重构这个数组的元素y。; M/ g3 @) ^/ r" z2 o/ V, R
回到问题中的查询,您可以应用相同的想法difference和old_mode: $ b7 |% b' h+ m; ?. [0 l: O" XSELECT * REPLACE ( ARRAY(SELECT AS STRUCT * EXCEPT (old_mode) FROM UNNEST(difference)) AS difference)FROM `bigquery-public-data.github_repos.commits`LIMIT 1000;包括一个查询结果difference其结构不包括数组old_mode字段。