Search in sources :

Example 1 with JobConfigurationTableCopy

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)));
}
Also used : Status(org.apache.beam.sdk.io.gcp.bigquery.BigQueryHelpers.Status) JobReference(com.google.api.services.bigquery.model.JobReference) JobConfigurationTableCopy(com.google.api.services.bigquery.model.JobConfigurationTableCopy) Job(com.google.api.services.bigquery.model.Job)

Example 2 with JobConfigurationTableCopy

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);
}
Also used : JobConfigurationTableCopy(com.google.api.services.bigquery.model.JobConfigurationTableCopy)

Aggregations

JobConfigurationTableCopy (com.google.api.services.bigquery.model.JobConfigurationTableCopy)2 Job (com.google.api.services.bigquery.model.Job)1 JobReference (com.google.api.services.bigquery.model.JobReference)1 Status (org.apache.beam.sdk.io.gcp.bigquery.BigQueryHelpers.Status)1