0
1

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 3 years have passed since last update.

google-api-ruby-client | GoogleCloud.client.bigquery.query でデフォルト制限を越えて結果を得る

Last updated at Posted at 2016-11-22

問題

普通にクエリを発行すると、全レコードが得られなかったりする。

大きなレコード数のあるテーブル。

GoogleCloud.client.bigquery.query('SELECT * FROM bq_dataset.table_name')
# => [{"rows"=>10601344}]

だがクエリを発行すると、すべての結果が得られない。

records = GoogleCloud.client.bigquery.query('SELECT * FROM bq_dataset.table_name LIMIT 100000')
records.size # => 35000

何故か中途半端な数字で返ってくる。
元のテーブルによって得られるレコード数が違う。バイト数制限とか?

解決

.all を付ける。
配列ではなくオブジェクトで返ってくるようになるので注意。

records = GoogleCloud.client.bigquery.query('SELECT * FROM bq_dataset.table_name LIMIT 100000').all
records.to_a.size # => 100000

環境

  • ruby 2.3.1
  • google-api-client (0.9.13)

参考

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?