2017-06-12 12 views
1

Google Cloud StorageにGoogle Cloud Datastoreのバックアップを作成しており、自動的にBigQueryにインポートしたいと考えています。BigQueryを使用してデータストアのバックアップテーブルを作成するJava API

TableDefinition tableDefinition = ExternalTableDefinition 
     .newBuilder(tableUri, Schema.of(), FormatOptions.datastoreBackup()) 
     .setAutodetect(true) 
     .build(); 
return bigQuery.create(TableInfo.of(TableId.of("ds", tableName), tableDefinition)); 

これは次の例外を投げます。

com.google.cloud.bigquery.BigQueryException:スキーマを指定し、私はそれがヌルポインタをスローnullにSchema.ofを()に変更した場合STORAGE_FORMAT_DATASTORE_BACKUP

のために禁止さ です。また、すべてのファクトリメソッドにはスキームが必要なメソッドシグニチャがあります。 Java APIを使用してこのテーブルを外部テーブルとして作成するにはどうすればよいですか?

答えて

0

この

public class DatastoreBackupImport { 

     private String datasetName = "..."; 
     private String uri = "gs://xxx/xxx/.xxx.backup_info"; 
     private String tableName = "xxx"; 

     private void importBackup(){ 
      BigQuery bigquery = BigQueryOptions.getDefaultInstance().getService(); 
      TableId tableId = TableId.of(datasetName, tableName); 
      TableDefinition tableDefinition = StandardTableDefinition.newBuilder().build(); 
      TableInfo tableInfo = TableInfo.newBuilder(tableId, tableDefinition).build(); 
      Table table = bigquery.create(tableInfo); 
      Job job = table.load(FormatOptions.datastoreBackup(), uri); 
    // Wait for the job to complete 
      try { 
       Job completedJob = job.waitFor(WaitForOption.checkEvery(1, TimeUnit.SECONDS), 
        WaitForOption.timeout(3, TimeUnit.MINUTES)); 
       if (completedJob != null && completedJob.getStatus().getError() == null) { 
        // Job completed successfully 
        System.out.println("Job completed successfully"); 
       } else { 
        // Handle error case 
        System.out.printf("There was an error"); 
        System.out.println(completedJob.getStatus().getError().getMessage()); 
       } 
      } catch (InterruptedException | TimeoutException e) { 
       // Handle interrupted wait 
       System.out.println("There was an interruption"); 
      } 
     } 
    } 
をお試しください
関連する問題