use of com.google.api.services.bigquery.model.JobConfigurationTableCopy in project beam by apache.
the class WriteRename method copy.
private void copy(JobService jobService, DatasetService datasetService, String jobIdPrefix, TableReference ref, List<TableReference> tempTables, WriteDisposition writeDisposition, CreateDisposition createDisposition, @Nullable String tableDescription) throws InterruptedException, IOException {
JobConfigurationTableCopy copyConfig = new JobConfigurationTableCopy().setSourceTables(tempTables).setDestinationTable(ref).setWriteDisposition(writeDisposition.name()).setCreateDisposition(createDisposition.name());
String projectId = ref.getProjectId();
Job lastFailedCopyJob = null;
for (int i = 0; i < BatchLoads.MAX_RETRY_JOBS; ++i) {
String jobId = jobIdPrefix + "-" + i;
JobReference jobRef = new JobReference().setProjectId(projectId).setJobId(jobId);
jobService.startCopyJob(jobRef, copyConfig);
Job copyJob = jobService.pollJob(jobRef, BatchLoads.LOAD_JOB_POLL_MAX_RETRIES);
Status jobStatus = BigQueryHelpers.parseStatus(copyJob);
switch(jobStatus) {
case SUCCEEDED:
if (tableDescription != null) {
datasetService.patchTableDescription(ref, tableDescription);
}
return;
case UNKNOWN:
throw new RuntimeException(String.format("UNKNOWN status of copy job [%s]: %s.", jobId, BigQueryHelpers.jobToPrettyString(copyJob)));
case FAILED:
lastFailedCopyJob = copyJob;
continue;
default:
throw new IllegalStateException(String.format("Unexpected status [%s] of load job: %s.", jobStatus, BigQueryHelpers.jobToPrettyString(copyJob)));
}
}
throw new RuntimeException(String.format("Failed to create copy job with id prefix %s, " + "reached max retries: %d, last failed copy job: %s.", jobIdPrefix, BatchLoads.MAX_RETRY_JOBS, BigQueryHelpers.jobToPrettyString(lastFailedCopyJob)));
}
use of com.google.api.services.bigquery.model.JobConfigurationTableCopy in project google-cloud-java by GoogleCloudPlatform.
the class CopyJobConfiguration method toPb.
@Override
com.google.api.services.bigquery.model.JobConfiguration toPb() {
JobConfigurationTableCopy configurationPb = new JobConfigurationTableCopy();
configurationPb.setDestinationTable(destinationTable.toPb());
if (sourceTables.size() == 1) {
configurationPb.setSourceTable(sourceTables.get(0).toPb());
} else {
configurationPb.setSourceTables(Lists.transform(sourceTables, TableId.TO_PB_FUNCTION));
}
if (createDisposition != null) {
configurationPb.setCreateDisposition(createDisposition.toString());
}
if (writeDisposition != null) {
configurationPb.setWriteDisposition(writeDisposition.toString());
}
return new com.google.api.services.bigquery.model.JobConfiguration().setCopy(configurationPb);
}
Aggregations