使用云功能将数据加载到BigQuery表中的问题

时间:2022-01-03 15:28:31

I'm having issues trying to load a Data store backup into an existing table in BigQuery. I'm getting the following error:

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

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

TypeError:bigquery.dataset(...)。table(...)。load不是函数

I'm following one of the examples in the BigQuery cloud Api repo.

我正在关注BigQuery云Api repo中的一个示例。

Not sure if I'm using this the wrong way, but what I'm trying to achieve is just have my cloud function update this BigQuery table from a Data Store dump, as opposed to delete and create daily - which seems counter productive and I was doing before.

我不确定我是否以错误的方式使用它,但我想要实现的只是让我的云功能从Data Store转储更新这个BigQuery表,而不是每天删除和创建 - 这似乎适得其反以前做过。

Here is my code:

这是我的代码:

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();
};

1 个解决方案

#1


2  

Sounds like you are using a version of the BigQuery library that doesn't have the load function on Tables. The load function was introduced in December 2017 in version 0.12.0 and was previously called import.

听起来你正在使用一个没有表上的加载功能的BigQuery库版本。加载功能于2017年12月在版本0.12.0中引入,之前称为导入。

#1


2  

Sounds like you are using a version of the BigQuery library that doesn't have the load function on Tables. The load function was introduced in December 2017 in version 0.12.0 and was previously called import.

听起来你正在使用一个没有表上的加载功能的BigQuery库版本。加载功能于2017年12月在版本0.12.0中引入,之前称为导入。