我在BigQuery中设计了一个视图,该视图引用了其他视图和一个Google表格。 根据我的经验,即使我只有一行,但在bigquery中查询google表格也要花30秒钟左右的时间,尽管我找不到任何文档来解释这一点。 该视图由4个CTE(全部引用其他视图)和Google表格组成,该视图中的SQL大约需要48秒才能运行。
但是当我将SQL保存为视图并从视图中执行Select *时,查询无法完成,查询运行了大约10分钟,然后给出了错误 “执行期间遇到错误。重试可能会解决问题。”
我了解查询视图的视图很麻烦,但是我可以在编辑器中查询视图而不会出现问题(大约需要一分钟),为什么将其另存为视图并查询更成问题呢?
以下是查询:
#standardSQL
with spends as (SELECT y.course,cast(concat(cast(extract (YEAR from date)as string),"-",cast(extract(MONTH from date)as string),"-01")as date)as month,sum(spend) as spend fROM `project.dataset.view1` x
left join (select * from `project.dataset.table1`) as y
on x.account_id = y.id
group by 1,2),
forecasts as (select * from `project.dataset.google_sheet1`),
cds as (select course, sum(spend)/7 as current_daily_spend from (SELECT y.course,
case when date between DATE_SUB(current_date(), interval 7 DAY) and DATE_SUB(current_date(), interval 1 DAY) then sum(spend) else null end AS spend
fROM `project.dataset.view1` x
left join (select * from `project.dataset.table1`) as y
on x.account_id = y.id
group by date,y.course)
group by course),
yesterday as (select course, sum(spend) as yesterday_spend from (SELECT y.course,
case when date = DATE_SUB(current_date(), interval 1 DAY) then sum(spend) else null end AS spend
fROM `project.dataset.view1` x
left join (select * from `project.dataset.table1`) as y
on x.account_id = y.id
group by date,y.course)
group by course)
Select forecasts.*,spends.spend,cds.current_daily_spend,yesterday.yesterday_spend from forecasts
left join spends
on forecasts.month = spends.month and forecasts.course = spends.course
left join cds
on spends.course = cds.course
left join yesterday
on spends.course = yesterday.course