代码之家  ›  专栏  ›  技术社区  ›  mauricioSanchez

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

  •  0
  • mauricioSanchez  · 技术社区  · 7 年前

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

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

    我在下面的例子中 BigQuery cloud Api 回购协议。

    我不确定我是否使用了错误的方法,但我试图实现的是让我的云函数从数据存储转储中更新这个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();
    };
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   Kat    7 年前

    听起来您使用的BigQuery库版本没有 load 作用于 Table s、 那个 负载 功能于2017年12月引入 version 0.12.0 之前被称为 import .

    推荐文章