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

fix: should not override queryParameters if params not informed #1359

Merged
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
16 changes: 9 additions & 7 deletions src/bigquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,17 +336,17 @@
private _universeDomain: string;
private _enableQueryPreview: boolean;

createQueryStream(options?: Query | string): ResourceStream<RowMetadata> {

Check warning on line 339 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

'options' is defined but never used
// placeholder body, overwritten in constructor
return new ResourceStream<RowMetadata>({}, () => {});
}

getDatasetsStream(options?: GetDatasetsOptions): ResourceStream<Dataset> {

Check warning on line 344 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

'options' is defined but never used
// placeholder body, overwritten in constructor
return new ResourceStream<Dataset>({}, () => {});
}

getJobsStream(options?: GetJobsOptions): ResourceStream<Job> {

Check warning on line 349 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

'options' is defined but never used
// placeholder body, overwritten in constructor
return new ResourceStream<Job>({}, () => {});
}
Expand Down Expand Up @@ -1469,13 +1469,15 @@
delete query.destination;
}

const {parameterMode, params} = this.buildQueryParams_(
query.params,
query.types
);
query.parameterMode = parameterMode;
query.queryParameters = params;
delete query.params;
if (query.params) {
const {parameterMode, params} = this.buildQueryParams_(
query.params,
query.types
);
query.parameterMode = parameterMode;
query.queryParameters = params;
delete query.params;
}

const reqOpts: JobOptions = {};
reqOpts.configuration = {
Expand Down Expand Up @@ -1531,7 +1533,7 @@
const parameterMode = is.array(params) ? 'positional' : 'named';
const queryParameters: bigquery.IQueryParameter[] = [];
if (parameterMode === 'named') {
const namedParams = params as {[param: string]: any};

Check warning on line 1536 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
for (const namedParameter of Object.getOwnPropertyNames(namedParams)) {
const value = namedParams[namedParameter];
let queryParameter;
Expand Down Expand Up @@ -2174,7 +2176,7 @@

options = extend({job}, queryOpts, options);
if (res && res.jobComplete) {
let rows: any = [];

Check warning on line 2179 in src/bigquery.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
if (res.schema && res.rows) {
rows = BigQuery.mergeSchemaWithRows_(res.schema, res.rows, {
wrapIntegers: options.wrapIntegers || false,
Expand Down
20 changes: 20 additions & 0 deletions test/bigquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2343,6 +2343,26 @@ describe('BigQuery', () => {
);
});

it('should not modify queryParameters if params is not informed', done => {
bq.createJob = (reqOpts: JobOptions) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
assert.strictEqual((reqOpts as any).params, undefined);
assert.deepStrictEqual(
reqOpts.configuration?.query?.queryParameters,
NAMED_PARAMS
);
done();
};

bq.createQueryJob(
{
query: QUERY_STRING,
queryParameters: NAMED_PARAMS,
},
assert.ifError
);
});

describe('named', () => {
it('should set the correct parameter mode', done => {
bq.createJob = (reqOpts: JobOptions) => {
Expand Down
Loading