如何在BigQuery中使用表通配符展平?

时间:2022-06-01 21:37:09

We recently switched to a standard setup with tables that are labeled by month (foo_2015_05) with a common format that contains a repeated field. Originally when I created a view based on one, large table, it forces me to FLATTEN the table on the repeated field.

我们最近切换到标准设置,其中包含以月(foo_2015_05)标记的表,其中包含重复字段的通用格式。最初当我创建一个基于一个大表的视图时,它迫使我在重复的字段上平移表。

When trying to update my view to account for the monthly tables, I can't seem to have both a table wildcard AND flatten at the same time.

当我尝试更新我的视图以考虑每月表时,我似乎无法同时使用表通配符和展平。

SELECT blah
FROM FLATTEN(TABLE_QUERY(dataset, "tableid CONTAINS 'foo_'"), repeated_field)

gives me the following error: Table name cannot be resolved: dataset name is missing

给我以下错误:无法解析表名:缺少数据集名称

Am I missing something? Or is there a work-around for this?

我错过了什么吗?或者有解决方法吗?

1 个解决方案

#1


I believe the issue is that FLATTEN does not work a union of tables, which TABLE_QUERY is eventually rewritten to, if the TABLE_QUERY evaluates to multiple tables. A workaround is to wrap the TABLE_QUERY in a subselect, making the FLATTEN operate over a single source, the subselect.

我认为问题在于,如果TABLE_QUERY评估为多个表,则FLATTEN不会运行表的联合,最终会重写TABLE_QUERY。解决方法是将TABLE_QUERY包装在子选择中,使FLATTEN在单个源(子选择)上运行。

SELECT blah
FROM FLATTEN(
  (SELECT * FROM TABLE_QUERY(dataset, "tableid CONTAINS 'foo_'")), 
  repeated_field)

#1


I believe the issue is that FLATTEN does not work a union of tables, which TABLE_QUERY is eventually rewritten to, if the TABLE_QUERY evaluates to multiple tables. A workaround is to wrap the TABLE_QUERY in a subselect, making the FLATTEN operate over a single source, the subselect.

我认为问题在于,如果TABLE_QUERY评估为多个表,则FLATTEN不会运行表的联合,最终会重写TABLE_QUERY。解决方法是将TABLE_QUERY包装在子选择中,使FLATTEN在单个源(子选择)上运行。

SELECT blah
FROM FLATTEN(
  (SELECT * FROM TABLE_QUERY(dataset, "tableid CONTAINS 'foo_'")), 
  repeated_field)