【问题标题】:Issues loading data into a BigQuery table using a cloud function使用云函数将数据加载到 BigQuery 表中的问题
【发布时间】:2018-05-16 15:37:58
【问题描述】:

我在尝试将数据存储备份加载到 BigQuery 中的现有表时遇到问题。我收到以下错误:

TypeError: bigquery.dataset(...).table(...).load is not a function

我正在关注BigQuery cloud Api repo 中的示例之一。

不确定我是否以错误的方式使用此方法,但我想要实现的只是让我的云功能从数据存储转储中更新此 BigQuery 表,而不是每天删除和创建 - 这似乎相反富有成效,我以前也这样做过。

这是我的代码:

exports.processFile = function (event, callback) {

  const BigQuery = require('@google-cloud/bigquery');
  const Storage = require('@google-cloud/storage');

  const bucketName = 'nyt-links-backup-dev';
  const filename = event.data.name;
  const tableId = 'links_data_tbl';
  const projectId = 'nyt-sartre-dev';

  // Instantiates clients
  const bigquery = new BigQuery({
    projectId: projectId,
  });

  const storage = new Storage({
    projectId: projectId,
  });

  const datasetId = 'sartre_sublink_dataset';
  const dataset = bigquery.dataset(datasetId);

  const metadata = {
    sourceFormat: 'AVRO',
  };     

  // Loads data from a Google Cloud Storage file into the table
  bigquery
    .dataset(datasetId)
    .table(tableId)
    .load(storage.bucket(bucketName).file(filename), metadata)
    .then(results => {
      const job = results[0];

      // load() waits for the job to finish
      assert.equal(job.status.state, 'DONE');
      console.log(`Job ${job.id} completed.`);

      // Check the job's status for errors
      const errors = job.status.errors;
      if (errors && errors.length > 0) {
        throw errors;
      }
    })
    .catch(err => {
      console.error('ERROR:', err);
    });
    callback();
};

【问题讨论】:

  • 您使用的是哪个版本的@google-cloud/bigquery?
  • @Kat 0.9.6。这就是为什么

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


【解决方案1】:

听起来您使用的 BigQuery 库版本在 Tables 上没有 load 函数。 load 函数于 2017 年 12 月在 version 0.12.0 中引入,之前称为 import

【讨论】:

    猜你喜欢
    • 2020-04-13
    • 2022-08-03
    • 2021-08-14
    • 1970-01-01
    • 1970-01-01
    • 2017-02-10
    • 2022-01-20
    • 2021-08-26
    • 1970-01-01
    相关资源
    最近更新 更多