【问题标题】:standalone script for loading data from google spreadsheet to bigquery用于将数据从谷歌电子表格加载到 bigquery 的独立脚本
【发布时间】:2016-08-26 07:15:50
【问题描述】:

我编写了一个独立脚本,用于将数据从 csv 文件加载到 bigquery,但我想知道如何将数据从电子表格加载到 bigquery。这是我将数据从 csv 加载到 bigquery 的代码。我想知道在哪里对 google 电子表格而不是 csv 文件进行更改。

function loadCsv() {
  // Replace this value with the project ID listed in the Google
  // Developers Console project.
  var projectId = '775034665452';
  var datasetId = 'DEV';
  // Sample CSV file of Google Trends data conforming to the schema below.
  // https://docs.google.com/file/d/0BwzA1Orbvy5WMXFLaTR1Z1p2UDg/edit
  var csvFileId = '0BwzA1Orbvy5WMXFLaTR1Z1p2UDg';

  // Create the table.
  var tableId = 'pets_' + new Date().getTime();
  var table = {
    tableReference: {
      projectId: projectId,
      datasetId: datasetId,
      tableId: tableId
    },
    schema: {
      fields: [
        {name: 'week', type: 'STRING'},
        {name: 'cat', type: 'INTEGER'},
        {name: 'dog', type: 'INTEGER'},
        {name: 'bird', type: 'INTEGER'}
      ]
    }
  };
  table = BigQuery.Tables.insert(table, projectId, datasetId);
  Logger.log('Table created: %s', table.id);

  // Load CSV data from Drive and convert to the correct format for upload.
  var file = DriveApp.getFileById(csvFileId);
  var data = file.getBlob().setContentType('application/octet-stream');

  // Create the data upload job.
  var job = {
    configuration: {
      load: {
        destinationTable: {
          projectId: projectId,
          datasetId: datasetId,
          tableId: tableId
        },
        skipLeadingRows: 1
      }
    }
  };
  job = BigQuery.Jobs.insert(job, projectId, data);
  Logger.log('Load job started. Check on the status of it here: ' +
      'https://bigquery.cloud.google.com/jobs/%s', projectId);
}

【问题讨论】:

    标签: google-apps-script google-sheets google-bigquery


    【解决方案1】:

    您必须先将数据加载到 BigQuery 中,然后才能运行查询。

    您可以通过以下方式load data

    加载的数据可以添加到新表、附加到表或覆盖表。

    BigQuery 支持从多种源格式加载数据,包括 CSV、JSON、Avro 和 Google Cloud Datastore 备份文件。如需更多信息,请参阅Data Formats

    正在加载 CSV 文件,请检查:https://cloud.google.com/bigquery/loading-data#loading_csv_files

    【讨论】:

    • 感谢您的信息!!但我想知道我们是否可以编写一个脚本来将数据从电子表格加载到 bigquery,而不是从 GCS 或手动加载。
    • 是的,请检查此文档伙伴:cloud.google.com/blog/big-data/2016/05/…
    猜你喜欢
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    • 2012-06-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多