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

feat: support JSON query param #1329

Merged
merged 3 commits into from
Jan 24, 2024
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
4 changes: 4 additions & 0 deletions src/bigquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,17 +312,17 @@
export class BigQuery extends Service {
location?: string;

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

Check warning on line 315 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 320 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 325 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 @@ -1005,6 +1005,8 @@
'GEOGRAPHY',
'ARRAY',
'STRUCT',
'JSON',
'RANGE',
];

if (is.array(providedType)) {
Expand Down Expand Up @@ -1182,6 +1184,8 @@
},
{}
);
} else if (typeName === 'JSON' && is.object(value)) {
queryParameter.parameterValue!.value = JSON.stringify(value);
} else {
queryParameter.parameterValue!.value = BigQuery._getValue(
value,
Expand Down
27 changes: 27 additions & 0 deletions test/bigquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,33 @@ describe('BigQuery', () => {
assert.deepStrictEqual(param, expectedParam);
});

it('should format JSON types', () => {
const typeName = 'JSON';
const value = {
foo: 'bar',
};
const strValue = JSON.stringify(value);
assert.deepStrictEqual(BigQuery.valueToQueryParameter_(value, typeName), {
parameterType: {
type: typeName,
},
parameterValue: {
value: strValue,
},
});
assert.deepStrictEqual(
BigQuery.valueToQueryParameter_(strValue, typeName),
{
parameterType: {
type: typeName,
},
parameterValue: {
value: strValue,
},
}
);
});

it('should format all other types', () => {
const typeName = 'ANY-TYPE';
sandbox.stub(BigQuery, 'getTypeDescriptorFromValue_').returns({
Expand Down
Loading