use of com.google.cloud.bigquery.Table in project google-cloud-java by GoogleCloudPlatform.
the class ITTableSnippets method testUpdate.
@Test
public void testUpdate() {
Table updatedTable = tableSnippets.update();
assertEquals("new description", updatedTable.getDescription());
}
use of com.google.cloud.bigquery.Table in project google-cloud-java by GoogleCloudPlatform.
the class ITTableSnippets method testDelete.
@Test
public void testDelete() {
Table doomedTable = bigquery.create(TableInfo.of(DOOMED_TABLE_ID, StandardTableDefinition.of(SCHEMA)));
TableSnippets doomedTableSnippets = new TableSnippets(doomedTable);
assertTrue(doomedTableSnippets.delete());
}
use of com.google.cloud.bigquery.Table 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.Table in project google-cloud-java by GoogleCloudPlatform.
the class ITBigQueryTest method testCreateViewTable.
@Test
public void testCreateViewTable() throws InterruptedException {
String tableName = "test_create_view_table";
TableId tableId = TableId.of(DATASET, tableName);
ViewDefinition viewDefinition = ViewDefinition.of("SELECT TimestampField, StringField, BooleanField FROM " + DATASET + "." + TABLE_ID.getTable());
TableInfo tableInfo = TableInfo.of(tableId, viewDefinition);
Table createdTable = bigquery.create(tableInfo);
assertNotNull(createdTable);
assertEquals(DATASET, createdTable.getTableId().getDataset());
assertEquals(tableName, createdTable.getTableId().getTable());
Table remoteTable = bigquery.getTable(DATASET, tableName);
assertNotNull(remoteTable);
assertEquals(createdTable.getTableId(), remoteTable.getTableId());
assertTrue(remoteTable.getDefinition() instanceof ViewDefinition);
Schema expectedSchema = Schema.newBuilder().addField(Field.newBuilder("TimestampField", Field.Type.timestamp()).setMode(Field.Mode.NULLABLE).build()).addField(Field.newBuilder("StringField", Field.Type.string()).setMode(Field.Mode.NULLABLE).build()).addField(Field.newBuilder("BooleanField", Field.Type.bool()).setMode(Field.Mode.NULLABLE).build()).build();
assertEquals(expectedSchema, remoteTable.getDefinition().getSchema());
QueryRequest request = QueryRequest.newBuilder("SELECT * FROM " + tableName).setDefaultDataset(DatasetId.of(DATASET)).setMaxWaitTime(60000L).setPageSize(1000L).build();
QueryResponse response = bigquery.query(request);
while (!response.jobCompleted()) {
response = bigquery.getQueryResults(response.getJobId());
Thread.sleep(1000);
}
int rowCount = 0;
for (List<FieldValue> row : response.getResult().getValues()) {
FieldValue timestampCell = row.get(0);
FieldValue stringCell = row.get(1);
FieldValue booleanCell = row.get(2);
assertEquals(FieldValue.Attribute.PRIMITIVE, timestampCell.getAttribute());
assertEquals(FieldValue.Attribute.PRIMITIVE, stringCell.getAttribute());
assertEquals(FieldValue.Attribute.PRIMITIVE, booleanCell.getAttribute());
assertEquals(1408452095220000L, timestampCell.getTimestampValue());
assertEquals("stringValue", stringCell.getStringValue());
assertEquals(false, booleanCell.getBooleanValue());
rowCount++;
}
assertEquals(2, rowCount);
assertTrue(remoteTable.delete());
}
use of com.google.cloud.bigquery.Table 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());
}
Aggregations