public class Job extends JobInfo
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
.
Modifier and Type | Class and Description |
---|---|
static class |
Job.Builder
A builder for
Job objects. |
JobInfo.CreateDisposition, JobInfo.SchemaUpdateOption, JobInfo.WriteDisposition
Modifier and Type | Method and Description |
---|---|
boolean |
cancel()
Sends a job cancel request.
|
boolean |
equals(Object obj) |
boolean |
exists()
Checks if this job exists.
|
BigQuery |
getBigquery()
Returns the job's
BigQuery object used to issue requests. |
QueryResponse |
getQueryResults(BigQuery.QueryResultsOption... options)
Gets the query results of this job.
|
int |
hashCode() |
boolean |
isDone()
Checks if this job has completed its execution, either failing or succeeding.
|
Job |
reload(BigQuery.JobOption... options)
Fetches current job's latest information.
|
Job.Builder |
toBuilder()
Returns a builder for the job object.
|
Job |
waitFor(RetryOption... waitOptions)
Blocks until this job completes its execution, either failing or succeeding.
|
getConfiguration, getEtag, getGeneratedId, getJobId, getSelfLink, getStatistics, getStatus, getUserEmail, newBuilder, of, of, toString
public boolean exists()
Example of checking that a job exists.
if (!job.exists()) {
// job doesn't exist
}
true
if this job exists, false
otherwiseBigQueryException
- upon failurepublic boolean isDone()
true
.
Example of waiting for a job until it reports that it is done.
while (!job.isDone()) {
Thread.sleep(1000L);
}
true
if this job is in JobStatus.State.DONE
state or if it does not
exist, false
if the state is not JobStatus.State.DONE
BigQueryException
- upon failurepublic Job waitFor(RetryOption... waitOptions) throws InterruptedException
null
. 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.
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 non-jittered custom max delay and total timeout.
Job completedJob =
job.waitFor(
RetryOption.maxRetryDelay(Duration.ofSeconds(30)),
RetryOption.totalTimeout(Duration.ofMinutes(1)),
RetryOption.jittered(false));
if (completedJob == null) {
// job no longer exists
} else if (completedJob.getStatus().getError() != null) {
// job failed, handle error
} else {
// job completed successfully
}
waitOptions
- options to configure checking period and timeoutBigQueryException
- upon failure, check Throwable.getCause()
for detailsInterruptedException
- if the current thread gets interrupted while waiting for the job
to completepublic QueryResponse getQueryResults(BigQuery.QueryResultsOption... options)
JobConfiguration.Type.QUERY
, otherwise this method will throw UnsupportedOperationException
. This method does not wait for the job to complete, to ensure that the job is completed first call waitFor(RetryOption...)
method.
Example of getting the results of a query job.
Job job = bigquery.create(queryJobInfo);
job.waitFor();
QueryResponse response = job.getQueryResults();
QueryResult result = response.getResult();
for (FieldValueList row : result.iterateAll()) {
// do something with the data
}
BigQueryException
- upon failurepublic Job reload(BigQuery.JobOption... options)
null
if the job does not exist.
Example of reloading all fields until job status is DONE.
while (job.getStatus().getState() != JobStatus.State.DONE) {
Thread.sleep(1000L);
job = job.reload();
}
Example of reloading status field until job status is DONE.
while (job.getStatus().getState() != JobStatus.State.DONE) {
Thread.sleep(1000L);
job = job.reload(BigQuery.JobOption.fields(BigQuery.JobField.STATUS));
}
options
- job optionsJob
object with latest information or null
if not foundBigQueryException
- upon failurepublic boolean cancel()
Example of cancelling a job.
if (job.cancel()) {
return true; // job successfully cancelled
} else {
// job not found
}
true
if cancel request was sent successfully, false
if job was not
foundBigQueryException
- upon failurepublic BigQuery getBigquery()
BigQuery
object used to issue requests.public Job.Builder toBuilder()
JobInfo
Copyright © 2017 Google. All rights reserved.