Skip to content

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

Merged
plamut merged 2 commits into
googleapis:masterfrom
plamut:iss-9177
Sep 10, 2019
Merged

BigQuery: Add support for array parameters to Cursor.execute()#9189
plamut merged 2 commits into
googleapis:masterfrom
plamut:iss-9177

Conversation

@plamut

@plamutplamut commented Sep 9, 2019

Copy link
Copy Markdown
Contributor

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.

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

@tswasttswast left a comment

Copy link
Copy Markdown
Contributor

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.

Comment threadbigquery/google/cloud/bigquery/dbapi/_helpers.py
Comment threadbigquery/google/cloud/bigquery/dbapi/_helpers.py
@plamut
plamut requested a review from tswastSeptember 10, 2019 08:30
@plamut
plamut merged commit adfc6d3 into googleapis:masterSep 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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigqueryIssues related to the BigQuery API.cla: yesThis 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

@plamut@tswast@googlebot