【问题标题】:Google BigQuery asking for JOIN EACH but I'm already using itGoogle BigQuery 要求 JOIN EACH,但我已经在使用它
【发布时间】:2015-02-24 19:01:20
【问题描述】:

我正在尝试在 BigQuery 中运行一个查询,该查询有两个子选择和一个连接,但我无法让它工作。我正在做的一种解决方法是自己运行子选择,然后将它们保存为表,然后使用连接执行另一个查询,但我认为我应该能够使用一个查询来执行此操作。

我收到了错误:

Table too large for JOIN. Consider using JOIN EACH. For more details, please see https://developers.google.com/bigquery/docs/query-reference#joins

但我已经在使用每个连接。我尝试过使用交叉连接并使用 group by each 但这些给了我不同的错误。 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

【问题讨论】:

    标签: google-bigquery


    【解决方案1】:

    GROUP BYJOIN EACH 中。 GROUP BY 达到了基数(不同值的数量)的限制,并且最终的分组不可并行化。这限制了 BigQuery 执行联接的能力。

    如果您将GROUP BY 更改为GROUP EACH BY,这很可能会起作用。

    (是的,我意识到这是不愉快且不标准的。BigQuery 团队目前正在努力使这样的事情“正常工作”。)

    【讨论】:

      【解决方案2】:

      这可以合并为一个查询:

      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。

      【讨论】:

      • 感谢 Pentium10,我认为应该有一种方法可以用一个 SELECT 语句来做到这一点,但我想不通。
      猜你喜欢
      • 2017-10-03
      • 2021-11-11
      • 2017-11-18
      • 2019-01-08
      • 2021-04-05
      • 1970-01-01
      • 2020-05-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多