代码之家  ›  专栏  ›  技术社区  ›  walker_4

为什么在大查询中Github存档中的分叉数量与UI不匹配?

  •  1
  • walker_4  · 技术社区  · 6 年前

    我正试图通过大查询在GitHub存档中获取各种GitHub回购指标。( doc here )但是,当我尝试计算分叉数时,我得到的分叉数与Github UI中指定的分叉数非常不同。例如,当我运行此SQL脚本时:

    SELECT repo.url,repo.name , COUNT(*) fork_count, 
    FROM [githubarchive:year.2011],
      [githubarchive:year.2012],
      [githubarchive:year.2013],
      [githubarchive:year.2014],
      [githubarchive:year.2015],
      [githubarchive:year.2016],
      [githubarchive:year.2017],
      [githubarchive:year.2018],
      [githubarchive:month.201901]
    WHERE type='ForkEvent'
    and repo.url like 'https://github.com/python/cpython'
    GROUP BY 1,2
    

    我得到的结果是:

    Row repo_url                           repo_name   fork_count    
    1   https://github.com/python/cpython   cpython    177
    

    但是,当我转到url' https://github.com/python/cpython 我看到有8198个叉子。这种差异的原因是什么?

    编辑:

    Felipe在下面指出,同一回购协议可能有多个URL。 Felipe's output

    但是,即使有多个URL,这个数字也与UI不完全匹配,这次比UI的数字大得多。有没有什么方法可以得到一个精确的匹配?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Felipe Hoffa    6 年前

    你在查询什么?注意,如果您选择repo id、name或url,将会得到不同的结果:

    #standardSQL
    SELECT repo.name, repo.id, repo.url, COUNT(*) c
    FROM `githubarchive.month.201*`
    WHERE type='ForkEvent'
    AND (
      repo.id = 81598961 
      OR repo.name='python/cpython'
      OR repo.url like 'https://github.com/python/cpython'
    )
    GROUP BY 1,2,3
    

    enter image description here

    如果你想知道“什么时候?”:

    #standardSQL
    SELECT repo.name, repo.id, repo.url, COUNT(*) c
      , MIN(DATE(created_at)) since, MAX(DATE(created_at)) until
    FROM `githubarchive.month.201*`
    WHERE type='ForkEvent'
    AND (
      repo.id = 81598961 
      OR repo.name='python/cpython'
      OR repo.url like 'https://github.com/python/cpython'
    )
    GROUP BY 1,2,3
    ORDER BY since
    

    enter image description here

    编辑:

    Github只为每个用户列出一个fork,所以如果您想删除重复的do count(distinct actor.id),它会降低到~9k。