Class: Yancya::BigQuery::Jobs

Inherits:
Resource
  • Object
show all
Defined in:
lib/yancya/big_query/jobs.rb

Instance Method Summary collapse

Methods inherited from Resource

#initialize

Constructor Details

This class inherits a constructor from Yancya::BigQuery::Resource

Instance Method Details

#cancel(project_id:, job_id:) ⇒ Object



7
8
9
10
11
12
# File 'lib/yancya/big_query/jobs.rb', line 7

def cancel(project_id:, job_id:)
  execute(
    api_method: @bq.api.jobs.cancel,
    parameters: { projectId: project_id, jobId: job_id }
  )
end

#get(project_id:, job_id:) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/yancya/big_query/jobs.rb', line 14

def get(project_id:, job_id:)
  resource = execute(
    api_method: @bq.api.jobs.get,
    parameters: { projectId: project_id, jobId: job_id }
  )

  BigQuery::Job.new(resource: resource, bq: @bq)
end

#get_query_results(project_id:, job_id:, page_token: nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/yancya/big_query/jobs.rb', line 23

def get_query_results(project_id:, job_id:, page_token: nil)
  execute(
    api_method: @bq.api.jobs.get_query_results,
    parameters: {
      projectId: project_id,
      jobId: job_id,
      pageToken: page_token
    }
  )
end

#insert(project_id:) ⇒ Object



34
35
36
37
# File 'lib/yancya/big_query/jobs.rb', line 34

def insert(project_id:)
  # TODO: https://developers.google.com/bigquery/docs/reference/v2/jobs/insert
  raise "This method is not yet working"
end

#list(project_id:) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/yancya/big_query/jobs.rb', line 39

def list(project_id:)
  resources = execute(
    api_method: @bq.api.jobs.list,
    parameters: { projectId: project_id, projection: "full" }
  )

  resources["jobs"].map{|job|
    BigQuery::Job.new(resource: job, bq: @bq)
  }
end

#query(project_id:, sql:) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/yancya/big_query/jobs.rb', line 50

def query(project_id:, sql:)
  resource = execute(
    api_method: @bq.api.jobs.query,
    body_object: { query: sql },
    parameters: { projectId: project_id }
  )

  BigQuery::Job.new(resource: resource, bq: @bq)
end