BigQuery错误:无法在重复字段

时间:2015-05-26 18:29:42

标签: google-bigquery

我有两个表table1(复杂的表有重复/记录列)和table2(非常简单)。我正在尝试使用以下查询创建一个包含table1中所有列和table2中的一列的新表:

select t1.id, t1.experience.desc, t1.experience.organization.*, t1.experience.department, t2.field2 as t1.experience.organization.newfield, t1.family_name
from [so_public.table1] as t1 left join each [so_public.table2] as t2
on t1.experience.organization.name = t2.field1

我收到错误无法在重复字段上进行分区,如下图所示。两个表的模式也显示在它们各自的图像中。

当想要合并两个表中的数据时,这里有一般的经验法则吗?我想尽力做什么?

实际的表格要复杂得多。我只展示了足以重现问题的背景。

Query with error Table1 schema Table2 schema

2 个答案:

答案 0 :(得分:6)

在加入桌子之前,你需要FLATTEN()。

这不起作用:

SELECT a.fullName, b.fullname
FROM [bigquery-samples:nested.persons_living] a
JOIN [bigquery-samples:nested.persons_living] b
ON a.citiesLived.place=b.citiesLived.place
LIMIT 1000

Error: Cannot join on repeated field citiesLived.place

这样做:

SELECT a.fullName, b.fullname
FROM FLATTEN([bigquery-samples:nested.persons_living], citiesLived) a
JOIN FLATTEN([bigquery-samples:nested.persons_living], citiesLived) b
ON a.citiesLived.place=b.citiesLived.place
LIMIT 1000

答案 1 :(得分:1)

使用您在编辑时发布的公开示例,一个有效的查询:

select t1.id, t1.experience.desc, t1.experience.department, t1.experience.organization.*, t2.field2 as t1.experience.organization.newfield, t1.family_name
from FLATTEN(FLATTEN([earnest-stock-91916:so_public.table1], experience.organization), experience) as t1 left join each [earnest-stock-91916:so_public.table2] as t2
on t1.experience.organization.name = t2.field1;

我能够FLATTEN数据(必须应用它两次),但不能恢复原始结构 - 加入其中一个子行更难。

我看到你想要做的是丰富一些子行?