Reference documentation and code samples for the BigQuery API class Google::Cloud::Bigquery::Job.
Job
Represents a generic Job that may be performed on a Table.
The subclasses of Job represent the specific BigQuery job types: CopyJob, ExtractJob, LoadJob, and QueryJob.
A job instance is created when you call Project#query_job, Dataset#query_job, Table#copy_job, Table#extract_job, Table#load_job.
Inherits
- Object
Example
require "google/cloud/bigquery" bigquery = Google::Cloud::Bigquery.new job = bigquery.query_job "SELECT COUNT(word) as count FROM " \ "`bigquery-public-data.samples.shakespeare`" job.wait_until_done! if job.failed? puts job.error else puts job.data.first end
Methods
#cancel
def cancel()Cancels the job.
require "google/cloud/bigquery" bigquery = Google::Cloud::Bigquery.new query = "SELECT COUNT(word) as count FROM " \ "`bigquery-public-data.samples.shakespeare`" job = bigquery.query_job query job.cancel
#config
def config()The configuration for the job. Returns a hash.
#configuration
def configuration()The configuration for the job. Returns a hash.
#created_at
def created_at() -> Time, nilThe time when the job was created.
- (Time, nil) — The creation time from the job statistics.
#delete
def delete() -> BooleanRequests that a job is deleted. This call will return when the job is deleted.
-
(Boolean) — Returns
trueif the job was deleted.
require "google/cloud/bigquery" bigquery = Google::Cloud::Bigquery.new job = bigquery.job "my_job" job.delete
#done?
def done?() -> BooleanChecks 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.
-
(Boolean) —
truewhenDONE,falseotherwise.
#ended_at
def ended_at() -> Time, nilThe time when the job ended.
This field is present when the job's state is DONE.
- (Time, nil) — The end time from the job statistics.
#error
def error() -> Hash, nilThe last error for the job, if any errors have occurred. Returns a hash.
-
(Hash, nil) — Returns a hash containing
reasonandmessagekeys:{ "reason"=>"notFound", "message"=>"Not found: Table bigquery-public-data:samples.BAD_ID" }
#errors
def errors() -> Array<Hash>, nilThe errors for the job, if any errors have occurred. Returns an array of hash objects. See #error.
-
(Array<Hash>, nil) — Returns an array of hashes containing
reasonandmessagekeys:{ "reason"=>"notFound", "message"=>"Not found: Table bigquery-public-data:samples.BAD_ID" }
#failed?
def failed?() -> BooleanChecks if an error is present. Use #error to access the error object.
-
(Boolean) —
truewhen there is an error,falseotherwise.
#job_id
def job_id() -> StringThe ID of the job.
-
(String) — The ID must contain only letters (
[A-Za-z]), numbers ([0-9]), underscores (_), or dashes (-). The maximum length is 1,024 characters.
#labels
def labels() -> HashA hash of user-provided labels associated with this job. Labels can be provided when the job is created, and used to organize and group jobs.
The returned hash is frozen and changes are not allowed. Use CopyJob::Updater#labels= or ExtractJob::Updater#labels= or LoadJob::Updater#labels= or QueryJob::Updater#labels= to replace the entire hash.
- (Hash) — The job labels.
#location
def location() -> StringThe geographic location where the job runs.
- (String) — A geographic location, such as "US", "EU" or "asia-northeast1".
#num_child_jobs
def num_child_jobs() -> IntegerThe number of child jobs executed.
- (Integer) — The number of child jobs executed.
#parent_job_id
def parent_job_id() -> String, nilIf this is a child job, the id of the parent.
-
(String, nil) — The ID of the parent job, or
nilif not a child job.
#pending?
def pending?() -> BooleanChecks if the job's state is PENDING.
-
(Boolean) —
truewhenPENDING,falseotherwise.
#project_id
def project_id() -> StringThe ID of the project containing the job.
- (String) — The project ID.
#refresh!
def refresh!()Reloads the job with current data from the BigQuery service.
require "google/cloud/bigquery" bigquery = Google::Cloud::Bigquery.new query = "SELECT COUNT(word) as count FROM " \ "`bigquery-public-data.samples.shakespeare`" job = bigquery.query_job query job.done? job.reload! job.done? #=> true
#reload!
def reload!()Reloads the job with current data from the BigQuery service.
require "google/cloud/bigquery" bigquery = Google::Cloud::Bigquery.new query = "SELECT COUNT(word) as count FROM " \ "`bigquery-public-data.samples.shakespeare`" job = bigquery.query_job query job.done? job.reload! job.done? #=> true
#rerun!
def rerun!()Created a new job with the current configuration.
require "google/cloud/bigquery" bigquery = Google::Cloud::Bigquery.new query = "SELECT COUNT(word) as count FROM " \ "`bigquery-public-data.samples.shakespeare`" job = bigquery.query_job query job.wait_until_done! job.rerun!
#reservation_usage
def reservation_usage() -> Array<Google::Cloud::Bigquery::Job::ReservationUsage>, nilAn array containing the job resource usage breakdown by reservation, if present. Reservation usage statistics are only reported for jobs that are executed within reservations. On-demand jobs do not report this data.
- (Array<Google::Cloud::Bigquery::Job::ReservationUsage>, nil) — The reservation usage, if present.
#running?
def running?() -> BooleanChecks if the job's state is RUNNING.
-
(Boolean) —
truewhenRUNNING,falseotherwise.
#script_statistics
def script_statistics() -> Google::Cloud::Bigquery::Job::ScriptStatistics, nilThe statistics including stack frames for a child job of a script.
-
(Google::Cloud::Bigquery::Job::ScriptStatistics, nil) — The script statistics, or
nilif the job is not a child job.
require "google/cloud/bigquery" bigquery = Google::Cloud::Bigquery.new multi_statement_sql = <<~SQL -- Declare a variable to hold names as an array. DECLARE top_names ARRAY<STRING>; -- Build an array of the top 100 names from the year 2017. SET top_names = ( SELECT ARRAY_AGG(name ORDER BY number DESC LIMIT 100) FROM `bigquery-public-data.usa_names.usa_1910_current` WHERE year = 2017 ); -- Which names appear as words in Shakespeare's plays? SELECT name AS shakespeare_name FROM UNNEST(top_names) AS name WHERE name IN ( SELECT word FROM `bigquery-public-data.samples.shakespeare` ); SQL job = bigquery.query_job multi_statement_sql job.wait_until_done! child_jobs = bigquery.jobs parent_job: job child_jobs.each do |child_job| script_statistics = child_job.script_statistics puts script_statistics.evaluation_kind script_statistics.stack_frames.each do |stack_frame| puts stack_frame.text end end
#session_id
def session_id() -> String, nilThe ID of the session if this job is part of one. See the create_session param in Project#query_job and
Dataset#query_job.
-
(String, nil) — The session ID, or
nilif not associated with a session.
#started_at
def started_at() -> Time, nilThe time when the job was started.
This field is present after the job's state changes from PENDING
to either RUNNING or DONE.
- (Time, nil) — The start time from the job statistics.
#state
def state() -> StringThe current state of the job. 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.
-
(String) — The state code. The possible values are
PENDING,RUNNING, andDONE.
#statistics
def statistics() -> HashThe statistics for the job. Returns a hash.
- (Hash) — The job statistics.
#stats
def stats() -> HashThe statistics for the job. Returns a hash.
- (Hash) — The job statistics.
#status
def status() -> HashThe job's status. Returns a hash. The values contained in the hash are also exposed by #state, #error, and #errors.
- (Hash) — The job status.
#transaction_id
def transaction_id() -> String, nilThe ID of a multi-statement transaction.
-
(String, nil) — The transaction ID, or
nilif not associated with a transaction.
#user_email
def user_email() -> StringThe email address of the user who ran the job.
- (String) — The email address.
#wait_until_done!
def wait_until_done!()Refreshes the job until the job is DONE. The delay between refreshes
starts at 5 seconds and increases exponentially to a maximum of 60
seconds.
require "google/cloud/bigquery" bigquery = Google::Cloud::Bigquery.new dataset = bigquery.dataset "my_dataset" table = dataset.table "my_table" extract_job = table.extract_job "gs://my-bucket/file-name.json", format: "json" extract_job.wait_until_done! extract_job.done? #=> true