【问题标题】:How to set the schema for a table to autodetect in Google App Scripts fetching data from Google Cloud Storage?如何设置表的架构以在 Google App Scripts 中自动检测从 Google Cloud Storage 获取数据?
【发布时间】:2018-03-20 17:12:32
【问题描述】:

我有一个 Google 应用脚本,它通过从 Google Cloud Storage 获取更新的数据来自动更新 Bigquery 中的表。

function loadCloudStorageFileToBigQuery(source,ProjectId, datasetId, tableId, schema) {  
    try{

        source="xxxxx";
        ProjectId="xxxxxx";
        datasetId="xxxxxx";
        tableId="xxxxxxx";
        schema={"configuration.load.autodetect":'true'};

        var tableReference = BigQuery.newTableReference();
        tableReference.setProjectId(ProjectId);
        tableReference.setDatasetId(datasetId);
        tableReference.setTableId(tableId);

        var load = BigQuery.newJobConfigurationLoad();
        load.setDestinationTable(tableReference);
        load.setSourceUris([source]);
        load.setSourceFormat('CSV');
        load.setMaxBadRecords(0);
        load.setWriteDisposition('WRITE_APPEND');

        var configuration = BigQuery.newJobConfiguration();
        configuration.setLoad(load);

        var newJob = BigQuery.newJob();
        newJob.setConfiguration(configuration);

        var job = BigQuery.Jobs.insert(newJob, ProjectId);

    }catch(err){ 
        Logger.log('Table upload error: %s', err);  
    } 
}

脚本似乎工作正常,因为我可以在大查询中看到作业历史记录中的错误。该错误表示未定义架构。我想将架构设置为自动检测。有人可以建议我需要在脚本中进行哪些更改吗?

【问题讨论】:

    标签: google-apps-script google-bigquery google-cloud-storage


    【解决方案1】:

    添加“load.setAutodetect(true);”

    更多详情: https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs#configuration.load

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-22
      • 1970-01-01
      • 2016-02-05
      • 1970-01-01
      • 2014-12-05
      • 2020-09-26
      相关资源
      最近更新 更多