@VisibleForTesting public Job getJob(JobReference jobRef, Sleeper sleeper, BackOff backoff) throws IOException, InterruptedException { String jobId = jobRef.getJobId(); Exception lastException; do { try { return client.jobs().get(jobRef.getProjectId(), jobId).execute(); } catch (GoogleJsonResponseException e) { if (errorExtractor.itemNotFound(e)) { LOG.info("No BigQuery job with job id {} found.", jobId); return null; } LOG.info( "Ignoring the error encountered while trying to query the BigQuery job {}", jobId, e); lastException = e; } catch (IOException e) { LOG.info( "Ignoring the error encountered while trying to query the BigQuery job {}", jobId, e); lastException = e; } } while (nextBackOff(sleeper, backoff)); throw new IOException( String.format( "Unable to find BigQuery job: %s, aborting after %d retries.", jobRef, MAX_RPC_RETRIES), lastException); } }
/** * Polls the status of a BigQuery job, returns Job reference if "Done" * * @param bigquery an authorized BigQuery client * @param projectId a string containing the current project ID * @param jobId a reference to an inserted query Job * @return a reference to the completed Job * @throws IOException * @throws InterruptedException */ private static Job checkQueryResults(Bigquery bigquery, String projectId, JobReference jobId) throws IOException, InterruptedException { // Variables to keep track of total query time long startTime = System.currentTimeMillis(); long elapsedTime; while (true) { Job pollJob = bigquery.jobs().get(projectId, jobId.getJobId()).execute(); elapsedTime = System.currentTimeMillis() - startTime; System.out.format("Job status (%dms) %s: %s\n", elapsedTime, jobId.getJobId(), pollJob.getStatus().getState()); if (pollJob.getStatus().getState().equals("DONE")) { return pollJob; } // Pause execution for one second before polling job status again, to // reduce unnecessary calls to the BigQUery API and lower overall // application bandwidth. Thread.sleep(1000); } } // [END start_query]
.get(jobRef.getProjectId(), jobRef.getJobId()) .setLocation(jobRef.getLocation()) .execute(); if (job == null) { LOG.info("Still waiting for BigQuery job {} to start", jobRef);
"Fetching existing job after catching exception for duplicate jobId '%s'", job.getJobReference().getJobId()); response = service.jobs().get(projectId, job.getJobReference().getJobId()).execute(); } else { throw new IOException(
@Override public Job getJob(String projectId, String jobId, String location, Map<Option, ?> options) { try { return bigquery .jobs() .get(projectId, jobId) .setLocation(location) .setFields(Option.FIELDS.getString(options)) .execute(); } catch (IOException ex) { BigQueryException serviceException = translate(ex); if (serviceException.getCode() == HTTP_NOT_FOUND) { return null; } throw serviceException; } }
@Override public Job getJob(String jobId, Map<Option, ?> options) { try { return bigquery.jobs() .get(this.options.projectId(), jobId) .setFields(FIELDS.getString(options)) .execute(); } catch (IOException ex) { BigQueryException serviceException = translate(ex); if (serviceException.code() == HTTP_NOT_FOUND) { return null; } throw serviceException; } }
@Override public Job getJob(String jobId, Map<Option, ?> options) { try { return bigquery.jobs() .get(this.options.projectId(), jobId) .setFields(FIELDS.getString(options)) .execute(); } catch (IOException ex) { BigQueryException serviceException = translate(ex); if (serviceException.code() == HTTP_NOT_FOUND) { return null; } throw serviceException; } }
public Job listJob(HttpServletResponse resp, Bigquery bigquery, String jobId) throws IOException { Bigquery.Projects.List projectRequest = bigquery.projects().list(); ProjectList projectResponse = projectRequest.execute(); if (projectResponse.getTotalItems() == 0) { return null; } Projects project = projectResponse.getProjects().get(0); Get jobsRequest = bigquery.jobs().get(project.getId(), jobId); Job j = jobsRequest.execute(); return j; } }
Job jobStatus(String projectId, String jobId) throws IOException { return client.jobs() .get(projectId, jobId) .execute(); }
@Override public Job getJob(String projectId, String jobId, String location, Map<Option, ?> options) { try { return bigquery .jobs() .get(projectId, jobId) .setLocation(location) .setFields(Option.FIELDS.getString(options)) .execute(); } catch (IOException ex) { BigQueryException serviceException = translate(ex); if (serviceException.getCode() == HTTP_NOT_FOUND) { return null; } throw serviceException; } }