javascript - Apps script write to Big Query unknown error -
this supposed read in csv , write bigquery. when runs, however, nothing written, , there no errors logged. read need write csv , turn octet stream. not sure whether or not compatible 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);} }
your sourceformat wrong csv files:
the format of data files. csv files, specify "csv". datastore backups, specify "datastore_backup". newline-delimited json, specify "newline_delimited_json". default value csv.
https://developers.google.com/bigquery/docs/reference/v2/jobs#configuration.load.sourceuris
on other hand think don't need @ load.setsourceuris(uris);
since try load local file, , not google cloud storage. check python example https://developers.google.com/bigquery/loading-data-into-bigquery
Comments
Post a Comment