2

Google Big Query を使用して GitHub アーカイブからデータを取得しようとしています。リクエストしている現在のデータ量は BigQuery が処理するには(少なくとも無料枠では)多すぎるため、リクエストの範囲を制限しようとしています。

現在1000 を超えるスターを持つリポジトリのみが過去のデータを返すように、データを制限したいと考えています。リポジトリが取得した最初の 1000 個のスターの履歴データが除外されるため、単に repository_watchers > 1000 と言うよりも複雑です。

SELECT repository_name, repository_owner, created_at, type, repository_url, repository_watchers
FROM [githubarchive:github.timeline]
WHERE type="WatchEvent"
ORDER BY created_at DESC

編集:私が使用したソリューション(@Brianの回答に基づく)

select y.repository_name, y.repository_owner, y.created_at, y.type, y.repository_url, y.repository_watchers
  from [githubarchive:github.timeline] y
  join (select repository_url, max(repository_watchers)
          from [githubarchive:github.timeline] x
         where x.type = 'WatchEvent'
         group by repository_url
        having max(repository_watchers) > 1000) x
    on y.repository_url = x.repository_url
  where y.type = 'WatchEvent'
 order by y.repository_name, y.repository_owner, y.created_at desc
4

1 に答える 1

3

試す:

select y.*
  from [githubarchive :github.timeline] y
  join (select repository_name, max(repository_watchers)
          from [githubarchive :github.timeline]
         where x.type = 'WatchEvent'
         group by repository_name
        having max(repository_watchers) > 1000) x
    on y.repository_name = x.repository_name
 order by y.created_at desc

その構文がサポートされていない場合は、次のような 3 ステップのソリューションを使用できます。

ステップ 1: REPOSITORY_WATCHERS の量が 1000 を超えるレコードが少なくとも 1 つある REPOSITORY_NAME 値を見つける

select repository_name, max(repository_watchers) as curr_watchers
  from [githubarchive :github.timeline]
 where type = 'WatchEvent'
 group by repository_name
having max(repository_watchers) > 1000

ステップ 2: その結果をテーブルとして保存し、SUB と呼びます

ステップ 3: SUB (および元のテーブル) に対して次を実行します。

select y.*
  from [githubarchive :github.timeline] y
  join sub x
    on y.repository_name = x.repository_name
 order by y.created_at desc
于 2014-07-27T23:06:02.550 に答える