Gcloud::Bigquery::QueryJob

QueryJob

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

See Querying Data and the Jobs API reference for details.

Methods

Public Instance Methods

batch?()

Checks if the priority for the query is BATCH.

bytes_processed()

The number of bytes processed by the query.

cache?()

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

cache_hit?()

Checks if the query results are from the query cache.

destination()

The table in which the query results are stored.

flatten?()

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.

interactive?()

Checks if the priority for the query is INTERACTIVE.

large_results?()

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

query_results(options = {})

Retrieves the query results for the job.

Parameters

options

An optional Hash for controlling additional behavior. (Hash)

options[:token]

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

options[:max]

Maximum number of results to return. (Integer)

options[:start]

Zero-based index of the starting row to read. (Integer)

options[:timeout]

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

Returns

Gcloud::Bigquery::QueryData

Example

require "gcloud"

gcloud = Gcloud.new
bigquery = gcloud.bigquery

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

loop do
  break if job.done?
  sleep 1
  job.refresh!
end
data = job.query_results
data.each do |row|
  puts row["word"]
end
data = data.next if data.next?