bigquery-client 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bigquery-client/jobs.rb +18 -4
- data/lib/bigquery-client/version.rb +1 -1
- data/test/test_jobs.rb +16 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62916ca2e9ee1f90227ea2f2e67c9cd4f26c316d
|
4
|
+
data.tar.gz: f763e852a5747075a16c6a33c6c9287d3ee8d577
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 383fd4cd1bfe5903d6689eafd06478ebd43441f2ddf61c24901e108c5e590c7f338122d59e3c95f01f1bafd57da8817efe794f8129af39b6190243a39b8f27fc
|
7
|
+
data.tar.gz: fe4db299be123fe3c5b7c7310a1d79d4bcd53456a98d8e780085b27cef6ba32b4c23bb46135b8fea04c4ebe5084464e880083a7ad740ed8cdfe5099afa5f3404
|
data/lib/bigquery-client/jobs.rb
CHANGED
@@ -3,10 +3,20 @@
|
|
3
3
|
module BigQuery
|
4
4
|
module Jobs
|
5
5
|
def sql(query, options = {})
|
6
|
-
|
7
|
-
names =
|
8
|
-
types =
|
9
|
-
records = (
|
6
|
+
jobs_query_response = jobs_query(query, options)
|
7
|
+
names = jobs_query_response['schema']['fields'].map {|field| field['name'] }
|
8
|
+
types = jobs_query_response['schema']['fields'].map {|field| field['type'] }
|
9
|
+
records = extract_records(jobs_query_response)
|
10
|
+
|
11
|
+
page_token = jobs_query_response['pageToken']
|
12
|
+
job_id = jobs_query_response['jobReference']['jobId']
|
13
|
+
inherited_options = options.select {|k,v| [:maxResults, :timeoutMs].include?(k) }
|
14
|
+
while page_token
|
15
|
+
query_results_response = query_results(job_id, inherited_options.merge({ pageToken: page_token }))
|
16
|
+
records += extract_records(query_results_response)
|
17
|
+
page_token = query_results_response['pageToken']
|
18
|
+
end
|
19
|
+
|
10
20
|
convert(records, types).map { |values| [names, values].transpose.to_h }
|
11
21
|
end
|
12
22
|
|
@@ -52,6 +62,10 @@ module BigQuery
|
|
52
62
|
|
53
63
|
private
|
54
64
|
|
65
|
+
def extract_records(response)
|
66
|
+
(response['rows'] || []).map {|row| row['f'].map {|record| record['v'] } }
|
67
|
+
end
|
68
|
+
|
55
69
|
def convert(records, types)
|
56
70
|
records.map do |values|
|
57
71
|
values.map.with_index do |value, index|
|
data/test/test_jobs.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class JobsTest < Test::Unit::TestCase
|
4
|
-
@@
|
4
|
+
@@normal_query = <<-"EOS"
|
5
5
|
SELECT
|
6
6
|
born_alive_alive, mother_residence_state, is_male
|
7
7
|
FROM
|
@@ -23,8 +23,17 @@ class JobsTest < Test::Unit::TestCase
|
|
23
23
|
0
|
24
24
|
EOS
|
25
25
|
|
26
|
+
@@huge_result_query = <<-"EOS"
|
27
|
+
SELECT
|
28
|
+
title
|
29
|
+
FROM
|
30
|
+
publicdata:samples.wikipedia
|
31
|
+
LIMIT
|
32
|
+
1234567
|
33
|
+
EOS
|
34
|
+
|
26
35
|
def test_sql
|
27
|
-
result = $client.sql(@@
|
36
|
+
result = $client.sql(@@normal_query)
|
28
37
|
assert { result.size == 100 }
|
29
38
|
assert { result.sample["born_alive_alive"].is_a? Fixnum }
|
30
39
|
assert { result.sample["mother_residence_state"].is_a? String }
|
@@ -35,4 +44,9 @@ class JobsTest < Test::Unit::TestCase
|
|
35
44
|
result = $client.sql(@@no_rows_query)
|
36
45
|
assert { result == [] }
|
37
46
|
end
|
47
|
+
|
48
|
+
def test_sql_pagination
|
49
|
+
record_size = $client.sql(@@huge_result_query, maxResults: 10000).size
|
50
|
+
assert { record_size == 1234567 }
|
51
|
+
end
|
38
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bigquery-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tsukuru Tanimichi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: google-api-client
|