Saturday, 15 August 2015

google apps script - Bigquery API: Running query with destinationTable does not save results -



google apps script - Bigquery API: Running query with destinationTable does not save results -

i'm trying utilize google apps script automate daily aggregation process. thought run on few tables 1 dataset, , save results table on sec dataset. user has permissions on both relevant datasets.

my request looks follows

var request = { "maxresults": 10000, "usequerycache": false, "destinationtable": { "projectid": "project_name_obfuscated", "datasetid": "project_114151_shared", "tableid": "test123" }, "writedisposition": "write_truncate", "createdisposition": "create_if_needed", "allowlargeresults": true, "query": "query syntax here" }; var queryresults = bigquery.jobs.query(request, "project_name_obfuscated");

(i've obfuscated name of projects , query confidentiality reasons).

the query runs fine, however, it's not beingness saved designated project/dataset/table i've defined.

in bq ui i'm seeing like:

job id: project_name_obfuscated:job_nhkqpi110p3i5yooo7nzxp3ttky start time: 5:47pm, 20 oct 2014 end time: 5:47pm, 20 oct 2014 bytes processed: 0 b destination table: project_name_obfuscated:_138c3340e691065e8db0b55781b5a41c6b4bcd49.anonev_soiirc10lfetj000kcj4rmxnc5e

any ideas i'm doing wrong?

you're using arguments available via jobs.insert in jobs.query method. jobs.query intended quick, synchronous queries, , doesn't back upwards total range of options available in jobs.insert, asynchronous version.

try like:

var configuration = { "query": { "usequerycache": false, "destinationtable": { "projectid": "project_name_obfuscated", "datasetid": "project_114151_shared", "tableid": "test123" }, "writedisposition": "write_truncate", "createdisposition": "create_if_needed", "allowlargeresults": true, "query": "query syntax here" } }; var job = { "configuration": configuration }; var jobresult = bigquery.jobs.insert(job, "project_name_obfuscated"); var jobid = jobresult.jobreference.jobid; // job might not done; wait until marked // complete. var sleeptimems = 500; while (true) { utilities.sleep(sleeptimems); sleeptimems *= 2; queryresults = bigquery.jobs.getqueryresults(projectid, jobid, { "maxresults": 10000); if (!queryresults.jobcomplete) { break; } }

google-apps-script google-bigquery

No comments:

Post a Comment