javascript - 使用云函数将数据加载到 BigQuery 表中时出现问题

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

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

类型错误:bigquery.dataset(...).table(...).load 不是函数

我正在遵循 BigQuery cloud Api 中的示例之一 repo 协议(protocol)。

不确定我是否使用了错误的方式,但我想要实现的只是让我的云函数从数据存储转储中更新此 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();
};

最佳答案

听起来您使用的 BigQuery 库版本在 Table 上没有 load 功能。 load 函数于 2017 年 12 月在 version 0.12.0 中引入。以前称为导入

关于javascript - 使用云函数将数据加载到 BigQuery 表中时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50374985/

相关文章:

node.js - 在浏览器中查看而非下载 Google Cloud Storage 文件

javascript - 在一页中加载多个视频

node.js - "npm install socket.io"错误

javascript - Ember.js 错误 : Object Photo has no method 'eachRelatedType'

python - AES - 使用 Crypto (node-js) 加密/使用 Pycrypto (python) 解密

mongodb - 是否可以使用 $inc 通过 Mongoose 更新子文档?

go - 用于 Golang 的稳定 GCP PubSub API

google-cloud-platform - 更新 BigQuery 永久外部表

javascript - Ajax 提交后打开一个新窗口

javascript - 从 javascript 字符串中删除 http 或 https