Class: BigQuery
- Inherits:
-
Object
show all
- Defined in:
- lib/bigquery.rb,
lib/bigquery/version.rb,
lib/bigquery/resource.rb,
lib/bigquery/query_async.rb,
lib/bigquery/bigquery_api.rb,
lib/bigquery/query_result.rb
Defined Under Namespace
Classes: BigQueryApi, QueryAsync, QueryResult, Resource
Constant Summary
collapse
- DEFAULT_KEY_PASS =
'notasecret'
- NAME =
'bigquery-ruby'
- VERSION =
"0.0.1"
Instance Attribute Summary collapse
Instance Method Summary
collapse
-
#create_table(table_id, schema) ⇒ Object
-
#datasets ⇒ Object
-
#initialize(project_id: nil, dataset_id: nil, api: nil, auth_email: nil, auth_key: nil, auth_pass: DEFAULT_KEY_PASS, client_id: nil, client_secret: nil) ⇒ BigQuery
constructor
A new instance of BigQuery.
-
#jobs ⇒ Object
-
#projects ⇒ Object
-
#query(sql, dry_run: false) ⇒ Object
-
#query_async(sql, dry_run: false) ⇒ Object
-
#tables ⇒ Object
Constructor Details
#initialize(project_id: nil, dataset_id: nil, api: nil, auth_email: nil, auth_key: nil, auth_pass: DEFAULT_KEY_PASS, client_id: nil, client_secret: nil) ⇒ BigQuery
Returns a new instance of BigQuery.
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/bigquery.rb', line 13
def initialize(project_id: nil, dataset_id: nil, api: nil,
auth_email: nil, auth_key: nil, auth_pass: DEFAULT_KEY_PASS,
client_id: nil, client_secret: nil)
@project_id = project_id
@dataset_id = dataset_id
if !api.nil?
@api = api
else
auth = do_auth(auth_email, auth_key, auth_pass, client_id, client_secret)
@api = BigQueryApi.new(auth)
end
end
|
Instance Attribute Details
#dataset_id ⇒ Object
Returns the value of attribute dataset_id.
11
12
13
|
# File 'lib/bigquery.rb', line 11
def dataset_id
@dataset_id
end
|
#project_id ⇒ Object
Returns the value of attribute project_id.
11
12
13
|
# File 'lib/bigquery.rb', line 11
def project_id
@project_id
end
|
Instance Method Details
#create_table(table_id, schema) ⇒ Object
54
55
56
57
|
# File 'lib/bigquery.rb', line 54
def create_table(table_id, schema)
check_dataset!
@api.tables_insert(@project_id, @dataset_id, table_id, schema)
end
|
#datasets ⇒ Object
35
36
37
38
39
|
# File 'lib/bigquery.rb', line 35
def datasets
check_project!
result = @api.datasets_list(@project_id)
result['datasets'].map {|d| BigQuery::Resource.new(d) }
end
|
#jobs ⇒ Object
41
42
43
44
45
|
# File 'lib/bigquery.rb', line 41
def jobs
check_project!
result = @api.jobs_list(@project_id)
result['jobs'].map {|d| BigQuery::Resource.new(d) }
end
|
#projects ⇒ Object
29
30
31
32
|
# File 'lib/bigquery.rb', line 29
def projects
result = @api.projects_list
result['projects'].map {|d| BigQuery::Resource.new(d) }
end
|
#query(sql, dry_run: false) ⇒ Object
59
60
61
62
63
|
# File 'lib/bigquery.rb', line 59
def query(sql, dry_run: false)
check_dataset!
result = do_query(sql, dry_run)
(dry_run) ? [] : BigQuery::QueryResult.new(result)
end
|
#query_async(sql, dry_run: false) ⇒ Object
65
66
67
68
69
70
|
# File 'lib/bigquery.rb', line 65
def query_async(sql, dry_run: false)
check_dataset!
result = @api.jobs_insert(@project_id, @dataset_id, sql, dry_run)
job_id = result['jobReference']['jobId']
(dry_run) ? nil : BigQuery::QueryAsync.new(@api, @project_id, job_id)
end
|
#tables ⇒ Object
48
49
50
51
52
|
# File 'lib/bigquery.rb', line 48
def tables
check_dataset!
result = @api.tables_list(@project_id, @dataset_id)
result['tables'].map {|d| BigQuery::Resource.new(d) }
end
|