use of com.google.cloud.bigquery.StandardTableDefinition 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.StandardTableDefinition in project google-cloud-java by GoogleCloudPlatform.
the class ITBigQueryTest method testListTables.
@Test
public void testListTables() {
String tableName = "test_list_tables";
StandardTableDefinition tableDefinition = StandardTableDefinition.of(TABLE_SCHEMA);
TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableDefinition);
Table createdTable = bigquery.create(tableInfo);
assertNotNull(createdTable);
Page<Table> tables = bigquery.listTables(DATASET);
boolean found = false;
Iterator<Table> tableIterator = tables.getValues().iterator();
while (tableIterator.hasNext() && !found) {
if (tableIterator.next().getTableId().equals(createdTable.getTableId())) {
found = true;
}
}
assertTrue(found);
assertTrue(createdTable.delete());
}
use of com.google.cloud.bigquery.StandardTableDefinition in project google-cloud-java by GoogleCloudPlatform.
the class ITBigQueryTest method testUpdateTable.
@Test
public void testUpdateTable() {
String tableName = "test_update_table";
StandardTableDefinition tableDefinition = StandardTableDefinition.of(TABLE_SCHEMA);
TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableDefinition);
Table createdTable = bigquery.create(tableInfo);
assertNotNull(createdTable);
Table updatedTable = bigquery.update(tableInfo.toBuilder().setDescription("newDescription").build());
assertEquals(DATASET, updatedTable.getTableId().getDataset());
assertEquals(tableName, updatedTable.getTableId().getTable());
assertEquals(TABLE_SCHEMA, updatedTable.getDefinition().getSchema());
assertEquals("newDescription", updatedTable.getDescription());
assertTrue(updatedTable.delete());
}
use of com.google.cloud.bigquery.StandardTableDefinition in project google-cloud-java by GoogleCloudPlatform.
the class ITBigQueryTest method testCreateAndGetTable.
@Test
public void testCreateAndGetTable() {
String tableName = "test_create_and_get_table";
TableId tableId = TableId.of(DATASET, tableName);
TimePartitioning partitioning = TimePartitioning.of(Type.DAY);
StandardTableDefinition tableDefinition = StandardTableDefinition.newBuilder().setSchema(TABLE_SCHEMA).setTimePartitioning(partitioning).build();
Table createdTable = bigquery.create(TableInfo.of(tableId, tableDefinition));
assertNotNull(createdTable);
assertEquals(DATASET, createdTable.getTableId().getDataset());
assertEquals(tableName, createdTable.getTableId().getTable());
Table remoteTable = bigquery.getTable(DATASET, tableName);
assertNotNull(remoteTable);
assertTrue(remoteTable.getDefinition() instanceof StandardTableDefinition);
assertEquals(createdTable.getTableId(), remoteTable.getTableId());
assertEquals(TableDefinition.Type.TABLE, remoteTable.getDefinition().getType());
assertEquals(TABLE_SCHEMA, remoteTable.getDefinition().getSchema());
assertNotNull(remoteTable.getCreationTime());
assertNotNull(remoteTable.getLastModifiedTime());
assertNotNull(remoteTable.<StandardTableDefinition>getDefinition().getNumBytes());
assertNotNull(remoteTable.<StandardTableDefinition>getDefinition().getNumRows());
assertEquals(partitioning, remoteTable.<StandardTableDefinition>getDefinition().getTimePartitioning());
assertTrue(remoteTable.delete());
}
use of com.google.cloud.bigquery.StandardTableDefinition in project google-cloud-java by GoogleCloudPlatform.
the class DatasetSnippets method createTable.
/**
* Example of creating a table in the dataset with schema and time partitioning.
*/
// [TARGET create(String, TableDefinition, TableOption...)]
// [VARIABLE “my_table”]
// [VARIABLE “my_field”]
public Table createTable(String tableName, String fieldName) {
// [START createTable]
Schema schema = Schema.of(Field.of(fieldName, Type.string()));
StandardTableDefinition definition = StandardTableDefinition.newBuilder().setSchema(schema).setTimePartitioning(TimePartitioning.of(TimePartitioning.Type.DAY)).build();
Table table = dataset.create(tableName, definition);
// [END createTable]
return table;
}
Aggregations