Google Bigquery的应用脚本未知错误

时间:2014-09-16 15:23:58

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

CST这应该读入a然后写入bigquery。但是,当它运行时,没有写入任何内容,并且没有记录错误。我读到我需要编写一个csv,然后把它变成一个Octet Stream。我不确定这是否与google bigquery兼容。我也尝试删除setSourceUris,但没有出现任何错误。

function test(){
try{
 var tableReference = BigQuery.newTableReference();
 tableReference.setProjectId(PROJECT_ID);
 tableReference.setDatasetId(datasetId);
 tableReference.setTableId(tableId);
 var schema = "CUSTOMER:string, CLASSNUM:integer, CLASSDESC:string, CSR:string, CSR2:string,     INSURANCE:string, REFERRALGENERAL:string, REFERRALSPECIFIC:string, NOTES:string, INMIN:integer, INHR:integer, OUTMIN:integer, OUTHR:integer, WAITMIN:integer, WAITHR:integer, DATETIMESTAMP:float, DATEYR:integer,DATEMONTH:integer, DATEDAY:integer";
 var load = BigQuery.newJobConfigurationLoad();
 load.setDestinationTable(tableReference);
 load.setSourceUris(URIs);
 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 loadr = DriveApp.getFilesByName("test.csv");
 var x = loadr.next().getBlob();
 Logger.log(x.getDataAsString());

 var d = DriveApp.getFilesByName("test.csv");
 var id = d.next().getId();
 Logger.log(id);
 var data = DocsList.getFileById(id).getBlob().getDataAsString();
 var mediaData = Utilities.newBlob(data, 'application/octet-stream');

 BigQuery.Jobs.insert(newJob, PROJECT_ID, mediaData) 
} 
catch(error){Logger.log("A" + error.message);} 
}

1 个答案:

答案 0 :(得分:0)

Apps Script文档包含一些示例代码,展示了如何将CSV加载到bigquery中:https://developers.google.com/apps-script/advanced/bigquery#load_csv_data