Пример #1
0
 @Test
 public void testCreateAndGetJob() {
   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.tableId().dataset());
   assertEquals(sourceTableName, createdTable.tableId().table());
   TableId destinationTable = TableId.of(DATASET, destinationTableName);
   CopyJobConfiguration copyJobConfiguration =
       CopyJobConfiguration.of(destinationTable, sourceTable);
   Job createdJob = bigquery.create(JobInfo.of(copyJobConfiguration));
   Job remoteJob = bigquery.getJob(createdJob.jobId());
   assertEquals(createdJob.jobId(), remoteJob.jobId());
   CopyJobConfiguration createdConfiguration = createdJob.configuration();
   CopyJobConfiguration remoteConfiguration = remoteJob.configuration();
   assertEquals(createdConfiguration.sourceTables(), remoteConfiguration.sourceTables());
   assertEquals(createdConfiguration.destinationTable(), remoteConfiguration.destinationTable());
   assertEquals(createdConfiguration.createDisposition(), remoteConfiguration.createDisposition());
   assertEquals(createdConfiguration.writeDisposition(), remoteConfiguration.writeDisposition());
   assertNotNull(remoteJob.etag());
   assertNotNull(remoteJob.statistics());
   assertNotNull(remoteJob.status());
   assertEquals(createdJob.selfLink(), remoteJob.selfLink());
   assertEquals(createdJob.userEmail(), remoteJob.userEmail());
   assertTrue(createdTable.delete());
   assertTrue(bigquery.delete(DATASET, destinationTableName));
 }
Пример #2
0
 @Test
 public void testCopyJob() throws InterruptedException {
   String sourceTableName = "test_copy_job_source_table";
   String destinationTableName = "test_copy_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.tableId().dataset());
   assertEquals(sourceTableName, createdTable.tableId().table());
   TableId destinationTable = TableId.of(DATASET, destinationTableName);
   CopyJobConfiguration configuration = CopyJobConfiguration.of(destinationTable, sourceTable);
   Job remoteJob = bigquery.create(JobInfo.of(configuration));
   while (!remoteJob.isDone()) {
     Thread.sleep(1000);
   }
   assertNull(remoteJob.status().error());
   Table remoteTable = bigquery.getTable(DATASET, destinationTableName);
   assertNotNull(remoteTable);
   assertEquals(destinationTable.dataset(), remoteTable.tableId().dataset());
   assertEquals(destinationTableName, remoteTable.tableId().table());
   assertEquals(TABLE_SCHEMA, remoteTable.definition().schema());
   assertTrue(createdTable.delete());
   assertTrue(remoteTable.delete());
 }
Пример #3
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());
 }
Пример #4
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)));
 }
Пример #5
0
 @Test
 public void testUpdateTable() {
   String tableName = "test_update_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("newDescription").build());
   assertEquals(DATASET, updatedTable.tableId().dataset());
   assertEquals(tableName, updatedTable.tableId().table());
   assertEquals(TABLE_SCHEMA, updatedTable.definition().schema());
   assertEquals("newDescription", updatedTable.description());
   assertTrue(updatedTable.delete());
 }
Пример #6
0
 @Test
 public void testUpdateNonExistingTable() {
   TableInfo tableInfo =
       TableInfo.of(
           TableId.of(DATASET, "test_update_non_existing_table"),
           StandardTableDefinition.of(SIMPLE_SCHEMA));
   try {
     bigquery.update(tableInfo);
     fail("BigQueryException was expected");
   } catch (BigQueryException e) {
     BigQueryError error = e.error();
     assertNotNull(error);
     assertEquals("notFound", error.reason());
     assertNotNull(error.message());
   }
 }
Пример #7
0
 @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.values().iterator();
   while (tableIterator.hasNext() && !found) {
     if (tableIterator.next().tableId().equals(createdTable.tableId())) {
       found = true;
     }
   }
   assertTrue(found);
   assertTrue(createdTable.delete());
 }
Пример #8
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());
 }
Пример #9
0
 @Test
 public void testCreateAndGetTable() {
   String tableName = "test_create_and_get_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);
   assertNotNull(remoteTable);
   assertTrue(remoteTable.definition() instanceof StandardTableDefinition);
   assertEquals(createdTable.tableId(), remoteTable.tableId());
   assertEquals(TableDefinition.Type.TABLE, remoteTable.definition().type());
   assertEquals(TABLE_SCHEMA, remoteTable.definition().schema());
   assertNotNull(remoteTable.creationTime());
   assertNotNull(remoteTable.lastModifiedTime());
   assertNotNull(remoteTable.<StandardTableDefinition>definition().numBytes());
   assertNotNull(remoteTable.<StandardTableDefinition>definition().numRows());
   assertTrue(remoteTable.delete());
 }