Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions lib/bigquery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ BigQuery.prototype.query = function(options, callback) {

options = options || {};

var job = options.job;

var requestQuery = extend({}, options);
delete requestQuery.job;

Expand All @@ -374,9 +376,9 @@ BigQuery.prototype.query = function(options, callback) {
}

function runQuery() {
if (options.job) {
if (job) {
// Get results of the query.
var path = '/queries/' + options.job.id;
var path = '/queries/' + job.id;
that.makeReq_('GET', path, requestQuery, null, responseHandler);
} else {
// Create a job.
Expand All @@ -389,23 +391,25 @@ BigQuery.prototype.query = function(options, callback) {
return;
}

var job = that.job(resp.jobReference.jobId);
var nextQuery = null;
var rows = Table.mergeSchemaWithRows_(resp.schema, resp.rows || []);
var rows = [];
if (resp.schema && resp.rows) {
rows = Table.mergeSchemaWithRows_(resp.schema, resp.rows);
}

var nextQuery = null;
if (resp.jobComplete === false) {
// Query is still running.
nextQuery = extend({
job: job
}, options);
nextQuery = extend({}, options);
} else if (resp.pageToken) {
// More results exist.
nextQuery = extend({
job: job
}, options, {
nextQuery = extend({}, options, {
pageToken: resp.pageToken
});
}
if (nextQuery && !nextQuery.job && resp.jobReference.jobId) {
// Create a prepared Job to continue the query.
nextQuery.job = that.job(resp.jobReference.jobId);
}

onComplete(null, rows, nextQuery, resp);
}
Expand Down
2 changes: 1 addition & 1 deletion test/bigquery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function fakeGsa() {
}

describe('BigQuery', function() {
var JOB_ID = JOB_ID;
var JOB_ID = 'JOB_ID';
var PROJECT_ID = 'test-project';

var BigQuery;
Expand Down