use of com.google.cloud.bigquery.Schema in project google-cloud-java by GoogleCloudPlatform.
the class ITBigQuerySnippets method testInsertAllAndListTableData.
@Test
public void testInsertAllAndListTableData() throws IOException, InterruptedException {
String tableName = "test_insert_all_and_list_table_data";
String fieldName1 = "booleanField";
String fieldName2 = "bytesField";
String fieldName3 = "recordField";
String fieldName4 = "stringField";
TableId tableId = TableId.of(DATASET, tableName);
Schema schema = Schema.of(Field.of(fieldName1, Type.bool()), Field.of(fieldName2, Type.bytes()), Field.of(fieldName3, Type.record(Field.of(fieldName4, Type.string()))));
TableInfo table = TableInfo.of(tableId, StandardTableDefinition.of(schema));
assertNotNull(bigquery.create(table));
InsertAllResponse response = bigquerySnippets.insertAll(DATASET, tableName);
assertFalse(response.hasErrors());
assertTrue(response.getInsertErrors().isEmpty());
Page<List<FieldValue>> listPage = bigquerySnippets.listTableDataFromId(DATASET, tableName);
while (Iterators.size(listPage.iterateAll().iterator()) < 1) {
Thread.sleep(500);
listPage = bigquerySnippets.listTableDataFromId(DATASET, tableName);
}
List<FieldValue> row = listPage.getValues().iterator().next();
assertEquals(true, row.get(0).getBooleanValue());
assertArrayEquals(new byte[] { 0xA, 0xD, 0xD, 0xE, 0xD }, row.get(1).getBytesValue());
assertEquals("Hello, World!", row.get(2).getRecordValue().get(0).getStringValue());
assertTrue(bigquerySnippets.deleteTable(DATASET, tableName));
}
Aggregations