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


我假设目标数据集是在查询本身内设置的。为什么不解决呢?

最佳答案

您的查询字符串的问题在于,它只是以#开头的一行,该行被视为注释-因此,错误消息-No query found

10-06 08:48