考虑以下 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 Function 中 - 删除了一些内容并保持简短):
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 进行了插入调用,实际上是我的源项目中的 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"
}
}
我假设目标数据集是在查询本身内设置的。为什么还不解决呢?
最佳答案
您的查询字符串的问题在于它只是以 # 开头的一行,该行被视为注释 - 因此出现错误消息 - 未找到查询
关于node.js - BigQuery Node.js API startQuery 不会将数据注入(inject)到目标表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46103227/