Module: BigQuery::Jobs

Included in:
Client
Defined in:
lib/bigquery-client/jobs.rb

Instance Method Summary collapse

Instance Method Details

#fetch_job(id, options = {}) ⇒ Object



39
40
41
42
43
44
# File 'lib/bigquery-client/jobs.rb', line 39

def fetch_job(id, options = {})
  access_api(
    api_method: bigquery.jobs.get,
    parameters: { jobId: id }.merge(options)
  )
end

#jobs(options = {}) ⇒ Object



32
33
34
35
36
37
# File 'lib/bigquery-client/jobs.rb', line 32

def jobs(options = {})
  access_api(
    api_method: bigquery.jobs.list,
    parameters: options
  )
end

#jobs_query(query, options = {}) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/bigquery-client/jobs.rb', line 13

def jobs_query(query, options = {})
  default = { query: query, timeoutMs: 600_000 }
  access_api(
    api_method: bigquery.jobs.query,
    body_object: default.merge(options)
  )
end

#load(options = {}) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/bigquery-client/jobs.rb', line 21

def load(options = {})
  access_api(
    api_method: bigquery.jobs.insert,
    body_object: {
      configuration: {
        load: options
      }
    }
  )
end

#query_results(id, options = {}) ⇒ Object



46
47
48
49
50
51
# File 'lib/bigquery-client/jobs.rb', line 46

def query_results(id, options = {})
  access_api(
    api_method: bigquery.jobs.get_query_results,
    parameters: { jobId: id }.merge(options)
  )
end

#sql(query, options = {}) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/bigquery-client/jobs.rb', line 5

def sql(query, options = {})
  result = jobs_query(query, options)
  names = result['schema']['fields'].map {|field| field['name'] }
  types = result['schema']['fields'].map {|field| field['type'] }
  records = result['rows'].map {|row| row['f'].map {|record| record['v'] } }
  convert(records, types).map { |values| [names, values].transpose.to_h }
end