bigquery 0.2.6 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/bigquery.rb +31 -0
  2. metadata +4 -4
data/lib/bigquery.rb CHANGED
@@ -60,6 +60,37 @@ class BigQuery
60
60
  })
61
61
  end
62
62
 
63
+ def get_query_results(jobId, opts = {})
64
+ opts['jobId'] = jobId
65
+ api({
66
+ :api_method => @bq.jobs.get_query_results,
67
+ :parameters => opts
68
+ })
69
+ end
70
+
71
+ # perform a query synchronously
72
+ # fetch all result rows, even when that takes >1 query
73
+ # invoke /block/ once for each row, passing the row
74
+ def each_row(q, &block)
75
+ current_row = 0
76
+ # repeatedly fetch results, starting from current_row
77
+ # invoke the block on each one, then grab next page if there is one
78
+ # it'll terminate when res has no 'rows' key or when we've done enough rows
79
+ # perform query...
80
+ res = query(q)
81
+ job_id = res['jobReference']['jobId']
82
+ # call the block on the first page of results
83
+ if( res && res['rows'] )
84
+ res['rows'].each(&block)
85
+ current_row += res['rows'].size
86
+ end
87
+ # keep grabbing pages from the API and calling the block on each row
88
+ while(( res = get_query_results(job_id, :startIndex => current_row) ) && res['rows'] && current_row < res['totalRows'].to_i ) do
89
+ res['rows'].each(&block)
90
+ current_row += res['rows'].size
91
+ end
92
+ end
93
+
63
94
  def tables(dataset = @dataset)
64
95
  api({
65
96
  :api_method => @bq.tables.list,
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bigquery
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 6
10
- version: 0.2.6
9
+ - 7
10
+ version: 0.2.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Adam Bronte
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-09-20 00:00:00 Z
18
+ date: 2012-09-25 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement