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));
}
Aggregations