gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 11:24:47 24 4
gpt4 key购买 nike

我在 Google Cloud Storage 上有一个 Google Cloud Datastore 备份,我想将其自动导入 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: Specifying a schema is disallowed for STORAGE_FORMAT_DATASTORE_BACKUP

如果我将 Schema.of() 更改为 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");
}
}
}

关于java - 通过 BigQuery Java api 创建数据存储备份表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44497946/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com