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

BigQuery: Add support for array parameters to Cursor.execute() #9189

Merged
merged 2 commits into from
Sep 10, 2019

Conversation

plamut
Copy link
Contributor

@plamut plamut commented Sep 9, 2019

Closes #9177.

This PR adds support for array-like query parameters.

How to test

Run the example from the issue description (slightly modified, see below). Binding an array-like parameter to a parametrized query should not raise an error, and the following should work as expected:

curr.execute(query, (('NY', 'TX'), ))

Mind that scanning arrays requires using IN UNNEST(...) construct (docs), thus the UNNEST function needs to be added to the query from the issue description:

query = """
  SELECT name, state
  FROM `bigquery-public-data.usa_names.usa_1910_2013`
  WHERE state IN UNNEST(%s)
  LIMIT 2
"""

Footnotes

  • No nested arrays support, only for arrays of scalar types.
  • Detecting if a value is "array-like" is approximate, it primarily tries to cover the most common cases.

@plamut plamut added the api: bigquery Issues related to the BigQuery API. label Sep 9, 2019
@plamut plamut requested a review from a team September 9, 2019 16:27
@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Sep 9, 2019
Copy link
Contributor

@tswast tswast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. Just want to make sure we don't confuse dictionaries as if they were array-like.

@plamut plamut requested a review from tswast September 10, 2019 08:30
@plamut plamut merged commit adfc6d3 into googleapis:master Sep 10, 2019
@plamut plamut deleted the iss-9177 branch September 10, 2019 19:09
emar-kar pushed a commit to MaxxleLLC/google-cloud-python that referenced this pull request Sep 11, 2019
…eapis#9189)

* Add support for array params to Cursor.execute()

* Raise NotImplementedError for STRUCT-like values
emar-kar pushed a commit to MaxxleLLC/google-cloud-python that referenced this pull request Sep 18, 2019
…eapis#9189)

* Add support for array params to Cursor.execute()

* Raise NotImplementedError for STRUCT-like values
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.

BigQuery: Support WHERE IN or WHERE ANY clause in DB-API
3 participants