Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.
This repository was archived by the owner on Feb 7, 2026. It is now read-only.

Named query params with an empty array cannot be parsed #400

@dinvlad

Description

@dinvlad

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

  1. 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: [],
  },
});
  1. Query fails with This value could not be translated to a BigQuery data type.
  2. 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!

Metadata

Metadata

Labels

api: bigqueryIssues related to the googleapis/nodejs-bigquery API.type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions