Google BigQuery v2 API - Class BigQueryJob (3.8.0)

public sealed class BigQueryJob

Reference documentation and code samples for the Google BigQuery v2 API class BigQueryJob.

An asynchronous job within BigQuery.

Inheritance

object > BigQueryJob

Namespace

Google.Cloud.BigQuery.V2

Assembly

Google.Cloud.BigQuery.V2.dll

Remarks

This class wraps the underlying REST API resource and retains a reference to the original client, allowing for simpler job-oriented operations.

Constructors

BigQueryJob(BigQueryClient, Job)

public BigQueryJob(BigQueryClient client, Job resource)

Constructs a new job.

Parameters
NameDescription
clientBigQueryClient

The client to use for operations on the job. Must not be null.

resourceJob

The REST-ful resource representing the job. Must not be null.

Remarks

This is public to allow tests to construct instances for production code to consume; production code should not normally construct instances itself.

Properties

Reference

public JobReference Reference { get; }

The fully-qualified identifier for the job. This is short-hand for Resource.JobReference.

Property Value
TypeDescription
JobReference
Remarks

The properties within the reference can be used to determine the project ID and job ID components.

Resource

public Job Resource { get; }

The underlying REST-ful resource for the job.

Property Value
TypeDescription
Job
Remarks

The data within the resource may be incomplete, depending on how it was obtained.

State

public JobState State { get; }

The state of the job.

Property Value
TypeDescription
JobState

Statistics

public JobStatistics Statistics { get; }

The statistics of the job. This is short-hand for Resource.Statistics.

Property Value
TypeDescription
JobStatistics

Status

public JobStatus Status { get; }

The full status of the job, including any errors. This is short-hand for Resource.Status.

Property Value
TypeDescription
JobStatus

Methods

Cancel(CancelJobOptions)

public BigQueryJob Cancel(CancelJobOptions options = null)

Cancels this job. This method just creates a JobReference and delegates to CancelJob(JobReference, CancelJobOptions).

Parameter
NameDescription
optionsCancelJobOptions

The options for the operation. May be null, in which case defaults will be supplied.

Returns
TypeDescription
BigQueryJob

The final state of the job.

Example

See BigQueryClient.CancelJob for an example using BigQueryClient.

CancelAsync(CancelJobOptions, CancellationToken)

public Task<BigQueryJob> CancelAsync(CancelJobOptions options = null, CancellationToken cancellationToken = default)

Asynchronously cancels this job. This method just creates a JobReference and delegates to CancelJobAsync(JobReference, CancelJobOptions, CancellationToken).

Parameters
NameDescription
optionsCancelJobOptions

The options for the operation. May be null, in which case defaults will be supplied.

cancellationTokenCancellationToken

The token to monitor for cancellation requests.

Returns
TypeDescription
TaskBigQueryJob

A task representing the asynchronous operation. When complete, the result is the final state of the job.

Example

See BigQueryClient.CancelJob for an example using BigQueryClient.

Delete(DeleteJobOptions)

public void Delete(DeleteJobOptions options = null)

Deletes this job. This method just creates a JobReference and delegates to DeleteJob(JobReference, DeleteJobOptions).

Parameter
NameDescription
optionsDeleteJobOptions

The options for the operation. May be null, in which case defaults will be supplied.

DeleteAsync(DeleteJobOptions, CancellationToken)

public Task DeleteAsync(DeleteJobOptions options = null, CancellationToken cancellationToken = default)

Asynchronously deletes this job. This method just creates a JobReference and delegates to DeleteJobAsync(JobReference, DeleteJobOptions, CancellationToken).

Parameters
NameDescription
optionsDeleteJobOptions

The options for the operation. May be null, in which case defaults will be supplied.

cancellationTokenCancellationToken

The token to monitor for cancellation requests.

Returns
TypeDescription
Task

A task representing the asynchronous operation. When complete, the result is the final state of the job.

GetQueryResults(GetQueryResultsOptions)

public BigQueryResults GetQueryResults(GetQueryResultsOptions options = null)

Retrieves the result of this job, which must be a query job. This method just creates a JobReference and delegates to GetQueryResults(JobReference, GetQueryResultsOptions).

Parameter
NameDescription
optionsGetQueryResultsOptions

The options for the operation. May be null, in which case defaults will be supplied.

Returns
TypeDescription
BigQueryResults

The result of the query.

Remarks

This method will only return when the query has completed.

Example

See BigQueryClient.GetQueryResults for an example using BigQueryClient.

