【发布时间】:2019-05-21 00:57:15
【问题描述】:
我正在使用 google.cloud.bigquery 库使用 bigquery.query() 方法执行和创建查询。我想从响应中获取Schema 详细信息,但是每当查询未返回任何结果时,我都会得到EmptyTableResult 而不是应该在其中列出Schema 和字段的响应。我使用了另一种创建作业然后使用查询作业的方法,我正在调用bigquery.getQueryResults,它应该返回QueryResponse 对象。下面是代码sn-p。
QueryJobConfiguration queryConfig =
QueryJobConfiguration.newBuilder(queryString)
.setDefaultDataset(bqDatasetId).setUseLegacySql(false)
.setFlattenResults(true).build();
JobId jobId = JobId.of(UUID.randomUUID().toString());
Job queryJob = bigQuery.create(JobInfo.newBuilder(queryConfig).setJobId(jobId).build());
// Wait for the query to complete.
queryJob = queryJob.waitFor();
// Check for errors
if (queryJob == null) {
throw new RuntimeException("Job no longer exists");
} else if (queryJob.getStatus().getError() != null) {
throw new RuntimeException(queryJob.getStatus().getError().toString());
}
// Get the results.
QueryResponse response = bigQuery.getQueryResults(queryJob.getJobId());
System.out.println(response);
在这里,在sysout 语句中,我得到了正确的响应,但是每当我尝试使用response.getSchema() 时,都会出现编译错误,提示getSchema() 不可见。谁能帮我这个?这种方法是正确的还是有其他方法可以做同样的事情?
【问题讨论】:
标签: java google-cloud-platform google-bigquery