Class: Yancya::BigQuery::Job

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

Instance Method Summary collapse

Constructor Details

#initialize(resource:, bq:) ⇒ Job



4
5
6
7
# File 'lib/yancya/big_query/job.rb', line 4

def initialize(resource:, bq:)
  @resource = resource
  @jobs = BigQuery::Jobs.new(bq: bq)
end

Instance Method Details

#all_query_resultsObject

caution: This method might return huge results



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/yancya/big_query/job.rb', line 25

def all_query_results
  loop.reduce([]) do |ary, _|
    ary.tap do |a|
      a << @jobs.get_query_results(
        project_id: project_id,
        job_id: job_id,
        page_token: (ary.last||{})["pageToken"]
      )
    end

    if (ary.last||{})["pageToken"].nil?
      break ary
    else
      ary
    end
  end
end

#errorsObject



63
64
65
# File 'lib/yancya/big_query/job.rb', line 63

def errors
  status["errors"]
end

#job_idObject



51
52
53
# File 'lib/yancya/big_query/job.rb', line 51

def job_id
  job_reference["jobId"]
end

#project_idObject



47
48
49
# File 'lib/yancya/big_query/job.rb', line 47

def project_id
  job_reference["projectId"]
end

#queryObject



55
56
57
# File 'lib/yancya/big_query/job.rb', line 55

def query
  (configuration["query"]||{})["query"]
end

#query_resultsObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/yancya/big_query/job.rb', line 9

def query_results
  @jobs.get_query_results(
    project_id: project_id,
    job_id: job_id
  ).tap do |qr|
    if qr["pageToken"]
      warn " This is a slice in all results.\n You have not took rest results.\n Perhaps all_query_results is useful.\n      TEXT\n    end\n  end\nend\n"

#reloadObject



43
44
45
# File 'lib/yancya/big_query/job.rb', line 43

def reload
  @jobs.get(project_id: project_id, job_id: job_id)
end

#stateObject



59
60
61
# File 'lib/yancya/big_query/job.rb', line 59

def state
  status["state"]
end