GetQueryResultsAsync(GetQueryResultsOptions, CancellationToken)

public Task<BigQueryResults> GetQueryResultsAsync(GetQueryResultsOptions options = null, CancellationToken cancellationToken = default)

Asynchronously retrieves the result of this job, which must be a query job. This method just creates a JobReference and delegates to GetQueryResultsAsync(JobReference, GetQueryResultsOptions, CancellationToken).

Parameters
NameDescription
optionsGetQueryResultsOptions

The options for the operation. May be null, in which case defaults will be supplied.

cancellationTokenCancellationToken

The token to monitor for cancellation requests.

Returns
TypeDescription
TaskBigQueryResults

A task representing the asynchronous operation. When complete, the result is a BigQueryResults representation of the query.

Remarks

The task returned by this method will only complete when the query has completed.

Example

See BigQueryClient.GetQueryResultsAsync for an example using BigQueryClient.

PollUntilCompleted(GetJobOptions, PollSettings)

public BigQueryJob PollUntilCompleted(GetJobOptions options = null, PollSettings pollSettings = null)

Polls this job for completion, returning a new BigQueryJob object with the updated information. This method just creates a JobReference and delegates to PollJobUntilCompleted(JobReference, GetJobOptions, PollSettings).

Parameters
NameDescription
optionsGetJobOptions

The options for the operation. May be null, in which case defaults will be supplied.

pollSettingsPollSettings

The settings to control how often and long the job is fetched before timing out if it is still incomplete. May be null, in which case defaults will be supplied.

Returns
TypeDescription
BigQueryJob

The completed job.

Remarks

Note that this method does not modify the state of the object it is called on. Instead, a new object is returned. If you need to check that the job completed without errors, or access any other information, you need to use the return value of the method.

Example

See BigQueryClient.PollJobUntilCompleted for an example using BigQueryClient.

PollUntilCompletedAsync(GetJobOptions, PollSettings, CancellationToken)

public Task<BigQueryJob> PollUntilCompletedAsync(GetJobOptions options = null, PollSettings pollSettings = null, CancellationToken cancellationToken = default)

Asynchronously polls this job for completion. This method just creates a JobReference and delegates to PollJobUntilCompletedAsync(JobReference, GetJobOptions, PollSettings, CancellationToken).

Parameters
NameDescription
optionsGetJobOptions

The options for the operation. May be null, in which case defaults will be supplied.

pollSettingsPollSettings

The settings to control how often and long the job is fetched before timing out if it is still incomplete. May be null, in which case defaults will be supplied.

cancellationTokenCancellationToken

The token to monitor for cancellation requests.

Returns
TypeDescription
TaskBigQueryJob

A task representing the asynchronous operation. When complete, the result is the completed job.

Example

See BigQueryClient.PollJobUntilCompleted for an example using BigQueryClient.

ThrowOnAnyError()

public BigQueryJob ThrowOnAnyError()

Throws an exception if the job has any errors, or returns this if the job has no errors so far. A job may have errors but still contain useful information, and may also contain errors before completing. If this method is called on a job that completed successfully but with errors, it will throw an exception. Use ThrowOnFatalError() to only throw an exception if a job has failed.

Returns
TypeDescription
BigQueryJob

this if the job has no errors.

Example
BigQueryClient client = BigQueryClient.Create(projectId);

string sql = $"This is a broken query";
BigQueryJob query = client.CreateQueryJob(sql, parameters: null).PollUntilCompleted();
try
{
    // Usually this method is called in a chain. It returns the same job
    // if there are no errors.
    query = query.ThrowOnAnyError();
}
catch (GoogleApiException exception)
{
    foreach (var error in exception.Error.Errors)
    {
        Console.WriteLine($"Location: {error.Location}; Reason: {error.Reason}; Message: {error.Message}");
    }
}
Exceptions
TypeDescription
GoogleApiException

The job has errors. The Errors property corresponds to the errors reported in Errors.

ThrowOnFatalError()

public BigQueryJob ThrowOnFatalError()

Throws an exception if the job has failed. Returns this if the job has not failed, even if it contains errors. A job may have errors but still contain useful information, and may also contain errors before completing. Use ThrowOnAnyError() to throw an exception if any errors have been reported.

Returns
TypeDescription
BigQueryJob

this if the job has not completed unsuccessfully (either because it hasn't completed, or it has completed successfully, potentially with non-fatal errors).

Exceptions
TypeDescription
GoogleApiException

The job has failed. Within the Errors property, the first error is from the ErrorResult, and any others are from Errors.