Пример #1
0
 @Test
 public void testInsertAllWithSuffix() throws InterruptedException {
   String tableName = "test_insert_all_with_suffix_table";
   StandardTableDefinition tableDefinition = StandardTableDefinition.of(TABLE_SCHEMA);
   TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableDefinition);
   assertNotNull(bigquery.create(tableInfo));
   InsertAllRequest request =
       InsertAllRequest.builder(tableInfo.tableId())
           .addRow(
               ImmutableMap.<String, Object>of(
                   "TimestampField",
                   "2014-08-19 07:41:35.220 -05:00",
                   "StringField",
                   "stringValue",
                   "IntegerField",
                   ImmutableList.of(0, 1),
                   "BooleanField",
                   false,
                   "RecordField",
                   ImmutableMap.of(
                       "TimestampField",
                       "1969-07-20 20:18:04 UTC",
                       "IntegerField",
                       ImmutableList.of(1, 0),
                       "BooleanField",
                       true)))
           .addRow(
               ImmutableMap.<String, Object>of(
                   "TimestampField",
                   "2014-08-19 07:41:35.220 -05:00",
                   "StringField",
                   "stringValue",
                   "IntegerField",
                   ImmutableList.of(0, 1),
                   "BooleanField",
                   false,
                   "RecordField",
                   ImmutableMap.of(
                       "TimestampField",
                       "1969-07-20 20:18:04 UTC",
                       "IntegerField",
                       ImmutableList.of(1, 0),
                       "BooleanField",
                       true)))
           .templateSuffix("_suffix")
           .build();
   InsertAllResponse response = bigquery.insertAll(request);
   assertFalse(response.hasErrors());
   assertEquals(0, response.insertErrors().size());
   String newTableName = tableName + "_suffix";
   Table suffixTable = bigquery.getTable(DATASET, newTableName, TableOption.fields());
   // wait until the new table is created. If the table is never created the test will time-out
   while (suffixTable == null) {
     Thread.sleep(1000L);
     suffixTable = bigquery.getTable(DATASET, newTableName, TableOption.fields());
   }
   assertTrue(bigquery.delete(TableId.of(DATASET, tableName)));
   assertTrue(suffixTable.delete());
 }
Пример #2
0
 @Test
 public void testUpdateTableWithSelectedFields() {
   String tableName = "test_update_with_selected_fields_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().description("newDescr").build(),
           TableOption.fields(TableField.DESCRIPTION));
   assertTrue(updatedTable.definition() instanceof StandardTableDefinition);
   assertEquals(DATASET, updatedTable.tableId().dataset());
   assertEquals(tableName, updatedTable.tableId().table());
   assertEquals("newDescr", updatedTable.description());
   assertNull(updatedTable.definition().schema());
   assertNull(updatedTable.lastModifiedTime());
   assertNull(updatedTable.<StandardTableDefinition>definition().numBytes());
   assertNull(updatedTable.<StandardTableDefinition>definition().numRows());
   assertTrue(createdTable.delete());
 }
Пример #3
0
 @Test
 public void testCreateAndGetTableWithSelectedField() {
   String tableName = "test_create_and_get_selected_fields_table";
   TableId tableId = TableId.of(DATASET, tableName);
   StandardTableDefinition tableDefinition = StandardTableDefinition.of(TABLE_SCHEMA);
   Table createdTable = bigquery.create(TableInfo.of(tableId, tableDefinition));
   assertNotNull(createdTable);
   assertEquals(DATASET, createdTable.tableId().dataset());
   assertEquals(tableName, createdTable.tableId().table());
   Table remoteTable =
       bigquery.getTable(DATASET, tableName, TableOption.fields(TableField.CREATION_TIME));
   assertNotNull(remoteTable);
   assertTrue(remoteTable.definition() instanceof StandardTableDefinition);
   assertEquals(createdTable.tableId(), remoteTable.tableId());
   assertEquals(TableDefinition.Type.TABLE, remoteTable.definition().type());
   assertNotNull(remoteTable.creationTime());
   assertNull(remoteTable.definition().schema());
   assertNull(remoteTable.lastModifiedTime());
   assertNull(remoteTable.<StandardTableDefinition>definition().numBytes());
   assertNull(remoteTable.<StandardTableDefinition>definition().numRows());
   assertTrue(remoteTable.delete());
 }