Skip to content

Commit

Permalink
bigquery: remove extraneous info from query result requests (#2341)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus authored Jun 1, 2017
1 parent b9c1ebe commit 3370862
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
43 changes: 24 additions & 19 deletions packages/bigquery/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,24 @@ BigQuery.prototype.query = function(options, callback) {

options = options || {};

var job = options.job;

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

if (job) {
// Get results of the query.
delete requestQuery.params;
delete requestQuery.query;

self.request({
uri: '/queries/' + job.id,
qs: requestQuery
}, responseHandler);

return;
}

if (options.params) {
options.useLegacySql = false;
options.parameterMode = is.array(options.params) ? 'positional' : 'named';
Expand All @@ -811,25 +829,12 @@ BigQuery.prototype.query = function(options, callback) {
delete options.params;
}

var job = options.job;

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

if (job) {
// Get results of the query.
self.request({
uri: '/queries/' + job.id,
qs: requestQuery
}, responseHandler);
} else {
// Create a job.
self.request({
method: 'POST',
uri: '/queries',
json: options
}, responseHandler);
}
// Create a job.
self.request({
method: 'POST',
uri: '/queries',
json: options
}, responseHandler);

function responseHandler(err, resp) {
if (err) {
Expand Down
24 changes: 24 additions & 0 deletions packages/bigquery/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,30 @@ describe('BigQuery', function() {
bq.query(options, assert.ifError);
});

it('should not include query info in result query', function(done) {
var options = {
job: bq.job(JOB_ID),
maxResults: 10,
timeoutMs: 8,

// should be removed:
params: {},
query: '...'
};

var expectedRequestQuery = {
maxResults: 10,
timeoutMs: 8
};

bq.request = function(reqOpts) {
assert.deepEqual(reqOpts.qs, expectedRequestQuery);
done();
};

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

describe('SQL parameters', function() {
var NAMED_PARAMS = {
key: 'value'
Expand Down

0 comments on commit 3370862

Please sign in to comment.