Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过BigQuery Java api创建数据存储备份表_Java_Google Cloud Datastore_Google Bigquery - Fatal编程技术网

通过BigQuery Java api创建数据存储备份表

通过BigQuery Java api创建数据存储备份表,java,google-cloud-datastore,google-bigquery,Java,Google Cloud Datastore,Google Bigquery,我在谷歌云存储上有一个谷歌云数据存储备份,我想将它自动导入BigQuery TableDefinition tableDefinition = ExternalTableDefinition .newBuilder(tableUri, Schema.of(), FormatOptions.datastoreBackup()) .setAutodetect(true) .build(); return bigQuery.create(TableInf

我在谷歌云存储上有一个谷歌云数据存储备份,我想将它自动导入BigQuery

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:指定架构是不正确的 不允许用于存储\u格式\u数据存储\u备份

如果我将Schema.of()更改为null,它将抛出一个null指针。并且所有工厂方法都有一个需要方案的方法签名。如何通过Java API将此表创建为外部表?

试试这个

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");
            }
        }
    }
试试这个

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");
            }
        }
    }