Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google bigquery @google cloud/bigquery查询API在云函数中使用时返回空承诺_Google Bigquery_Google Cloud Functions_Google Api Nodejs Client - Fatal编程技术网

Google bigquery @google cloud/bigquery查询API在云函数中使用时返回空承诺

Google bigquery @google cloud/bigquery查询API在云函数中使用时返回空承诺,google-bigquery,google-cloud-functions,google-api-nodejs-client,Google Bigquery,Google Cloud Functions,Google Api Nodejs Client,我正在尝试使用'@googlecloud/bigquery'库从googlecloud函数中查询bigquery。当承诺返回时,我得到的只是一个数组,其中包含另一个空数组,即使当我从大查询控制台运行相同的查询时,我得到的是一个非空响应 我尝试使用异步函数代替承诺,但没有成功。我还为我的服务帐户授予了“BigQuery管理员”和“编辑”权限,但这两种权限都没有实现 我知道API遇到了大问题。当我尝试从我的云函数创建一个新的数据集时,该调用工作得很好,但由于某些原因,我无法从BQ返回查询结果 f

我正在尝试使用'@googlecloud/bigquery'库从googlecloud函数中查询bigquery。当承诺返回时,我得到的只是一个数组,其中包含另一个空数组,即使当我从大查询控制台运行相同的查询时,我得到的是一个非空响应

我尝试使用异步函数代替承诺,但没有成功。我还为我的服务帐户授予了“BigQuery管理员”和“编辑”权限,但这两种权限都没有实现

我知道API遇到了大问题。当我尝试从我的云函数创建一个新的数据集时,该调用工作得很好,但由于某些原因,我无法从BQ返回查询结果

  function warningAndPreventionIntent(agent) {
    let userCountry = agent.parameters['geo-country'];
    console.log(String(userCountry[0]));

    const gotCountry = userCountry.length > 0;

    if(gotCountry) {
      agent.add('Im looking into your trip');

      const OPTIONS = {
              query: 'SELECT disease.name FROM `projectId.dataset.table`, unnest(disease) disease WHERE country = @country',
              timeoutMs: 10000,
              useLegacySql: false,
              params: {country: userCountry[0]}
      };

      return bigquery
      .query(OPTIONS)
      .then(results => {
          console.log(JSON.stringify(results[0]))
          const ROWS = results[0];

          let diseaseList = [];

          for(var row of ROWS) {
            diseaseList.push(row.name);
            console.log(diseaseList);
          }

          return true;

      })
      .catch(err => {
        console.error('ERROR:', err);
      });
    }
  }

我应该得到一个带有值的JSON
result
对象,但我只得到一个空数组的and和array
[[]]

请找到一个使用公共数据集的工作示例,您可以用它来测试查询

if (!global._babelPolyfill) {
    var a = require("babel-polyfill")
}

import BigQuery from '@google-cloud/bigquery'

describe('Check google-cloud', async () => {

    it('Test query', async () => {
        let result = await test('panada')

    })

    async function test(p1) {
        try {
            const bigquery = new BigQuery({
                projectId: `projectId`,
                keyFilename: '/Users/tamirklein/ssh/mydata.json'
            })

            let query = [
                'SELECT url',
                'FROM `publicdata.samples.github_nested`',
                'WHERE repository.owner = @owner'

            ].join(' ')

            console.log(`query is: ${query}`)
            let [result] = await bigquery.query({
                query,
                params: {
                    owner: p1
                }
            })

            result.forEach((row, index) => {
                console.log(`row number ${index}, url is: ${row.url}`)
            })
        } catch (err) {
            console.log("err", err)
        }
    }
})

我现在也得到了同样的结果。我更新了我的云函数,但没有更改代码,行为也发生了更改。

考虑到您的评论,将google/bigquery降级为1.3.X有助于解决此问题。在我看来,你可能受到了影响。这看起来是固定的,因此您可以升级到最新的API版本,而无需重新引入错误。

如果您在代码中硬编码国家,会发生什么情况?我的想法是用最小的依赖性测试一个查询本身。@Kolban我也考虑过这一点,但这似乎不是问题所在。当我硬编码这个国家时,我得到了同样的回应。我也尝试过查询公共数据集而不是我自己的数据集,但仍然没有得到响应。仅供参考,我也遇到过同样的问题(nodejs cloud function>bigquery返回空数组)。我们也更改了软件包版本(我们升级到目前最新的4.1.2),问题消失了。欢迎使用SO!请写一个清楚而有用的答案@Dan Wilson我通过将我使用的google/bigquery依赖项降级到1.3.x解决了我的问题。当我安装npm时,我似乎将库升级到了版本3,而版本3对我不起作用。希望这个帮助看起来google/bigquery版本是我的问题。当我降级到1.3.x时,我的问题得到了解决。不确定我是否使用了错误的新版本,或者是否存在错误。