node.js - BigQuery Node.js API startQuery 不会将数据注入(inject)到目标表中

标签 node.js google-bigquery google-cloud-platform google-cloud-functions

考虑以下 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/

相关文章:

node.js - Puppeteer:如何仅等待第一个响应(HTML)

node.js - 异步 nodejs 模块导出

node.js - 使用 Twitter 中的 Meteor 应用程序发送推文

sql - BigQuery 上的 WHERE 子句中的 SELECT 语句不起作用

google-bigquery - 大查询 : Partitioning data past 2000 limit (Update: Now 4000 limit)

google-cloud-platform - gcloud alpha 命令和 gcloud beta 命令有什么区别?

google-cloud-platform - kubectl udp负载均衡器问题

apache-spark - 从谷歌云中的 spark worker 获取日志输出

javascript - Node.js:为 exec() 清理不受信任的用户输入

python - 用户没有 bigquery.datasets.update 权限