Named query params with an empty array cannot be parsed
See original GitHub issueEnvironment details
- OS: High Sierra (10.13.6)
- Node.js version: 8.15.1
- npm version: 6.9.0
@google-cloud/bigquery
version: 2.1.0
Steps to reproduce
- Run a query with an empty array as the value of a named query param, e.g.
const [rows] = await bq.query({
query,
params: {
key: [],
},
});
- Query fails with
This value could not be translated to a BigQuery data type
. - Attempt to run the same query with an empty array literal in BigQuery UI or CLI and observe that the query succeeds:
...
WHERE `dataset.table`.Key IN UNNEST([])
Source of the error
I believe the error is a result of the login in https://github.com/googleapis/nodejs-bigquery/blob/ba5c82efc4c6f2aa50df2c386ab0b6894d0dd2aa/src/index.ts#L726
You can see that nodejs-bigquery
is trying to determine the type of the query param from the first element. If the array is empty, value[0]
is undefined
, and getType_()
throws an error. This issue is similar to https://github.com/googleapis/google-cloud-java/issues/2678, where they did fix it (and as they state there, it is not a limitation of the API).
EDIT: The API does seem to require specifying arrayType
, e.g.
"parameterType": {
"type": "ARRAY",
"arrayType": {
"type": "INT64"
}
},
Since JavaScript (unlike Java) doesn’t store the array type info at runtime (afaik), I wonder if there’s a way to supply the type explicitly in this case. Not sure if this is more of a feature request and would you consider a PR for it.
Thanks!
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (4 by maintainers)
@JustinBeckwith I’m changing this to a FR but I’m going to take it on next
@callmehiphop It seems like this is fixed w/ #4271; can you or @steffnay confirm?