Skip to content

Commit fb13510

Browse files
authored
fix: pass Query.wrapIntegers to job.getQueryResults (#1191)
`Query.wrapIntegers` was being ignored and not passed to `job.getQueryResults` when used in `bigquery.query`.
1 parent b5801a6 commit fb13510

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

β€Žsrc/bigquery.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ export class BigQuery extends Service {
928928
'value ' +
929929
value.integerValue +
930930
" is out of bounds of 'Number.MAX_SAFE_INTEGER'.\n" +
931-
"To prevent this error, please consider passing 'options.wrapNumbers' as\n" +
931+
"To prevent this error, please consider passing 'options.wrapIntegers' as\n" +
932932
'{\n' +
933933
' integerTypeCastFunction: provide <your_custom_function>\n' +
934934
' fields: optionally specify field name(s) to be custom casted\n' +
@@ -2025,6 +2025,12 @@ export class BigQuery extends Service {
20252025
): void | Promise<SimpleQueryRowsResponse> | Promise<QueryRowsResponse> {
20262026
let options =
20272027
typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
2028+
const queryOpts =
2029+
typeof query === 'object'
2030+
? {
2031+
wrapIntegers: query.wrapIntegers,
2032+
}
2033+
: {};
20282034
const callback =
20292035
typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;
20302036
this.createQueryJob(query, (err, job, resp) => {
@@ -2038,7 +2044,7 @@ export class BigQuery extends Service {
20382044
}
20392045
// The Job is important for the `queryAsStream_` method, so a new query
20402046
// isn't created each time results are polled for.
2041-
options = extend({job}, options);
2047+
options = extend({job}, queryOpts, options);
20422048
job!.getQueryResults(options, callback as QueryRowsCallback);
20432049
});
20442050
}
@@ -2283,7 +2289,6 @@ export class BigQueryInt extends Number {
22832289
throw error;
22842290
}
22852291
} else {
2286-
// return this.value;
22872292
return BigQuery.decodeIntegerValue_({
22882293
integerValue: this.value,
22892294
schemaFieldName: this._schemaFieldName,

β€Žtest/bigquery.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ describe('BigQuery', () => {
926926
'value ' +
927927
opts.integerValue +
928928
" is out of bounds of 'Number.MAX_SAFE_INTEGER'.\n" +
929-
"To prevent this error, please consider passing 'options.wrapNumbers' as\n" +
929+
"To prevent this error, please consider passing 'options.wrapIntegers' as\n" +
930930
'{\n' +
931931
' integerTypeCastFunction: provide <your_custom_function>\n' +
932932
' fields: optionally specify field name(s) to be custom casted\n' +
@@ -2720,6 +2720,35 @@ describe('BigQuery', () => {
27202720
});
27212721
});
27222722

2723+
it('should call job#getQueryResults with query options', done => {
2724+
let queryResultsOpts = {};
2725+
const fakeJob = {
2726+
getQueryResults: (options: {}, callback: Function) => {
2727+
queryResultsOpts = options;
2728+
callback(null, FAKE_ROWS, FAKE_RESPONSE);
2729+
},
2730+
};
2731+
2732+
bq.createQueryJob = (query: {}, callback: Function) => {
2733+
callback(null, fakeJob, FAKE_RESPONSE);
2734+
};
2735+
2736+
const query = {
2737+
query: QUERY_STRING,
2738+
wrapIntegers: true,
2739+
};
2740+
bq.query(query, (err: Error, rows: {}, resp: {}) => {
2741+
assert.ifError(err);
2742+
assert.deepEqual(queryResultsOpts, {
2743+
job: fakeJob,
2744+
wrapIntegers: true,
2745+
});
2746+
assert.strictEqual(rows, FAKE_ROWS);
2747+
assert.strictEqual(resp, FAKE_RESPONSE);
2748+
done();
2749+
});
2750+
});
2751+
27232752
it('should assign Job on the options', done => {
27242753
const fakeJob = {
27252754
getQueryResults: (options: {}) => {

0 commit comments

Comments
 (0)