Search in sources :

Example 1 with ExtractJobConfiguration

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

the class ITBigQueryTest method testExtractJob.

@Test
public void testExtractJob() throws InterruptedException, TimeoutException {
    String tableName = "test_export_job_table";
    TableId destinationTable = TableId.of(DATASET, tableName);
    LoadJobConfiguration configuration = LoadJobConfiguration.newBuilder(destinationTable, "gs://" + BUCKET + "/" + LOAD_FILE).setSchema(SIMPLE_SCHEMA).build();
    Job remoteLoadJob = bigquery.create(JobInfo.of(configuration));
    remoteLoadJob = remoteLoadJob.waitFor();
    assertNull(remoteLoadJob.getStatus().getError());
    ExtractJobConfiguration extractConfiguration = ExtractJobConfiguration.newBuilder(destinationTable, "gs://" + BUCKET + "/" + EXTRACT_FILE).setPrintHeader(false).build();
    Job remoteExtractJob = bigquery.create(JobInfo.of(extractConfiguration));
    remoteExtractJob = remoteExtractJob.waitFor();
    assertNull(remoteExtractJob.getStatus().getError());
    assertEquals(CSV_CONTENT, new String(storage.readAllBytes(BUCKET, EXTRACT_FILE), StandardCharsets.UTF_8));
    assertTrue(bigquery.delete(DATASET, tableName));
}
Also used : TableId(com.google.cloud.bigquery.TableId) LoadJobConfiguration(com.google.cloud.bigquery.LoadJobConfiguration) Job(com.google.cloud.bigquery.Job) ExtractJobConfiguration(com.google.cloud.bigquery.ExtractJobConfiguration) Test(org.junit.Test)

Aggregations

ExtractJobConfiguration (com.google.cloud.bigquery.ExtractJobConfiguration)1 Job (com.google.cloud.bigquery.Job)1 LoadJobConfiguration (com.google.cloud.bigquery.LoadJobConfiguration)1 TableId (com.google.cloud.bigquery.TableId)1 Test (org.junit.Test)1