use of com.google.cloud.bigquery.CopyJobConfiguration in project google-cloud-java by GoogleCloudPlatform.
the class ITBigQueryTest method testCreateAndGetJob.
@Test
public void testCreateAndGetJob() throws InterruptedException, TimeoutException {
String sourceTableName = "test_create_and_get_job_source_table";
String destinationTableName = "test_create_and_get_job_destination_table";
TableId sourceTable = TableId.of(DATASET, sourceTableName);
StandardTableDefinition tableDefinition = StandardTableDefinition.of(TABLE_SCHEMA);
TableInfo tableInfo = TableInfo.of(sourceTable, tableDefinition);
Table createdTable = bigquery.create(tableInfo);
assertNotNull(createdTable);
assertEquals(DATASET, createdTable.getTableId().getDataset());
assertEquals(sourceTableName, createdTable.getTableId().getTable());
TableId destinationTable = TableId.of(DATASET, destinationTableName);
CopyJobConfiguration copyJobConfiguration = CopyJobConfiguration.of(destinationTable, sourceTable);
Job createdJob = bigquery.create(JobInfo.of(copyJobConfiguration));
Job remoteJob = bigquery.getJob(createdJob.getJobId());
assertEquals(createdJob.getJobId(), remoteJob.getJobId());
CopyJobConfiguration createdConfiguration = createdJob.getConfiguration();
CopyJobConfiguration remoteConfiguration = remoteJob.getConfiguration();
assertEquals(createdConfiguration.getSourceTables(), remoteConfiguration.getSourceTables());
assertEquals(createdConfiguration.getDestinationTable(), remoteConfiguration.getDestinationTable());
assertEquals(createdConfiguration.getCreateDisposition(), remoteConfiguration.getCreateDisposition());
assertEquals(createdConfiguration.getWriteDisposition(), remoteConfiguration.getWriteDisposition());
assertNotNull(remoteJob.getEtag());
assertNotNull(remoteJob.getStatistics());
assertNotNull(remoteJob.getStatus());
assertEquals(createdJob.getSelfLink(), remoteJob.getSelfLink());
assertEquals(createdJob.getUserEmail(), remoteJob.getUserEmail());
assertTrue(createdTable.delete());
Job completedJob = remoteJob.waitFor(WaitForOption.checkEvery(1, TimeUnit.SECONDS), WaitForOption.timeout(1, TimeUnit.MINUTES));
assertNotNull(completedJob);
assertNull(completedJob.getStatus().getError());
assertTrue(bigquery.delete(DATASET, destinationTableName));
}
use of com.google.cloud.bigquery.CopyJobConfiguration in project google-cloud-java by GoogleCloudPlatform.
the class ITBigQueryTest method testCopyJob.
@Test
public void testCopyJob() throws InterruptedException, TimeoutException {
String sourceTableName = "test_copy_job_source_table";
String destinationTableName = "test_copy_job_destination_table";
TableId sourceTable = TableId.of(DATASET, sourceTableName);
StandardTableDefinition tableDefinition = StandardTableDefinition.of(TABLE_SCHEMA);
TableInfo tableInfo = TableInfo.of(sourceTable, tableDefinition);
Table createdTable = bigquery.create(tableInfo);
assertNotNull(createdTable);
assertEquals(DATASET, createdTable.getTableId().getDataset());
assertEquals(sourceTableName, createdTable.getTableId().getTable());
TableId destinationTable = TableId.of(DATASET, destinationTableName);
CopyJobConfiguration configuration = CopyJobConfiguration.of(destinationTable, sourceTable);
Job remoteJob = bigquery.create(JobInfo.of(configuration));
remoteJob = remoteJob.waitFor();
assertNull(remoteJob.getStatus().getError());
Table remoteTable = bigquery.getTable(DATASET, destinationTableName);
assertNotNull(remoteTable);
assertEquals(destinationTable.getDataset(), remoteTable.getTableId().getDataset());
assertEquals(destinationTableName, remoteTable.getTableId().getTable());
assertEquals(TABLE_SCHEMA, remoteTable.getDefinition().getSchema());
assertTrue(createdTable.delete());
assertTrue(remoteTable.delete());
}
use of com.google.cloud.bigquery.CopyJobConfiguration in project google-cloud-java by GoogleCloudPlatform.
the class ITBigQueryTest method testCreateAndGetJobWithSelectedFields.
@Test
public void testCreateAndGetJobWithSelectedFields() throws InterruptedException, TimeoutException {
String sourceTableName = "test_create_and_get_job_with_selected_fields_source_table";
String destinationTableName = "test_create_and_get_job_with_selected_fields_destination_table";
TableId sourceTable = TableId.of(DATASET, sourceTableName);
StandardTableDefinition tableDefinition = StandardTableDefinition.of(TABLE_SCHEMA);
TableInfo tableInfo = TableInfo.of(sourceTable, tableDefinition);
Table createdTable = bigquery.create(tableInfo);
assertNotNull(createdTable);
assertEquals(DATASET, createdTable.getTableId().getDataset());
assertEquals(sourceTableName, createdTable.getTableId().getTable());
TableId destinationTable = TableId.of(DATASET, destinationTableName);
CopyJobConfiguration configuration = CopyJobConfiguration.of(destinationTable, sourceTable);
Job createdJob = bigquery.create(JobInfo.of(configuration), JobOption.fields(JobField.ETAG));
CopyJobConfiguration createdConfiguration = createdJob.getConfiguration();
assertNotNull(createdJob.getJobId());
assertNotNull(createdConfiguration.getSourceTables());
assertNotNull(createdConfiguration.getDestinationTable());
assertNotNull(createdJob.getEtag());
assertNull(createdJob.getStatistics());
assertNull(createdJob.getStatus());
assertNull(createdJob.getSelfLink());
assertNull(createdJob.getUserEmail());
Job remoteJob = bigquery.getJob(createdJob.getJobId(), JobOption.fields(JobField.ETAG));
CopyJobConfiguration remoteConfiguration = remoteJob.getConfiguration();
assertEquals(createdJob.getJobId(), remoteJob.getJobId());
assertEquals(createdConfiguration.getSourceTables(), remoteConfiguration.getSourceTables());
assertEquals(createdConfiguration.getDestinationTable(), remoteConfiguration.getDestinationTable());
assertEquals(createdConfiguration.getCreateDisposition(), remoteConfiguration.getCreateDisposition());
assertEquals(createdConfiguration.getWriteDisposition(), remoteConfiguration.getWriteDisposition());
assertNotNull(remoteJob.getEtag());
assertNull(remoteJob.getStatistics());
assertNull(remoteJob.getStatus());
assertNull(remoteJob.getSelfLink());
assertNull(remoteJob.getUserEmail());
assertTrue(createdTable.delete());
Job completedJob = remoteJob.waitFor(WaitForOption.checkEvery(1, TimeUnit.SECONDS), WaitForOption.timeout(1, TimeUnit.MINUTES));
assertNotNull(completedJob);
assertNull(completedJob.getStatus().getError());
assertTrue(bigquery.delete(DATASET, destinationTableName));
}
Aggregations