将嵌套的BigQuery数据导出到云存储

时间:2017-07-04 14:44:25

标签: java json google-cloud-datastore google-bigquery google-cloud-platform

我正在尝试通过API将bigquery数据导出到Google云存储桶。我从这里改编了代码片段 https://cloud.google.com/bigquery/docs/exporting-data

Job job = table.extract(format, gcsUrl);
// 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
  } else {
    // Handle error case
       System.out.println(completedJob.getStatus().getError());
  }
} catch (InterruptedException | TimeoutException e) {
  // Handle interrupted wait

}

我与" JSON"交换格式因为我的数据是嵌套的,不能导出到CSV和gcsUrl与" gs://mybucket/export_*.json"。  但错误消息告诉我以下问题:

transfer not working  BigQueryError{reason=invalid, location=null, message=Operation cannot be performed on a nested schema. Field: totals}

有什么建议吗? JSON应该能够处理嵌套格式......

1 个答案:

答案 0 :(得分:3)

参考destinationFormat option,您应为"NEWLINE_DELIMITED_JSON"变量设置format,以便导出为JSON。