23
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Github on BigQueryを使ってgoでよく使われるpackageを調べる

Last updated at Posted at 2016-06-30

Github on BigQueryとは

Google Cloud Platform Blog: GitHub on BigQuery: Analyze all the open source code
にあるように、Githubにある全てのオープンなソースコードに対してBigQueryからクエリがかけられます。すごい。

Goで使われているpackageを調べる

以下にあるサンプルに、よく使われるgoのpackageを調べるクエリが載っている。

GitHub Data  |  BigQuery  |  Google Cloud Platform

例ではTop10だが、30にしてやってみた。

以下のクエリ例では sample_xxxというデータを間引いた小さなテーブルを参照してますが、結果は sample_を取り除いたテーブルに対して実行しています。

クエリ

SELECT
  REGEXP_EXTRACT(line, r'"([^"]+)"') AS url,
  COUNT(*) AS count
FROM
  FLATTEN( (
    SELECT
      SPLIT(SPLIT(REGEXP_EXTRACT(content, r'.*import\s*[(]([^)]*)[)]'), '\n'), ';') AS line,
    FROM (
      SELECT
        id,
        content
      FROM
        [bigquery-public-data:github_repos.sample_contents]
      WHERE
        REGEXP_MATCH(content, r'.*import\s*[(][^)]*[)]')) AS C
    JOIN (
      SELECT
        id
      FROM
        [bigquery-public-data:github_repos.sample_files]
      WHERE
        path LIKE '%.go'
      GROUP BY
        id) AS F
    ON
      C.id = F.id), line)
GROUP BY
  url
HAVING
  url IS NOT NULL
ORDER BY
  count DESC
LIMIT 30

結果

url count
1 fmt 692434
2 time 390527
3 strings 364287
4 testing 311692
5 os 311061
6 net/http 224422
7 io 193310
8 bytes 191048
9 errors 183711
10 io/ioutil 173026
11 encoding/json 163164
12 strconv 162616
13 log 141918
14 sync 135247
15 reflect 115058
16 path/filepath 107154
17 net 96514
18 net/url 79102
19 sort 67765
20 context 59503
21 golang.org/x/net/context 59146
22 flag 59020
23 runtime 58575
24 regexp 58526
25 k8s.io/kubernetes/pkg/api 52827
26 path 52798
27 github.com/golang/glog 52015
28 k8s.io/apimachinery/pkg/apis/meta/v1 49840
29 math 47452
30 bufio 45251

上位は基本的に標準packageが多いです。
次に、標準packageでないものを調べたかったのでimportにURLが含まれるものを調べてみました。

クエリ

SELECT
  REGEXP_EXTRACT(line, r'"([^\.]+\.[^"]+)"') AS url,
  COUNT(*) AS count
FROM
  FLATTEN( (
    SELECT
      SPLIT(SPLIT(REGEXP_EXTRACT(content, r'.*import\s*[(]([^)]*)[)]'), '\n'), ';') AS line,
    FROM (
      SELECT
        id,
        content
      FROM
        [bigquery-public-data:github_repos.sample_contents]
      WHERE
        REGEXP_MATCH(content, r'.*import\s*[(][^)]*[)]')) AS C
    JOIN (
      SELECT
        id
      FROM
        [bigquery-public-data:github_repos.sample_files]
      WHERE
        path LIKE '%.go'
      GROUP BY
        id) AS F
    ON
      C.id = F.id), line)
GROUP BY
  url
HAVING
  url IS NOT NULL
ORDER BY
  count DESC
LIMIT 30

結果

url count
1 golang.org/x/net/context 59146
2 k8s.io/kubernetes/pkg/api 52827
3 github.com/golang/glog 52015
4 k8s.io/apimachinery/pkg/apis/meta/v1 49840
5 github.com/stretchr/testify/assert 42613
6 github.com/onsi/ginkgo 34234
7 github.com/onsi/gomega 34054
8 github.com/spf13/cobra 31093
9 github.com/Sirupsen/logrus 28731
10 k8s.io/apimachinery/pkg/runtime 28554
11 gopkg.in/check.v1 22537
12 github.com/pkg/errors 22353
13 k8s.io/api/core/v1 20038
14 github.com/juju/errors 18756
15 github.com/aws/aws-sdk-go/aws 17602
16 k8s.io/kubernetes/pkg/runtime 17278
17 k8s.io/kubernetes/pkg/api/v1 15727
18 k8s.io/apimachinery/pkg/types 15658
19 github.com/sirupsen/logrus 15291
20 k8s.io/kubernetes/pkg/api/unversioned 15111
21 k8s.io/apimachinery/pkg/runtime/schema 15102
22 k8s.io/apimachinery/pkg/api/errors 14614
23 google.golang.org/grpc 14068
24 github.com/Azure/go-autorest/autorest 13074
25 k8s.io/apimachinery/pkg/labels 13049
26 github.com/stretchr/testify/require 13042
27 k8s.io/apimachinery/pkg/watch 12363
28 k8s.io/client-go/rest 11300
29 github.com/Azure/go-autorest/autorest/azure 11263
30 github.com/juju/testing/checkers 10800

ログとかテスト系が多い中に、kubernetes関係がちょこちょこ入ってきてる。

以上は2018/8/23に更新しました。

23
23
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
23

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?