Database Reference
In-Depth Information
* Pulls the field names out of query results.
Retrurns them
* as a 2D array with 1 row, so they can be written
via the
* same mechanism we use to write rows of data.
*/
function extractHeaders(fields) {
return [fields.map(function(field) {return
field.name;})];
}
/**
* Runs a given SQL query and writes the results to
the chunkWriter
* one page at a time. This is preferable to returning
results, since
* the query results may be large.
*/
function runSqlQuery(projectId, sql, chunkWriter) {
Logger.log('%s: Running query: %s', projectId, sql);
var resource = {
'query': sql,
'maxResults': MAX_RESULTS_PER_PAGE
};
var queryResults = BigQuery.Jobs.query(resource,
projectId);
var jobId = queryResults.jobReference.jobId;
// The job might not actually be done; wait until it
is marked
// complete. For simple queries, it will have
completed within the
// default timeout, but for more complex queries
(JOIN, etc), you
// might find the query takes a long time.
var sleepTimeMs = 500;
while (!queryResults.jobComplete) {
Search WWH ::




Custom Search