【问题标题】:load csv file from cloud storage to big query将 csv 文件从云存储加载到大查询
【发布时间】:2016-10-12 17:05:23
【问题描述】:

我正在尝试使用应用程序脚本将 Cloud Storage 中的简单 cvs 文件加载到 BigQuery 表中。我已经创建了表并希望将文件附加到表中的现有数据中。当我运行脚本时,我收到以下错误消息“mediaData 参数仅支持 Blob 类型的上传”。我不确定如何在这方面取得进展,并且在寻找答案时遇到了障碍。这是我正在使用的代码 sn-p:

function loadCloudStorageFileToBigQuery(source, datasetId, tableId, schema) {  
    try{
        var tableReference = BigQuery.newTableReference();
        tableReference.setProjectId(MY_PROJECT);
        tableReference.setDatasetId(datasetId);
        tableReference.setTableId(tableId);

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

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

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

        var job = BigQuery.Jobs.insert(newJob, null, {projectId:MY_PROJECT});

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

任何建议或帮助将不胜感激。

【问题讨论】:

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


    【解决方案1】:

    我通过简单地将实际加载插入更改为以下内容来解决问题:

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

    我还删除了架构,因为表已经存在

    工作函数如下:

            var tableReference = BigQuery.newTableReference();
            tableReference.setProjectId(MY_PROJECT);
            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, MY_PROJECT);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多