以下查询无法更改。此查询用于从我开始使用Firebase和BigQuery跟踪它们时开始选择所有活动用户。我使用此查询将数据导出到我自己的数据库中,以便我的项目可以更快地查询。
这里的查询只是我要查询的两个数据集,在我的实际查询中,它更像是100多个联合在一起的数据集。
每次运行完全构造的查询时,都会出现以下错误:
查询执行期间资源超出:查询计划资源不足 - 太多子查询或查询过于复杂..
WITH allTables AS (SELECT
app,
date,
SUM(CASE WHEN period = 30 THEN users END) as days_30
FROM (
SELECT
CONCAT(user_dim.app_info.app_id, ':', user_dim.app_info.app_platform) as app,
dates.date as date,
periods.period as period,
COUNT(DISTINCT user_dim.app_info.app_instance_id) as users
FROM `TBL1.*` as activity
CROSS JOIN
UNNEST(event_dim) AS event
CROSS JOIN (
SELECT DISTINCT
TIMESTAMP_TRUNC(TIMESTAMP_MICROS(event.timestamp_micros), DAY, 'UTC') as date
FROM `TBL1.*`
CROSS JOIN
UNNEST(event_dim) as event) as dates
CROSS JOIN (
SELECT
period
FROM (
SELECT 30 as period
)
) as periods
WHERE
dates.date >= TIMESTAMP_TRUNC(TIMESTAMP_MICROS(event.timestamp_micros), DAY, 'UTC')
AND
FLOOR(TIMESTAMP_DIFF(dates.date, TIMESTAMP_MICROS(event.timestamp_micros), DAY)/periods.period) = 0
GROUP BY 1,2,3
)
GROUP BY 1,2
UNION ALL SELECT
app,
date,
SUM(CASE WHEN period = 30 THEN users END) as days_30
FROM (
SELECT
CONCAT(user_dim.app_info.app_id, ':', user_dim.app_info.app_platform) as app,
dates.date as date,
periods.period as period,
COUNT(DISTINCT user_dim.app_info.app_instance_id) as users
FROM `TBL2.*` as activity
CROSS JOIN
UNNEST(event_dim) AS event
CROSS JOIN (
SELECT DISTINCT
TIMESTAMP_TRUNC(TIMESTAMP_MICROS(event.timestamp_micros), DAY, 'UTC') as date
FROM `TBL2.*`
CROSS JOIN
UNNEST(event_dim) as event) as dates
CROSS JOIN (
SELECT
period
FROM (
SELECT 30 as period
)
) as periods
WHERE
dates.date >= TIMESTAMP_TRUNC(TIMESTAMP_MICROS(event.timestamp_micros), DAY, 'UTC')
AND
FLOOR(TIMESTAMP_DIFF(dates.date, TIMESTAMP_MICROS(event.timestamp_micros), DAY)/periods.period) = 0
GROUP BY 1,2,3
)
GROUP BY 1,2 ) SELECT
app as target,
UNIX_SECONDS(date) as datapoint_time,
SUM(days_30) as datapoint_value
FROM allTables
WHERE
date >= TIMESTAMP_ADD(TIMESTAMP_TRUNC(CURRENT_TIMESTAMP, Day, 'UTC'), INTERVAL -30 DAY)
GROUP BY date,1
ORDER BY date ASC
我读到删除ORDER BY date ASC
可能有所帮助,但在我的情况下却没有。有没有一种方法可以让BigQuery使用更多的资源,因为这个查询不会经常运行而且可以接受一个小的价格飙升。 '
BigQuery响应:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "resourcesExceeded",
"message": "Resources exceeded during query execution: Not enough resources for query planning - too many subqueries or query is too complex."
}
],
"code": 400,
"message": "Resources exceeded during query execution: Not enough resources for query planning - too many subqueries or query is too complex."
},
"query": ""
}
最近的工作JSON:
{
"status": {
"state": "DONE",
"errorResult": {
"reason": "resourcesExceeded",
"message": "Resources exceeded during query execution: Not enough resources for query planning - too many subqueries or query is too complex.."
}
},
"kind": "bigquery#job",
"statistics": {
"endTime": "1493215173261",
"creationTime": "1493215171094",
"startTime": "1493215173261"
},
"jobReference": {
"projectId": "premium-apps",
"jobId": "bquijob_4aad2106_15baa8f26b9"
},
"state": "DONE",
"id": "premium-apps:bquijob_4aad2106_15baa8f26b9",
"errorResult": {
"reason": "resourcesExceeded",
"message": "Resources exceeded during query execution: Not enough resources for query planning - too many subqueries or query is too complex.."
}
}