另一个示例,我创建了一个按站名聚集的 NOAA GSOD 汇总表 - 我没有按天进行分区,而是根本没有对其进行分区。
假设我想为名称为SAN FRAN% 的所有电台查找自 1980 年以来最热的日子:
SELECT name, state, ARRAY_AGG(STRUCT(date,temp) ORDER BY temp DESC LIMIT 5) top_hot, MAX(date) active_until
FROM `fh-bigquery.weather_gsod.all`
WHERE name LIKE 'SAN FRANC%'
AND date > '1980-01-01'
GROUP BY 1,2
ORDER BY active_until DESC
请注意,我只处理了 55.2MB 的数据后得到了结果。
源表上的等效查询(没有集群)改为处理 4GB:
# query on non-clustered tables - too much data compared to the other one
SELECT name, state, ARRAY_AGG(STRUCT(CONCAT(a.year,a.mo,a.da),temp) ORDER BY temp DESC LIMIT 5) top_hot, MAX(CONCAT(a.year,a.mo,a.da)) active_until
FROM `bigquery-public-data.noaa_gsod.gsod*` a
JOIN `bigquery-public-data.noaa_gsod.stations` b
ON a.wban=b.wban AND a.stn=b.usaf
WHERE name LIKE 'SAN FRANC%'
AND _table_suffix >= '1980'
GROUP BY 1,2
ORDER BY active_until DESC
我还添加了一个地理聚集表,以按位置而不是站名进行搜索。在此处查看详细信息:https://stackoverflow.com/a/34804655/132438