question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Named query params with an empty array cannot be parsed

See original GitHub issue

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 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:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
callmehiphopcommented, Oct 17, 2019

@JustinBeckwith I’m changing this to a FR but I’m going to take it on next

1reaction
meredithslotacommented, Nov 21, 2019

@callmehiphop It seems like this is fixed w/ #4271; can you or @steffnay confirm?

Read more comments on GitHub >

github_iconTop Results From Across the Web

nuxt.js - How to handle empty array as params with $fetch?
i am building a search interface with filters and searchbox. The framework i'm using is Nuxt3. On the one hand I use $fetch...
Read more >
42961 (REST API: Cannot pass empty object url encoded data)
A post request to any of this endpoints has no possible ways to clear the arrays using queryparams. Yes, JSON works but JSON...
Read more >
URL | Node.js v19.3.0 Documentation
Parsing the URL string using the WHATWG API: ... values of all name-value pairs whose name is name . If there are no...
Read more >
Running parameterized queries | BigQuery - Google Cloud
Parameters cannot be used as substitutes for identifiers, column names, table names, or other parts of the query. To specify a named parameter, ......
Read more >
TypeError: Reduce of empty array with no initial value
In JavaScript, there are several reduce functions: ... These functions optionally take an initialValue (which will be used as the first argument to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found