Class: Gcloud::Bigquery::QueryJob

Inherits:
Job
  • Object
show all
Defined in:
lib/gcloud/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

#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)

32
33
34
35
# File 'lib/gcloud/bigquery/query_job.rb', line 32

def batch?
  val = config["query"]["priority"]
  val == "BATCH"
end

#bytes_processedObject

The number of bytes processed by the query.


82
83
84
# File 'lib/gcloud/bigquery/query_job.rb', line 82

def bytes_processed
  stats["query"]["totalBytesProcessed"]
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)

58
59
60
61
62
# File 'lib/gcloud/bigquery/query_job.rb', line 58

def cache?
  val = config["query"]["useQueryCache"]
  return false if val.nil?
  val
end

#cache_hit?Boolean

Checks if the query results are from the query cache.

Returns:

  • (Boolean)

76
77
78
# File 'lib/gcloud/bigquery/query_job.rb', line 76

def cache_hit?
  stats["query"]["cacheHit"]
end

#destinationObject

The table in which the query results are stored.


88
89
90
91
92
93
94
# File 'lib/gcloud/bigquery/query_job.rb', line 88

def destination
  table = config["query"]["destinationTable"]
  return nil unless table
  retrieve_table table["projectId"],
                 table["datasetId"],
                 table["tableId"]
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)

68
69
70
71
72
# File 'lib/gcloud/bigquery/query_job.rb', line 68

def flatten?
  val = config["query"]["flattenResults"]
  return true if val.nil?
  val
end

#interactive?Boolean

Checks if the priority for the query is INTERACTIVE.

Returns:

  • (Boolean)

39
40
41
42
43
# File 'lib/gcloud/bigquery/query_job.rb', line 39

def interactive?
  val = config["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)

48
49
50
51
52
# File 'lib/gcloud/bigquery/query_job.rb', line 48

def large_results?
  val = config["query"]["allowLargeResults"]
  return false if val.nil?
  val
end

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

Retrieves the query results for the job.

Examples:

require "gcloud"

gcloud = Gcloud.new
bigquery = gcloud.bigquery

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

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:


125
126
127
128
129
130
131
132
133
134
# File 'lib/gcloud/bigquery/query_job.rb', line 125

def query_results token: nil, max: nil, start: nil, timeout: nil
  ensure_connection!
  options = { token: token, max: max, start: start, timeout: timeout }
  resp = connection.job_query_results job_id, options
  if resp.success?
    QueryData.from_gapi resp.data, connection
  else
    fail ApiError.from_response(resp)
  end
end