Class: Google::Cloud::Bigquery::QueryJob

Inherits:
Job
  • Object
show all
Defined in:
lib/google/cloud/bigquery/query_job.rb

Overview

QueryJob

A Job subclass representing a query operation that may be performed on a Table. A QueryJob instance is created when you call Project#query_job, Dataset#query_job, or View#data.

Instance Method Summary collapse

Methods inherited from Job

#cancel, #configuration, #created_at, #done?, #ended_at, #error, #errors, #failed?, #job_id, #pending?, #project_id, #reload!, #rerun!, #running?, #started_at, #state, #statistics, #status, #wait_until_done!

Instance Method Details

#batch?Boolean

Checks if the priority for the query is BATCH.

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/google/cloud/bigquery/query_job.rb', line 35

def batch?
  val = @gapi.configuration.query.priority
  val == "BATCH"
end

#bytes_processedObject

The number of bytes processed by the query.



101
102
103
104
105
# File 'lib/google/cloud/bigquery/query_job.rb', line 101

def bytes_processed
  Integer @gapi.statistics.query.total_bytes_processed
rescue
  nil
end

#cache?Boolean

Checks if the query job looks for an existing result in the query cache. For more information, see Query Caching.

Returns:

  • (Boolean)


61
62
63
64
65
# File 'lib/google/cloud/bigquery/query_job.rb', line 61

def cache?
  val = @gapi.configuration.query.use_query_cache
  return false if val.nil?
  val
end

#cache_hit?Boolean

Checks if the query results are from the query cache.

Returns:

  • (Boolean)


95
96
97
# File 'lib/google/cloud/bigquery/query_job.rb', line 95

def cache_hit?
  @gapi.statistics.query.cache_hit
end

#destinationObject

The table in which the query results are stored.



109
110
111
112
113
114
115
# File 'lib/google/cloud/bigquery/query_job.rb', line 109

def destination
  table = @gapi.configuration.query.destination_table
  return nil unless table
  retrieve_table table.project_id,
                 table.dataset_id,
                 table.table_id
end

#flatten?Boolean

Checks if the query job flattens nested and repeated fields in the query results. The default is true. If the value is false,

large_results? should return true.

Returns:

  • (Boolean)


71
72
73
74
75
# File 'lib/google/cloud/bigquery/query_job.rb', line 71

def flatten?
  val = @gapi.configuration.query.flatten_results
  return true if val.nil?
  val
end

#interactive?Boolean

Checks if the priority for the query is INTERACTIVE.

Returns:

  • (Boolean)


42
43
44
45
46
# File 'lib/google/cloud/bigquery/query_job.rb', line 42

def interactive?
  val = @gapi.configuration.query.priority
  return true if val.nil?
  val == "INTERACTIVE"
end

#large_results?Boolean

Checks if the the query job allows arbitrarily large results at a slight cost to performance.

Returns:

  • (Boolean)


51
52
53
54
55
# File 'lib/google/cloud/bigquery/query_job.rb', line 51

def large_results?
  val = @gapi.configuration.query.allow_large_results
  return false if val.nil?
  val
end

#legacy_sql?Boolean

Checks if the query job is using legacy sql.

Returns:

  • (Boolean)


119
120
121
122
123
# File 'lib/google/cloud/bigquery/query_job.rb', line 119

def legacy_sql?
  val = @gapi.configuration.query.use_legacy_sql
  return true if val.nil?
  val
end

#maximum_billing_tierObject

Limits the billing tier for this job. For more information, see High-Compute queries.



81
82
83
# File 'lib/google/cloud/bigquery/query_job.rb', line 81

def maximum_billing_tier
  @gapi.configuration.query.maximum_billing_tier
end

#maximum_bytes_billedObject

Limits the bytes billed for this job.



87
88
89
90
91
# File 'lib/google/cloud/bigquery/query_job.rb', line 87

def maximum_bytes_billed
  Integer @gapi.configuration.query.maximum_bytes_billed
rescue
  nil
end

#query_results(token: nil, max: nil, start: nil, timeout: nil) ⇒ Google::Cloud::Bigquery::QueryData

Retrieves the query results for the job.

Examples:

require "google/cloud/bigquery"

bigquery = Google::Cloud::Bigquery.new

sql = "SELECT word FROM publicdata.samples.shakespeare"
job = bigquery.query_job sql

job.wait_until_done!
data = job.query_results
data.each do |row|
  puts row[:word]
end
data = data.next if data.next?

Parameters:

  • token (String)

    Page token, returned by a previous call, identifying the result set.

  • max (Integer)

    Maximum number of results to return.

  • start (Integer)

    Zero-based index of the starting row to read.

  • timeout (Integer)

    How long to wait for the query to complete, in milliseconds, before returning. Default is 10,000 milliseconds (10 seconds).

Returns:



159
160
161
162
163
164
# File 'lib/google/cloud/bigquery/query_job.rb', line 159

def query_results token: nil, max: nil, start: nil, timeout: nil
  ensure_service!
  options = { token: token, max: max, start: start, timeout: timeout }
  gapi = service.job_query_results job_id, options
  QueryData.from_gapi gapi, service
end

#standard_sql?Boolean

Checks if the query job is using standard sql.

Returns:

  • (Boolean)


127
128
129
# File 'lib/google/cloud/bigquery/query_job.rb', line 127

def standard_sql?
  !legacy_sql?
end