示例#1
0
 @Test
 public void testListAllTableData() {
   Page<List<FieldValue>> rows = bigquery.listTableData(TABLE_ID);
   int rowCount = 0;
   for (List<FieldValue> row : rows.values()) {
     FieldValue timestampCell = row.get(0);
     FieldValue stringCell = row.get(1);
     FieldValue integerCell = row.get(2);
     FieldValue booleanCell = row.get(3);
     FieldValue recordCell = row.get(4);
     assertEquals(FieldValue.Attribute.PRIMITIVE, timestampCell.attribute());
     assertEquals(FieldValue.Attribute.PRIMITIVE, stringCell.attribute());
     assertEquals(FieldValue.Attribute.REPEATED, integerCell.attribute());
     assertEquals(FieldValue.Attribute.PRIMITIVE, booleanCell.attribute());
     assertEquals(FieldValue.Attribute.RECORD, recordCell.attribute());
     assertEquals(1408452095220000L, timestampCell.timestampValue());
     assertEquals("stringValue", stringCell.stringValue());
     assertEquals(0, integerCell.repeatedValue().get(0).longValue());
     assertEquals(1, integerCell.repeatedValue().get(1).longValue());
     assertEquals(false, booleanCell.booleanValue());
     assertEquals(-14182916000000L, recordCell.recordValue().get(0).timestampValue());
     assertTrue(recordCell.recordValue().get(1).isNull());
     assertEquals(1, recordCell.recordValue().get(2).repeatedValue().get(0).longValue());
     assertEquals(0, recordCell.recordValue().get(2).repeatedValue().get(1).longValue());
     assertEquals(true, recordCell.recordValue().get(3).booleanValue());
     rowCount++;
   }
   assertEquals(2, rowCount);
 }
示例#2
0
 @Test
 public void testInsertFromFile() throws InterruptedException {
   String destinationTableName = "test_insert_from_file_table";
   TableId tableId = TableId.of(DATASET, destinationTableName);
   WriteChannelConfiguration configuration =
       WriteChannelConfiguration.builder(tableId)
           .formatOptions(FormatOptions.json())
           .createDisposition(JobInfo.CreateDisposition.CREATE_IF_NEEDED)
           .schema(TABLE_SCHEMA)
           .build();
   try (WriteChannel channel = bigquery.writer(configuration)) {
     channel.write(ByteBuffer.wrap(JSON_CONTENT.getBytes(StandardCharsets.UTF_8)));
   } catch (IOException e) {
     fail("IOException was not expected");
   }
   // wait until the new table is created. If the table is never created the test will time-out
   while (bigquery.getTable(tableId) == null) {
     Thread.sleep(1000L);
   }
   Page<List<FieldValue>> rows = bigquery.listTableData(tableId);
   int rowCount = 0;
   for (List<FieldValue> row : rows.values()) {
     FieldValue timestampCell = row.get(0);
     FieldValue stringCell = row.get(1);
     FieldValue integerCell = row.get(2);
     FieldValue booleanCell = row.get(3);
     FieldValue recordCell = row.get(4);
     assertEquals(FieldValue.Attribute.PRIMITIVE, timestampCell.attribute());
     assertEquals(FieldValue.Attribute.PRIMITIVE, stringCell.attribute());
     assertEquals(FieldValue.Attribute.REPEATED, integerCell.attribute());
     assertEquals(FieldValue.Attribute.PRIMITIVE, booleanCell.attribute());
     assertEquals(FieldValue.Attribute.RECORD, recordCell.attribute());
     assertEquals(1408452095220000L, timestampCell.timestampValue());
     assertEquals("stringValue", stringCell.stringValue());
     assertEquals(0, integerCell.repeatedValue().get(0).longValue());
     assertEquals(1, integerCell.repeatedValue().get(1).longValue());
     assertEquals(false, booleanCell.booleanValue());
     assertEquals(-14182916000000L, recordCell.recordValue().get(0).timestampValue());
     assertTrue(recordCell.recordValue().get(1).isNull());
     assertEquals(1, recordCell.recordValue().get(2).repeatedValue().get(0).longValue());
     assertEquals(0, recordCell.recordValue().get(2).repeatedValue().get(1).longValue());
     assertEquals(true, recordCell.recordValue().get(3).booleanValue());
     rowCount++;
   }
   assertEquals(2, rowCount);
   assertTrue(bigquery.delete(DATASET, destinationTableName));
 }