Exemple #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());
 }
Exemple #2
0
 @Test
 public void testInsertAll() {
   String tableName = "test_insert_all_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)))
           .build();
   InsertAllResponse response = bigquery.insertAll(request);
   assertFalse(response.hasErrors());
   assertEquals(0, response.insertErrors().size());
   assertTrue(bigquery.delete(TableId.of(DATASET, tableName)));
 }