From 29194d3cbd3e2312cf2b8072e25e6a92f6310036 Mon Sep 17 00:00:00 2001 From: Stephen Sawchuk Date: Wed, 10 Jun 2015 09:58:40 -0400 Subject: [PATCH] bigquery#query: stop passing Job object to API --- lib/bigquery/index.js | 10 ++++++++-- test/bigquery/index.js | 20 +++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/bigquery/index.js b/lib/bigquery/index.js index 27620c7008f..d5697ac681d 100644 --- a/lib/bigquery/index.js +++ b/lib/bigquery/index.js @@ -361,6 +361,11 @@ BigQuery.prototype.query = function(options, callback) { options = options || {}; + var requestQuery = { + maxResults: options.maxResults, + timeoutMs: options.timeoutMs, + }; + if (!util.is(callback, 'function')) { stream = streamEvents(through.obj()); stream.once('reading', runQuery); @@ -372,8 +377,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..612ca68956a 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() {