Ejemplo n.º 1
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());
 }