0

我正嘗試使用應用程序腳本將雲存儲中的簡單cvs文件加載到BigQuery表中。我已經創建了該表並希望將該文件附加到表中的現有數據。當我運行該腳本時,出現以下錯誤消息'mediaData參數僅支持上傳的Blob類型'。我不確定如何進步並找到答案。這裏是我使用的代碼片段:將雲存儲中的csv文件加載到大查詢

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

任何意見或幫助將不勝感激。

回答

0

我通過簡單地改變實際加載插入到解決的問題如下:

變種作業= 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); 
相關問題