-
Notifications
You must be signed in to change notification settings - Fork 132
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
feat: Handle passing of arrays to in statements more efficiently in SQLAlchemy 1.4 and higher #253
Conversation
For reviewers: When dealing with an in expression, like BigQuery lets you pass array parameters, which is much better for this case. See the comment here: https://github.com/googleapis/python-bigquery-sqlalchemy/pull/253/files#diff-efe1987a73ae5b54aa817dc8c70541025df89d9d08601c8ab33fa84ad8c09de7R421-R441 For SQLAlchemy 1.4, it's fairly easy to disable this behavior. (I beat my head against earlier versions and gave up. :)) The only trick is to make sure we call Finally,
|
and added unit test to cover it. Also fixed constraints
def test_select_in_lit(faux_conn, last_query): | ||
faux_conn.execute(sqlalchemy.select([sqlalchemy.literal(1).in_([1, 2, 3])])) | ||
last_query( | ||
"SELECT %(param_1:INT64)s IN UNNEST(%(param_2:INT64)s) AS `anon_1`", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the type of param_2
be ARRAY<INT64>
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because the BQ DB API does special handling of arrays.
It sees that we have a scalar type of INT64 and that we have a sequence, and then creates a ArrayQueryParameter
.
It happens that since I added struct support, passing ARRAY<INT64>
would probably work (because I have to handle structs of arrays). But just usng INT64
works too.
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Fixes #194 🦕