Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bigquery#query: stop passing Job object to API #652

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
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