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

BigQueryV2: Allow passing an empty array as a value for params #4269

Closed
wants to merge 1 commit into from

Conversation

knu
Copy link

@knu knu commented Oct 23, 2019

Currently passing an empty array causes the following error:

NoMethodError: undefined method `parameter_type' for nil:NilClass

This is due to Convert.to_query_param trying to use the type of the first element as array_type without checking if a given array has an element.

This PR adds the necessary check.

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Oct 23, 2019
@quartzmo quartzmo added the api: bigquery Issues related to the BigQuery API. label Oct 23, 2019
@quartzmo
Copy link
Member

@knu Thank you for submitting this pull request!

@blowmage blowmage self-assigned this Oct 23, 2019
@quartzmo
Copy link
Member

Related issue in google-cloud-java? googleapis/google-cloud-java#2678

@blowmage
Copy link
Contributor

blowmage commented Nov 7, 2019

Thank you for your pull request. Unfortunately we have addressed this issue in a different manner. After discussions with the BigQuery team we have decided to add an optional types argument. This new argument is used to specify the type of a query parameter when one can't be determined. So while PR has elected to use STRING when a type can't be determined, users will have to specify this as follows:

data = dataset.query "SELECT name FROM my_table " \
                     "WHERE url IN UNNEST(@urls)",
                     params: { urls: [] },
                     types: { urls: [:STRING] }

Users are also able to specify a non-STRING array:

data = dataset.query "SELECT name FROM my_table " \
                     "WHERE id IN UNNEST(@ids)",
                     params: { ids: [] },
                     types: { ids: [:INT64] }

@quartzmo
Copy link
Member

@pdfabbro Did you intend to post this comment regarding googleapis/nodejs-bigquery here on a googleapis/google-cloud-ruby PR?

@quartzmo
Copy link
Member

I think maybe you should post it here? Sorry if I'm not understanding something about how this is relevant to the Ruby client.

https://github.com/googleapis/nodejs-bigquery/issues

@quartzmo
Copy link
Member

Great, thanks. I'll verify your observations with the Ruby client and open a new issue for this repo (a sibling to the nodejs repo) if needed. Appreciate the heads up!

@quartzmo
Copy link
Member

The new issue related to null parameter values is googleapis/nodejs-bigquery#915.

@knu knu changed the title Allow passing an empty array as a value for params BigQuery: Allow passing an empty array as a value for params Feb 5, 2021
@knu knu changed the title BigQuery: Allow passing an empty array as a value for params BigQueryV2: Allow passing an empty array as a value for params Feb 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigquery Issues related to the BigQuery API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants