【问题标题】:Apps script write to Big Query unknown error应用程序脚本写入 Big Query 未知错误
【发布时间】:2014-11-04 08:39:12
【问题描述】:

这应该读取 CSV,然后将其写入 bigquery。但是,当它运行时,没有写入任何内容,也没有记录任何错误。我读到我需要写一个 csv 然后把它变成一个八位字节流。我不确定这是否与 google bigquery 兼容。

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('NEWLINE_DELIMITED_JSON');
  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);}
}

【问题讨论】:

  • 您的问题有答案吗?谢谢

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


【解决方案1】:

您的 CSV 文件的 sourceFormat 错误:

数据文件的格式。对于 CSV 文件,指定“CSV”。为了 数据存储备份,指定“DATASTORE_BACKUP”。对于换行符 JSON,指定“NEWLINE_DELIMITED_JSON”。默认值为 CSV。

https://developers.google.com/bigquery/docs/reference/v2/jobs#configuration.load.sourceUris

另一方面,我认为您根本不需要 load.setSourceUris(URIs);,因为您尝试从本地文件加载,而不是从 Google Cloud Storage 加载。检查这个python示例https://developers.google.com/bigquery/loading-data-into-bigquery

【讨论】:

  • 我将 sourceFormat 更改为 CSV 并删除了 setSourceUris,但它仍然没有写入并且仍然没有显示错误。我再次放入 setSourceUris 并且没有错误。我真的不确定该怎么做。我需要做的就是让这部分工作,我完成了这个项目的 Bigquery 方面。
猜你喜欢
  • 2012-09-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-23
  • 2011-05-13
  • 2020-03-31
  • 1970-01-01
  • 2012-01-14
相关资源
最近更新 更多