@SuppressWarnings("unchecked") static <T extends JobStatistics> T fromPb(com.google.api.services.bigquery.model.Job jobPb) { JobConfiguration jobConfigPb = jobPb.getConfiguration(); com.google.api.services.bigquery.model.JobStatistics statisticPb = jobPb.getStatistics(); if (jobConfigPb.getLoad() != null) { return (T) LoadStatistics.fromPb(statisticPb); } else if (jobConfigPb.getExtract() != null) { return (T) ExtractStatistics.fromPb(statisticPb); } else if (jobConfigPb.getQuery() != null) { return (T) QueryStatistics.fromPb(statisticPb); } else if (jobConfigPb.getCopy() != null) { return (T) CopyStatistics.fromPb(statisticPb); } else { throw new IllegalArgumentException("unknown job configuration: " + jobConfigPb); } } }
BuilderImpl(Job jobPb) { this.etag = jobPb.getEtag(); this.generatedId = jobPb.getId(); if (jobPb.getJobReference() != null) { this.jobId = JobId.fromPb(jobPb.getJobReference()); } this.selfLink = jobPb.getSelfLink(); if (jobPb.getStatus() != null) { this.status = JobStatus.fromPb(jobPb.getStatus()); } if (jobPb.getStatistics() != null) { this.statistics = JobStatistics.fromPb(jobPb); } this.userEmail = jobPb.getUserEmail(); if (jobPb.getConfiguration() != null) { this.configuration = JobConfiguration.fromPb(jobPb.getConfiguration()); } }
static List<ResourceId> getExtractFilePaths(String extractDestinationDir, Job extractJob) throws IOException { JobStatistics jobStats = extractJob.getStatistics(); List<Long> counts = jobStats.getExtract().getDestinationUriFileCounts(); if (counts.size() != 1) { String errorMessage = (counts.isEmpty() ? "No destination uri file count received." : String.format( "More than one destination uri file count received. First two are %s, %s", counts.get(0), counts.get(1))); throw new RuntimeException(errorMessage); } long filesCount = counts.get(0); ImmutableList.Builder<ResourceId> paths = ImmutableList.builder(); ResourceId extractDestinationDirResourceId = FileSystems.matchNewResource(extractDestinationDir, true /* isDirectory */); for (long i = 0; i < filesCount; ++i) { ResourceId filePath = extractDestinationDirResourceId.resolve( String.format("%012d%s", i, ".avro"), ResolveOptions.StandardResolveOptions.RESOLVE_FILE); paths.add(filePath); } return paths.build(); }
switch (jobStatus) { case SUCCEEDED: LOG.info("Load job {} succeeded. Statistics: {}", currentJobId, job.getStatistics()); return true; case UNKNOWN:
BuilderImpl(Job jobPb) { this.etag = jobPb.getEtag(); this.generatedId = jobPb.getId(); if (jobPb.getJobReference() != null) { this.jobId = JobId.fromPb(jobPb.getJobReference()); } this.selfLink = jobPb.getSelfLink(); if (jobPb.getStatus() != null) { this.status = JobStatus.fromPb(jobPb.getStatus()); } if (jobPb.getStatistics() != null) { this.statistics = JobStatistics.fromPb(jobPb.getStatistics()); } this.userEmail = jobPb.getUserEmail(); this.configuration = JobConfiguration.fromPb(jobPb.getConfiguration()); }
BuilderImpl(Job jobPb) { this.etag = jobPb.getEtag(); this.generatedId = jobPb.getId(); if (jobPb.getJobReference() != null) { this.jobId = JobId.fromPb(jobPb.getJobReference()); } this.selfLink = jobPb.getSelfLink(); if (jobPb.getStatus() != null) { this.status = JobStatus.fromPb(jobPb.getStatus()); } if (jobPb.getStatistics() != null) { this.statistics = JobStatistics.fromPb(jobPb.getStatistics()); } this.userEmail = jobPb.getUserEmail(); this.configuration = JobConfiguration.fromPb(jobPb.getConfiguration()); }
@SuppressWarnings("unchecked") static <T extends JobStatistics> T fromPb(com.google.api.services.bigquery.model.Job jobPb) { JobConfiguration jobConfigPb = jobPb.getConfiguration(); com.google.api.services.bigquery.model.JobStatistics statisticPb = jobPb.getStatistics(); if (jobConfigPb.getLoad() != null) { return (T) LoadStatistics.fromPb(statisticPb); } else if (jobConfigPb.getExtract() != null) { return (T) ExtractStatistics.fromPb(statisticPb); } else if (jobConfigPb.getQuery() != null) { return (T) QueryStatistics.fromPb(statisticPb); } else if (jobConfigPb.getCopy() != null) { return (T) CopyStatistics.fromPb(statisticPb); } else { throw new IllegalArgumentException("unknown job configuration: " + jobConfigPb); } } }
@Override public JobStatistics dryRunQuery( String projectId, JobConfigurationQuery queryConfig, String location) throws InterruptedException, IOException { JobReference jobRef = new JobReference().setLocation(location).setProjectId(projectId); Job job = new Job() .setJobReference(jobRef) .setConfiguration(new JobConfiguration().setQuery(queryConfig).setDryRun(true)); return executeWithRetries( client.jobs().insert(projectId, job), String.format( "Unable to dry run query: %s, aborting after %d retries.", queryConfig, MAX_RPC_RETRIES), Sleeper.DEFAULT, createDefaultBackoff(), ALWAYS_RETRY) .getStatistics(); }
client.jobs().insert(projectId, dryRunJob), String.format("Error when trying to dry run query %s.", queryConfig.toPrettyString())).getStatistics();
BuilderImpl(Job jobPb) { this.etag = jobPb.getEtag(); this.generatedId = jobPb.getId(); if (jobPb.getJobReference() != null) { this.jobId = JobId.fromPb(jobPb.getJobReference()); } this.selfLink = jobPb.getSelfLink(); if (jobPb.getStatus() != null) { this.status = JobStatus.fromPb(jobPb.getStatus()); } if (jobPb.getStatistics() != null) { this.statistics = JobStatistics.fromPb(jobPb); } this.userEmail = jobPb.getUserEmail(); if (jobPb.getConfiguration() != null) { this.configuration = JobConfiguration.fromPb(jobPb.getConfiguration()); } }