简体   繁体   English

在bigquery上查询项目中的所有数据集和表?

[英]Query all datasets and tables within project on bigquery?

I'm currently trying to create my own analytics panel with the data I get off of BigQuery. 我目前正在尝试使用从BigQuery获得的数据创建自己的分析面板。 I have all my data coming in correctly and am able to query each table individually or every table in a specific dataset but not query every dataset within a project. 我可以正确输入所有数据,并且能够分别查询每个表或特定数据集中的每个表,但不能查询项目中的每个数据集。

To put it simply, I want to query every single table I have within BigQuery at once. 简而言之,我想一次查询BigQuery中的每个表。 The tables within BigQuery are being populated by Firebase Analytics and are likely to change without notice, add or remove one. FireQuery Analytics正在填充BigQuery中的表格,这些表格可能会更改,恕不另行通知,添加或删除其中的一个。

I'm aware of the method where you JOIN each table within a query but the values are hard coded. 我知道您在查询中JOIN每个表的方法,但是值是硬编码的。 I need a way where I can provide a wildcard and automatically query every table. 我需要一种可以提供通配符并自动查询每个表的方式。

Any help at all would be great, thanks! 根本没有任何帮助,谢谢!

Unfortunately, you can't write a single query that can query all tables in all datasets without knowing the dataset names beforehand. 不幸的是,您无法编写一个查询来查询所有数据集中的所有表,而无需事先知道数据集名称。

However, if you can programatically construct your query, you can use BigQuery's datasets.list API to get all the dataset names, and then construct a query that will get all tables within those datasets using table wildcards as described above. 但是,如果您可以以编程方式构造查询,则可以使用BigQuery的datasets.list API获取所有数据集名称,然后构造一个查询,如上所述,该查询将使用表通配符获取这些数据集中的所有表。

Have you seen the documentation on wildcard tables ? 您看过通配符表上的文档吗? The example it gives is: 它给出的示例是:

#standardSQL
SELECT
  max,
  ROUND((max-32)*5/9,1) celsius,
  mo,
  da,
  year
FROM
  `bigquery-public-data.noaa_gsod.gsod19*`
WHERE
  max != 9999.9 # code for missing data
  AND _TABLE_SUFFIX BETWEEN '29'
  AND '40'
ORDER BY
  max DESC;

Wildcard tables apply at the table level, though--not the dataset level--so you would still need to perform a union between the tables from all of your datasets, eg: 通配符表适用于表级别,而不适用于数据集级别,因此您仍然需要在所有数据集中的表之间执行联合,例如:

SELECT *
FROM (
  SELECT * FROM `first-dataset.*` UNION ALL
  SELECT * FROM `second-dataset.*` UNION ALL
  SELECT * FROM ...
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM