bigquery 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/bigquery.rb +62 -0
- metadata +61 -0
data/lib/bigquery.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'google/api_client'
|
2
|
+
|
3
|
+
class BigQuery
|
4
|
+
|
5
|
+
attr_accessor :dataset, :project_id
|
6
|
+
|
7
|
+
def initialize(opts = {})
|
8
|
+
@client = Google::APIClient.new
|
9
|
+
|
10
|
+
@client.authorization.client_id = opts['client_id']
|
11
|
+
@client.authorization.client_secret = opts['client_secret']
|
12
|
+
@client.authorization.refresh_token = opts['refresh_token']
|
13
|
+
|
14
|
+
@client.authorization.fetch_access_token!
|
15
|
+
@bq = @client.discovered_api("bigquery", "v2")
|
16
|
+
|
17
|
+
@project_id = opts['project_id']
|
18
|
+
@dataset = opts['dataset']
|
19
|
+
end
|
20
|
+
|
21
|
+
def query(q)
|
22
|
+
api({
|
23
|
+
:api_method => @bq.jobs.query,
|
24
|
+
:body_object => { "query" => q, 'timeoutMs' => 90 * 1000}
|
25
|
+
})
|
26
|
+
end
|
27
|
+
|
28
|
+
def load(opts)
|
29
|
+
api({
|
30
|
+
:api_method => @bq.jobs.insert,
|
31
|
+
:body_object => {
|
32
|
+
"configuration" => {
|
33
|
+
"load" => opts
|
34
|
+
}
|
35
|
+
}
|
36
|
+
})
|
37
|
+
end
|
38
|
+
|
39
|
+
def tables(dataset = @dataset)
|
40
|
+
api({
|
41
|
+
:api_method => @bq.tables.list,
|
42
|
+
:parameters => {"datasetId" => dataset}
|
43
|
+
})['tables']
|
44
|
+
end
|
45
|
+
|
46
|
+
def tables_formatted(dataset = @dataset)
|
47
|
+
tables(dataset).map {|t| "[#{dataset}.#{t['tableReference']['tableId']}]"}
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def api(opts)
|
53
|
+
if opts[:parameters]
|
54
|
+
opts[:parameters] = opts[:parameters].merge({"projectId" => @project_id})
|
55
|
+
else
|
56
|
+
opts[:parameters] = {"projectId" => @project_id}
|
57
|
+
end
|
58
|
+
|
59
|
+
resp = @client.execute(opts)
|
60
|
+
JSON.parse(resp.body)
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bigquery
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Adam Bronte
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: google-api-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: A nice wrapper for Google Big Query
|
31
|
+
email: adam@brontesaurus.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- lib/bigquery.rb
|
37
|
+
homepage: https://github.com/abronte/BigQuery
|
38
|
+
licenses: []
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.8.24
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: A nice wrapper for Google Big Query
|
61
|
+
test_files: []
|