Class: RbBigQuery::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/rbbigquery/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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]
  authorize(opts[:service_email], opts[:key_path])
end

Instance Attribute Details

#bqObject

Returns the value of attribute bq.



3
4
5
# File 'lib/rbbigquery/client.rb', line 3

def bq
  @bq
end

#clientObject

Returns the value of attribute client.



3
4
5
# File 'lib/rbbigquery/client.rb', line 3

def client
  @client
end

#project_idObject

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

Returns:



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.

Parameters:

  • query (String)

Returns:

  • (String)

    row response string



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