Search in sources :

Example 1 with JobOption

use of com.google.cloud.bigquery.BigQuery.JobOption in project google-cloud-java by GoogleCloudPlatform.

the class TableSnippets method copyTableId.

/**
   * Example copying the table to a destination table.
   */
// [TARGET copy(TableId, JobOption...)]
// [VARIABLE "my_dataset"]
// [VARIABLE "my_destination_table"]
public Job copyTableId(String dataset, String tableName) throws BigQueryException {
    // [START copyTableId]
    TableId destinationId = TableId.of(dataset, tableName);
    JobOption options = JobOption.fields(JobField.STATUS, JobField.USER_EMAIL);
    Job job = table.copy(destinationId, options);
    // Wait for the job to complete.
    try {
        Job completedJob = job.waitFor(WaitForOption.checkEvery(1, TimeUnit.SECONDS), WaitForOption.timeout(3, TimeUnit.MINUTES));
        if (completedJob != null && completedJob.getStatus().getError() == null) {
        // Job completed successfully.
        } else {
        // Handle error case.
        }
    } catch (InterruptedException | TimeoutException e) {
    // Handle interrupted wait
    }
    // [END copyTableId]
    return job;
}
Also used : TableId(com.google.cloud.bigquery.TableId) Job(com.google.cloud.bigquery.Job) JobOption(com.google.cloud.bigquery.BigQuery.JobOption) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

JobOption (com.google.cloud.bigquery.BigQuery.JobOption)1 Job (com.google.cloud.bigquery.Job)1 TableId (com.google.cloud.bigquery.TableId)1 TimeoutException (java.util.concurrent.TimeoutException)1