Google BigQuery 要求 JOIN EACH 但我已经在使用它了
Google BigQuery asking for JOIN EACH but I'm already using it
我正在尝试 运行 BigQuery 中的一个查询,它有两个子选择和一个连接,但我无法让它工作。作为解决方法,我正在做的是 运行 子选择本身,然后将它们保存为表,然后使用连接执行另一个查询,但我认为我应该能够通过一个查询来完成此操作。
我遇到错误:
Table too large for JOIN. Consider using JOIN EACH. For more details, please see https://developers.google.com/bigquery/docs/query-reference#joins
但我已经在使用每个连接了。我试过使用交叉连接和按每个组使用,但这些给了我不同的错误。关于这个主题的 Stack Overflow 上的其他问题没有帮助,一个说这是 BigQuery 中的一个错误,另一个是有人使用 'cross join each'...
以下是我的sql,如有错误请见谅,但我认为应该可以:
select
t1.device_uuid,
t1.session_uuid,
t1.nth,
t1.Diamonds_Launch,
t2.Diamonds_Close
from (
select
device_uuid,
session_uuid,
nth,
sum(cast([project_id].[table_id].attributes.Value as integer)) as Diamonds_Launch
from [project_id].[table_id]
where name = 'App Launch'
and attributes.Name = 'Inventory - Diamonds'
group by device_uuid, session_uuid, nth
) as t1
join each (
select
device_uuid,
session_uuid,
nth,
sum(cast([project_id].[table_id].attributes.Value as integer)) as Diamonds_Close
from [project_id].[table_id]
where name = 'App Close'
and attributes.Name = 'Inventory - Diamonds'
group by device_uuid, session_uuid, nth
) as t2
on t1.device_uuid = t2.device_uuid
and t1.session_uuid = t2.session_uuid
这可以合并为一个查询:
SELECT device_uuid,
session_uuid,
nth,
SUM(IF (name = 'App Launch', INTEGER([project_id].[table_id].attributes.Value), 0)) AS Diamonds_Launch,
SUM(IF (name = 'App Close', INTEGER([project_id].[table_id].attributes.Value), 0)) AS Diamonds_Close,
FROM [project_id].[table_id]
WHERE attributes.Name = 'Inventory - Diamonds'
GROUP BY device_uuid,
session_uuid,
nth
您还必须对大型表使用 GROUP EACH。
您在 JOIN EACH
中得到了 GROUP BY
。 GROUP BY
达到基数限制(不同值的数量)并且最终分组不可并行化。这限制了 BigQuery 进行连接的能力。
如果您将 GROUP BY
更改为 GROUP EACH BY
,这很可能会起作用。
(是的,我知道这很不愉快且不标准。BigQuery 团队目前正在努力制作这样的东西 'just work'。)
我正在尝试 运行 BigQuery 中的一个查询,它有两个子选择和一个连接,但我无法让它工作。作为解决方法,我正在做的是 运行 子选择本身,然后将它们保存为表,然后使用连接执行另一个查询,但我认为我应该能够通过一个查询来完成此操作。
我遇到错误:
Table too large for JOIN. Consider using JOIN EACH. For more details, please see https://developers.google.com/bigquery/docs/query-reference#joins
但我已经在使用每个连接了。我试过使用交叉连接和按每个组使用,但这些给了我不同的错误。关于这个主题的 Stack Overflow 上的其他问题没有帮助,一个说这是 BigQuery 中的一个错误,另一个是有人使用 'cross join each'...
以下是我的sql,如有错误请见谅,但我认为应该可以:
select
t1.device_uuid,
t1.session_uuid,
t1.nth,
t1.Diamonds_Launch,
t2.Diamonds_Close
from (
select
device_uuid,
session_uuid,
nth,
sum(cast([project_id].[table_id].attributes.Value as integer)) as Diamonds_Launch
from [project_id].[table_id]
where name = 'App Launch'
and attributes.Name = 'Inventory - Diamonds'
group by device_uuid, session_uuid, nth
) as t1
join each (
select
device_uuid,
session_uuid,
nth,
sum(cast([project_id].[table_id].attributes.Value as integer)) as Diamonds_Close
from [project_id].[table_id]
where name = 'App Close'
and attributes.Name = 'Inventory - Diamonds'
group by device_uuid, session_uuid, nth
) as t2
on t1.device_uuid = t2.device_uuid
and t1.session_uuid = t2.session_uuid
这可以合并为一个查询:
SELECT device_uuid,
session_uuid,
nth,
SUM(IF (name = 'App Launch', INTEGER([project_id].[table_id].attributes.Value), 0)) AS Diamonds_Launch,
SUM(IF (name = 'App Close', INTEGER([project_id].[table_id].attributes.Value), 0)) AS Diamonds_Close,
FROM [project_id].[table_id]
WHERE attributes.Name = 'Inventory - Diamonds'
GROUP BY device_uuid,
session_uuid,
nth
您还必须对大型表使用 GROUP EACH。
您在 JOIN EACH
中得到了 GROUP BY
。 GROUP BY
达到基数限制(不同值的数量)并且最终分组不可并行化。这限制了 BigQuery 进行连接的能力。
如果您将 GROUP BY
更改为 GROUP EACH BY
,这很可能会起作用。
(是的,我知道这很不愉快且不标准。BigQuery 团队目前正在努力制作这样的东西 'just work'。)