[go: up one dir, main page]

Skip to content

Commit

Permalink
fix: pass Query.wrapIntegers to job.getQueryResults (#1191)
Browse files Browse the repository at this point in the history
`Query.wrapIntegers` was being ignored and not passed to `job.getQueryResults` when used in `bigquery.query`.
  • Loading branch information
alvarowolfx committed Mar 17, 2023
1 parent b5801a6 commit fb13510
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
11 changes: 8 additions & 3 deletions src/bigquery.ts
Expand Up @@ -928,7 +928,7 @@ export class BigQuery extends Service {
'value ' +
value.integerValue +
" is out of bounds of 'Number.MAX_SAFE_INTEGER'.\n" +
"To prevent this error, please consider passing 'options.wrapNumbers' as\n" +
"To prevent this error, please consider passing 'options.wrapIntegers' as\n" +
'{\n' +
' integerTypeCastFunction: provide <your_custom_function>\n' +
' fields: optionally specify field name(s) to be custom casted\n' +
Expand Down Expand Up @@ -2025,6 +2025,12 @@ export class BigQuery extends Service {
): void | Promise<SimpleQueryRowsResponse> | Promise<QueryRowsResponse> {
let options =
typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
const queryOpts =
typeof query === 'object'
? {
wrapIntegers: query.wrapIntegers,
}
: {};
const callback =
typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
this.createQueryJob(query, (err, job, resp) => {
Expand All @@ -2038,7 +2044,7 @@ export class BigQuery extends Service {
}
// The Job is important for the `queryAsStream_` method, so a new query
// isn't created each time results are polled for.
options = extend({job}, options);
options = extend({job}, queryOpts, options);
job!.getQueryResults(options, callback as QueryRowsCallback);
});
}
Expand Down Expand Up @@ -2283,7 +2289,6 @@ export class BigQueryInt extends Number {
throw error;
}
} else {
// return this.value;
return BigQuery.decodeIntegerValue_({
integerValue: this.value,
schemaFieldName: this._schemaFieldName,
Expand Down
31 changes: 30 additions & 1 deletion test/bigquery.ts
Expand Up @@ -926,7 +926,7 @@ describe('BigQuery', () => {
'value ' +
opts.integerValue +
" is out of bounds of 'Number.MAX_SAFE_INTEGER'.\n" +
"To prevent this error, please consider passing 'options.wrapNumbers' as\n" +
"To prevent this error, please consider passing 'options.wrapIntegers' as\n" +
'{\n' +
' integerTypeCastFunction: provide <your_custom_function>\n' +
' fields: optionally specify field name(s) to be custom casted\n' +
Expand Down Expand Up @@ -2720,6 +2720,35 @@ describe('BigQuery', () => {
});
});

it('should call job#getQueryResults with query options', done => {
let queryResultsOpts = {};
const fakeJob = {
getQueryResults: (options: {}, callback: Function) => {
queryResultsOpts = options;
callback(null, FAKE_ROWS, FAKE_RESPONSE);
},
};

bq.createQueryJob = (query: {}, callback: Function) => {
callback(null, fakeJob, FAKE_RESPONSE);
};

const query = {
query: QUERY_STRING,
wrapIntegers: true,
};
bq.query(query, (err: Error, rows: {}, resp: {}) => {
assert.ifError(err);
assert.deepEqual(queryResultsOpts, {
job: fakeJob,
wrapIntegers: true,
});
assert.strictEqual(rows, FAKE_ROWS);
assert.strictEqual(resp, FAKE_RESPONSE);
done();
});
});

it('should assign Job on the options', done => {
const fakeJob = {
getQueryResults: (options: {}) => {
Expand Down

0 comments on commit fb13510

Please sign in to comment.