Gcloud::Bigquery::Job

Job

Represents a generic Job that may be performed on a Table.

See Managing Jobs, Datasets, and Projects for an overview of BigQuery jobs, and the Jobs API reference for details.

The subclasses of Job represent the specific BigQuery job types: CopyJob, ExtractJob, LoadJob, and QueryJob.

A job instance is created when you call Gcloud::Bigquery::Project#query_job, Gcloud::Bigquery::Dataset#query_job, Gcloud::Bigquery::Table#copy, Gcloud::Bigquery::Table#extract, Gcloud::Bigquery::Table#load, or Gcloud::Bigquery::View#data.

require "gcloud"

gcloud = Gcloud.new
bigquery = gcloud.bigquery

q = "SELECT COUNT(word) as count FROM publicdata:samples.shakespeare"
job = bigquery.query_job q

loop do
  break if job.done?
  sleep 1
  job.refresh!
end

if job.failed?
  puts job.error
else
  puts job.query_results.first
end

Methods

Public Instance Methods

config()

Alias for: configuration

configuration()

The configuration for the job. Returns a hash. See the Jobs API reference.

Also aliased as: config

created_at()

The time when the job was created.

done?()

Checks if the job's state is DONE. When true, the job has stopped running. However, a DONE state does not mean that the job completed successfully. Use failed? to detect if an error occurred or if the job was successful.

ended_at()

The time when the job ended. This field is present when the job's state is DONE.

error()

The last error for the job, if any errors have occurred. Returns a hash. See the Jobs API reference.

Returns

Hash

{
  "reason"=>"notFound",
  "message"=>"Not found: Table publicdata:samples.BAD_ID"
}

errors()

The errors for the job, if any errors have occurred. Returns an array of hash objects. See error.

failed?()

Checks if an error is present.

job_id()

The ID of the job.

pending?()

Checks if the job's state is PENDING.

project_id()

The ID of the project containing the job.

refresh!()

Reloads the job with current data from the BigQuery service.

rerun!()

Created a new job with the current configuration.

running?()

Checks if the job's state is RUNNING.

started_at()

The time when the job was started. This field is present after the job's state changes from PENDING to either RUNNING or DONE.

state()

The current state of the job. The possible values are PENDING, RUNNING, and DONE. A DONE state does not mean that the job completed successfully. Use failed? to discover if an error occurred or if the job was successful.

statistics()

The statistics for the job. Returns a hash. See the Jobs API reference.

Also aliased as: stats

stats()

Alias for: statistics

status()

The job's status. Returns a hash. The values contained in the hash are also exposed by state, error, and errors.