Skip to content

Commit

Permalink
Merge pull request #652 from stephenplusplus/spp--bigquery-limit-api-…
Browse files Browse the repository at this point in the history
…passthrough

bigquery#query: stop passing Job object to API
  • Loading branch information
stephenplusplus committed Jun 10, 2015
2 parents 01ec51f + 061bf39 commit 525c9d5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
8 changes: 6 additions & 2 deletions lib/bigquery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
20 changes: 15 additions & 5 deletions test/bigquery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,23 +366,33 @@ 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();
};

bq.query(options, assert.ifError);
});

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() {
Expand Down

0 comments on commit 525c9d5

Please sign in to comment.