Java Code Examples for com.google.api.services.bigquery.model.JobStatus#getErrors()

The following examples show how to use com.google.api.services.bigquery.model.JobStatus#getErrors() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BigqueryConnection.java    From nomulus with Apache License 2.0 6 votes vote down vote up
/**
 * Checks completed job for errors.
 *
 * @throws BigqueryJobFailureException
 */
private static Job checkJob(Job job) {
  verify(job.getStatus() != null);
  JobStatus jobStatus = job.getStatus();
  if (jobStatus.getErrorResult() != null) {
    throw BigqueryJobFailureException.create(jobStatus);
  } else {
    logger.atInfo().log(summarizeCompletedJob(job));
    if (jobStatus.getErrors() != null) {
      for (ErrorProto error : jobStatus.getErrors()) {
        logger.atWarning().log("%s: %s", error.getReason(), error.getMessage());
      }
    }
    return job;
  }
}
 
Example 2
Source File: BigQueryHelpers.java    From beam with Apache License 2.0 5 votes vote down vote up
static Status parseStatus(@Nullable Job job) {
  if (job == null) {
    return Status.UNKNOWN;
  }
  JobStatus status = job.getStatus();
  if (status.getErrorResult() != null) {
    return Status.FAILED;
  } else if (status.getErrors() != null && !status.getErrors().isEmpty()) {
    return Status.FAILED;
  } else {
    return Status.SUCCEEDED;
  }
}
 
Example 3
Source File: BigQueryHelpers.java    From beam with Apache License 2.0 4 votes vote down vote up
static RetryJobIdResult getRetryJobId(
    RetryJobId currentJobId, SerializableFunction<RetryJobId, Job> lookupJob) {
  for (int retryIndex = currentJobId.getRetryIndex(); ; retryIndex++) {
    RetryJobId jobId = new RetryJobId(currentJobId.getJobIdPrefix(), retryIndex);
    try {
      Job loadJob = lookupJob.apply(jobId);
      if (loadJob == null) {
        LOG.info("job id {} not found, so retrying with that id", jobId);
        // This either means that the original job was never properly issued (on the first
        // iteration of the loop) or that we've found a retry id that has not been used yet. Try
        // again with this job id.
        return new RetryJobIdResult(jobId, true);
      }
      JobStatus jobStatus = loadJob.getStatus();
      if (jobStatus == null) {
        LOG.info("job status for {} not found, so retrying with that job id", jobId);
        return new RetryJobIdResult(jobId, true);
      }
      if ("PENDING".equals(jobStatus.getState()) || "RUNNING".equals(jobStatus.getState())) {
        // The job id has been issued and is currently pending. This can happen after receiving
        // an error from the load or copy job creation (e.g. that error might come because the
        // job already exists). Return to the caller which job id is pending (it might not be the
        // one passed in) so the caller can then wait for this job to finish.
        LOG.info("job {} in pending or running state, so continuing with that job id", jobId);
        return new RetryJobIdResult(jobId, false);
      }
      if (jobStatus.getErrorResult() == null
          && (jobStatus.getErrors() == null || jobStatus.getErrors().isEmpty())) {
        // Import succeeded. No retry needed.
        LOG.info("job {} succeeded, so not retrying ", jobId);
        return new RetryJobIdResult(jobId, false);
      }
      // This job has failed, so we assume the data cannot enter BigQuery. We will check the next
      // job in the sequence (with the same unique prefix) to see if is either pending/succeeded
      // or can be used to generate a retry job.
      LOG.info("job {} is failed. Checking the next job id", jobId);
    } catch (RuntimeException e) {
      LOG.info("caught exception while querying job {}", jobId);
      return new RetryJobIdResult(jobId, true);
    }
  }
}