【问题标题】:Google BigQuery GROUP BY timeoutGoogle BigQuery GROUP BY 超时
【发布时间】:2016-04-05 10:06:45
【问题描述】:

我正在尝试通过 Google BigQuery 从 github 存档中查询协作者登录信息、存储库语言和名称。如果我排除 GROUP BY,则以下查询可以正常工作,但是使用 GROUP BY,查询将永远持续下去,直到我从 google bigquery 获得超时。由于 Google BigQuery 没有 DISTINCT,我尝试使用 GROUP BY 作为 DISTINCT,这样我就不会得到重复的行。这是我正在使用的查询:

SELECT
    a1.actor_attributes_login,
    a2.actor_attributes_login,
    a1.repository_language,
    a1.repository_name,
FROM
    [githubarchive:year.2014] AS a1
LEFT JOIN
    [githubarchive:year.2014] AS a2
ON
    a1.repository_name = a2.repository_name
WHERE
    a1.actor_attributes_login != a2.actor_attributes_login
    AND a1.actor_attributes_location = "California"
    AND (a1.repository_language = "Java"
      OR a1.repository_language = "Python")
GROUP BY
    a1.actor_attributes_login,
    a2.actor_attributes_login,
    a1.repository_language,
    a1.repository_name
LIMIT
    10000

【问题讨论】:

    标签: sql google-bigquery


    【解决方案1】:

    嗯。您可以尝试在 进行连接之前删除重复项:

    SELECT a1.actor_attributes_login, a2.actor_attributes_login,
           a1.repository_language, a1.repository_name
    FROM (SELECT a.actor_attributes_login, a.repository_language, a1.repository_name
          FROM githubarchive:year.2014] a
          WHERE a.actor_attributes_location = 'California AND
                a.repository_language IN ('Java', 'Python')
          GROUP BY a.actor_attributes_login, a.repository_language, a.repository_name
         ) a1 LEFT JOIN
         (SELECT a1.actor_attributes_login, a1.repository_language, a1.repository_name
          FROM githubarchive:year.2014] a1
          GROUP BY a1.actor_attributes_login, a1.repository_language, a1.repository_name
         ) a2
         ON a1.repository_name = a2.repository_name
    WHERE a1.actor_attributes_login <> a2.actor_attributes_login
    LIMIT 10000;
    

    如果您消除子查询中的重复项,我认为您不需要外部 GROUP BY

    此外,如果您使用的是LIMIT,您应该有一个ORDER BY

    【讨论】:

    • 啊传奇!我不得不在第一个内部选择中更改名称 a1,因为它用于该表中的 2 个表,并且它被拒绝,因为它模棱两可,但除此之外它工作得很好。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-11
    • 2021-09-08
    • 1970-01-01
    • 2018-12-28
    • 2015-10-17
    • 1970-01-01
    相关资源
    最近更新 更多