Save table on google big query using google app script -


i trying save table using app script. want use table in query in same script. need wait before first table created second query can find date in google big query project.

{     {          var projectid = 'p1';         var datasetid = 'd1';         var tableid = 'rr_signup1_' + week;         logger.log(tableid);          var job = {             configuration: {                 query: {                     query: 'query desciption',                      destinationtable : {                         projectid: projectid,                         datasetid : datasetid,                                 tableid : tableid                     }                 }             }         };     }      var queryresults = bigquery.jobs.insert(job, projectid);     var jobid = queryresults.jobreference.jobid;     logger.log(queryresults.status);     var sleeptimems = 500;     while (true) {         utilities.sleep(sleeptimems);         sleeptimems *= 2;         queryresults = bigquery.jobs.getqueryresults(projectid, jobid);         if (!queryresults.jobcomplete) {             break;         }     }       {         {             var projectid = 'p1';             var datasetid = 'd1';             var tableid = 'rr_signup2_' + week;             logger.log(tableid);              var job = {                 configuration: {                     query: {                         query: 'select  uid, signup_time [' + tableid1 + '] ;',                         destinationtable : {                             projectid: projectid,                             datasetid : datasetid,                             tableid : tableid                         }                     }                 }             };         }          var queryresults = bigquery.jobs.insert(job, projectid);         var jobid = queryresults.jobreference.jobid;         logger.log(queryresults.status);         var sleeptimems = 500;         while (true) {             utilities.sleep(sleeptimems);             sleeptimems *= 2;             queryresults = bigquery.jobs.getqueryresults(projectid, jobid);             if (!queryresults.jobcomplete) {                 break;             }         } 

the code creates first table , goes infinite loop , times out eventually. state of query not change running done

this code use check state of insert job:

job = bigquery.jobs.insert(job, projectid, data); var jobid = job.jobreference.jobid; var status = null;  // check on status of query job. var sleeptimems = 1000; while (job.status.state != "done") { if (job.status.errorresult != null)   status = "fail" utilities.sleep(sleeptimems); job = bigquery.jobs.get(projectid, jobid); }  if (status != "fail") {    logger.log('load job started. jobid: ' + jobid); } else { logger.log('load job error. jobid: ' + jobid + "\r\nerrors: " +  job.status.errors[0].message + " | " + job.status.errors[0].location); } 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -