Class: RbBigQuery::Client
- Inherits:
-
Object
- Object
- RbBigQuery::Client
- Defined in:
- lib/rbbigquery/client.rb
Instance Attribute Summary collapse
-
#bq ⇒ Object
Returns the value of attribute bq.
-
#client ⇒ Object
Returns the value of attribute client.
-
#project_id ⇒ Object
Returns the value of attribute project_id.
Instance Method Summary collapse
- #find_or_create_table(dataset, table_id, schema) ⇒ RbBigQuery::Table
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
-
#query(query) ⇒ String
Executes provided query.
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
6 7 8 9 10 11 12 13 14 |
# File 'lib/rbbigquery/client.rb', line 6 def initialize(opts = {}) @client = Google::APIClient.new( application_name: opts[:application_name], application_version: opts[:application_version] ) @bq = @client.discovered_api("bigquery", "v2") @project_id = opts[:project_id] (opts[:service_email], opts[:key_path]) end |
Instance Attribute Details
#bq ⇒ Object
Returns the value of attribute bq.
3 4 5 |
# File 'lib/rbbigquery/client.rb', line 3 def bq @bq end |
#client ⇒ Object
Returns the value of attribute client.
3 4 5 |
# File 'lib/rbbigquery/client.rb', line 3 def client @client end |
#project_id ⇒ Object
Returns the value of attribute project_id.
3 4 5 |
# File 'lib/rbbigquery/client.rb', line 3 def project_id @project_id end |
Instance Method Details
#find_or_create_table(dataset, table_id, schema) ⇒ RbBigQuery::Table
17 18 19 |
# File 'lib/rbbigquery/client.rb', line 17 def find_or_create_table(dataset, table_id, schema) RbBigQuery::Table.new(self, dataset, table_id, schema) end |
#query(query) ⇒ String
Executes provided query.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rbbigquery/client.rb', line 24 def query(query) response = @client.execute({ :api_method => @bq.jobs.query, :parameters => { 'projectId' => @project_id, }, :body_object => { 'query' => query } }) build_rows_from_response(response) end |