Class Job
- All Implemented Interfaces:
Serializable
Objects of this class are immutable. To get a Job object with the most recent
information use reload(com.google.cloud.bigquery.BigQuery.JobOption...). Job adds a layer of service-related functionality over
JobInfo.
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class com.google.cloud.bigquery.JobInfo
JobInfo.CreateDisposition, JobInfo.SchemaUpdateOption, JobInfo.WriteDisposition -
Method Summary
Modifier and TypeMethodDescriptionbooleancancel()Sends a job cancel request.final booleanbooleanexists()Checks if this job exists.Returns the job'sBigQueryobject used to issue requests.getQueryResults(BigQuery.QueryResultsOption... options) Gets the query results of this job.final inthashCode()booleanisDone()Checks if this job has completed its execution, either failing or succeeding.reload(BigQuery.JobOption... options) Fetches current job's latest information.Returns a builder for the job object.waitFor(BigQueryRetryConfig bigQueryRetryConfig, com.google.cloud.RetryOption... waitOptions) Blocks until this job completes its execution, either failing or succeeding.waitFor(com.google.cloud.RetryOption... waitOptions) Methods inherited from class com.google.cloud.bigquery.JobInfo
getConfiguration, getEtag, getGeneratedId, getJobId, getSelfLink, getStatistics, getStatus, getUserEmail, newBuilder, of, of, toString
-
Method Details
-
exists
public boolean exists()Checks if this job exists.Example of checking that a job exists.
if (!job.exists()) { // job doesn't exist }- Returns:
trueif this job exists,falseotherwise- Throws:
BigQueryException- upon failure
-
isDone
public boolean isDone()Checks if this job has completed its execution, either failing or succeeding. If the job does not exist this method returnstrue.Example of waiting for a job until it reports that it is done.
while (!job.isDone()) { Thread.sleep(1000L); }- Returns:
trueif this job is inJobStatus.State.DONEstate or if it does not exist,falseif the state is notJobStatus.State.DONE- Throws:
BigQueryException- upon failure
-
waitFor
- Throws:
InterruptedException
-
waitFor
public Job waitFor(BigQueryRetryConfig bigQueryRetryConfig, com.google.cloud.RetryOption... waitOptions) throws InterruptedException Blocks until this job completes its execution, either failing or succeeding. This method returns current job's latest information. If the job no longer exists, this method returnsnull. By default, the job status is checked using jittered exponential backoff with 1 second as an initial delay, 2.0 as a backoff factor, 1 minute as maximum delay between polls, 12 hours as a total timeout and unlimited number of attempts. For query jobs, the job status check can be configured to retry on specific BigQuery error messages usingBigQueryRetryConfig. ThisBigQueryRetryConfigconfiguration is not available for non-query jobs.Example usage of
waitFor().Job completedJob = job.waitFor(); if (completedJob == null) { // job no longer exists } else if (completedJob.getStatus().getError() != null) { // job failed, handle error } else { // job completed successfully }Example usage of
waitFor()with checking period and timeout.Job completedJob = job.waitFor( RetryOption.initialRetryDelay(Duration.ofSeconds(1)), RetryOption.totalTimeout(Duration.ofMinutes(1))); if (completedJob == null) { // job no longer exists } else if (completedJob.getStatus().getError() != null) { // job failed, handle error } else { // job completed successfully }Example usage of
waitFor()with BigQuery retry configuration to retry on rate limit exceeded error messages for query jobs.Job completedJob = job.waitFor( BigQueryRetryConfig.newBuilder() .retryOnMessage(BigQueryErrorMessages.RATE_LIMIT_EXCEEDED_MSG) .retryOnMessage(BigQueryErrorMessages.JOB_RATE_LIMIT_EXCEEDED_MSG) .retryOnRegEx(BigQueryErrorMessages.RetryRegExPatterns.RATE_LIMIT_EXCEEDED_REGEX) .build()); if (completedJob == null) { // job no longer exists } else if (completedJob.getStatus().getError() != null) { // job failed, handle error } else { // job completed successfully }- Parameters:
bigQueryRetryConfig- configures retries for query jobs for BigQuery failureswaitOptions- options to configure checking period and timeout- Throws:
BigQueryException- upon failure, checkThrowable.getCause()for detailsInterruptedException- if the current thread gets interrupted while waiting for the job to complete
-
getQueryResults
public TableResult getQueryResults(BigQuery.QueryResultsOption... options) throws InterruptedException, JobException Gets the query results of this job. This job must be of typeJobConfiguration.Type.QUERY, otherwise this method will throwUnsupportedOperationException.If the job hasn't finished, this method waits for the job to complete. However, the state of the current
Jobinstance is not updated. To get the new state, callwaitFor(RetryOption...)orreload(JobOption...).- Throws:
BigQueryException- upon failureInterruptedExceptionJobException
-
reload
Fetches current job's latest information. Returnsnullif the job does not exist.Example of reloading all fields until job status is DONE.
while (!JobStatus.State.DONE.equals(job.getStatus().getState())) { Thread.sleep(1000L); job = job.reload(); }Example of reloading status field until job status is DONE.
while (!JobStatus.State.DONE.equals(job.getStatus().getState())) { Thread.sleep(1000L); job = job.reload(BigQuery.JobOption.fields(BigQuery.JobField.STATUS)); }- Parameters:
options- job options- Returns:
- a
Jobobject with latest information ornullif not found - Throws:
BigQueryException- upon failure
-
cancel
public boolean cancel()Sends a job cancel request.Example of cancelling a job.
if (job.cancel()) { return true; // job successfully cancelled } else { // job not found }- Returns:
trueif cancel request was sent successfully,falseif job was not found- Throws:
BigQueryException- upon failure
-
getBigQuery
Returns the job'sBigQueryobject used to issue requests. -
toBuilder
Description copied from class:JobInfoReturns a builder for the job object. -
equals
-
hashCode
public final int hashCode()
-