Class BigQueryJob (2.4.0)

public sealed 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(CancellationToken))

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
Task<BigQueryJob>

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.

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(CancellationToken))

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
Task<BigQueryResults>

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(CancellationToken))

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
Task<BigQueryJob>

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

Returns this if the job has no errors, or throws an exception containing the errors. A job may have errors but still contain useful information, and may also contain errors before completing.

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.