diff --git a/lib/bigquery/index.js b/lib/bigquery/index.js index 27620c7008f..2d2c2d5c010 100644 --- a/lib/bigquery/index.js +++ b/lib/bigquery/index.js @@ -361,6 +361,9 @@ BigQuery.prototype.query = function(options, callback) { options = options || {}; + var requestQuery = extend({}, options); + delete requestQuery.job; + if (!util.is(callback, 'function')) { stream = streamEvents(through.obj()); stream.once('reading', runQuery); @@ -372,8 +375,9 @@ BigQuery.prototype.query = function(options, callback) { function runQuery() { if (options.job) { - that.makeReq_( - 'GET', '/queries/' + options.job.id, options, null, responseHandler); + // Get results of the query. + var path = '/queries/' + options.job.id; + that.makeReq_('GET', path, requestQuery, null, responseHandler); } else { // Create a job. that.makeReq_('POST', '/queries', null, options, responseHandler); diff --git a/test/bigquery/index.js b/test/bigquery/index.js index 47856181ad7..3758d60a335 100644 --- a/test/bigquery/index.js +++ b/test/bigquery/index.js @@ -366,9 +366,7 @@ describe('BigQuery', function() { }; bq.makeReq_ = function(method, path, query, body) { - assert.equal(body.query, QUERY_STRING); - assert.equal(body.a, 'b'); - assert.equal(body.c, 'd'); + assert.deepEqual(body, options); done(); }; @@ -376,13 +374,25 @@ describe('BigQuery', function() { }); it('should get the results of a job if one is provided', function(done) { - bq.makeReq_ = function(method, path) { + var options = { + job: bq.job(JOB_ID), + maxResults: 10, + timeoutMs: 8 + }; + + var expectedRequestQuery = { + maxResults: 10, + timeoutMs: 8 + }; + + bq.makeReq_ = function(method, path, query) { assert.equal(method, 'GET'); assert.equal(path, '/queries/' + JOB_ID); + assert.deepEqual(query, expectedRequestQuery); done(); }; - bq.query({ job: bq.job(JOB_ID) }, assert.ifError); + bq.query(options, assert.ifError); }); it('should be a stream if a callback is omitted', function() {