Environment 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
|
arrayType: BigQuery.getType_(value[0]), |
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 googleapis/google-cloud-java#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!
Environment details
@google-cloud/bigqueryversion: 2.1.0Steps to reproduce
This value could not be translated to a BigQuery data type.Source of the error
I believe the error is a result of the login in
nodejs-bigquery/src/index.ts
Line 726 in ba5c82e
You can see that
nodejs-bigqueryis trying to determine the type of the query param from the first element. If the array is empty,value[0]isundefined, andgetType_()throws an error. This issue is similar to googleapis/google-cloud-java#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.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!