考虑以下BQ查询:
const sourceQuery = '#standardSQL SELECT station_id, time FROM bryans_bike_analysis_data.2016_status_data ' +
'WHERE SAFE_CAST(bikes_available as INT64)=0 AND SAFE_CAST(docks_available AS INT64)=0' +
'GROUP BY station_id, time';
并考虑以下代码(放置在Google Cloud功能中 - 删除了一些东西,请简短简短):
bqSource.startQuery({
destination: bqDest.dataset(destDataset).table(destTable),
query: sourceQuery
}, function(err, job) {
if (!err) {
console.log("Succesfully initialized query");
job.getQueryResults(function(err, rows, apiResponse) {
if (!err) {
console.log("Successfully completed inner");
console.log(apiResponse);
}
else {
console.log(err);
console.log(apiResponse);
res.status(500).end();
}
});
}
else {
console.log(err);
res.status(500).end();
}
});
文档使我相信该查询应执行,然后将结果放入表中(在单独的项目中),按照目标属性指定。但是,这是返回的错误:
errors:
[ { domain: 'global',
reason: 'invalidQuery',
message: '1.195 - 1.195: No query found.',
locationType: 'other',
location: 'query' } ],
response: undefined,
message: '1.195 - 1.195: No query found.' }
当我查看日志时,似乎对我的目标项目的BQ进行了插入调用,实际上是我的 source 项目中的getqueryresults
调用,它正在获取错误。在我的源项目中的错误中,日志读取:
jobGetQueryResultsResponse: {
job: {
jobConfiguration: {
query: {
createDisposition: "CREATE_IF_NEEDED"
defaultDataset: {
}
destinationTable: {
datasetId: "destination_bq_cp_test"
projectId: "armalavage-test"
tableId: "bikes_available"
}
query: "#standardSQL SELECT station_id, time FROM bryans_bike_analysis_data.2016_status_data WHERE SAFE_CAST(bikes_available as INT64)=0 AND SAFE_CAST(docks_available AS INT64)=0GROUP BY station_id, time"
writeDisposition: "WRITE_EMPTY"
}
}
我假设目标数据集是在查询本身内设置的。为什么不解决?
查询字符串的问题是,它只是一行以#开始,它被视为评论 - 因此错误消息-No query found