-
Notifications
You must be signed in to change notification settings - Fork 61
feat: async execute query client #1011
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: async execute query client #1011
Conversation
Co-authored-by: Mateusz Walkiewicz <[email protected]>
Here is the summary of changes. You are about to add 1 region tag.
This comment is generated by snippet-bot.
|
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.
Added a couple requests for missing docstrings, etc. But overall LGTM once the tests pass
|
||
|
||
class ParameterTypeInferenceFailed(ValueError): | ||
pass |
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.
nit: it would be good to have a docstring here
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.
done
) | ||
|
||
|
||
class ExecuteQueryIteratorAsync: |
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.
docstring?
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.
done
def __aiter__(self): | ||
return self | ||
|
||
async def metadata(self) -> Optional[Metadata]: |
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.
please add docstrings on all of these methods
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.
done
params: Optional[Dict[str, ExecuteQueryValueType]], | ||
parameter_types: Optional[Dict[str, SqlType.Type]], | ||
): | ||
if not params: |
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.
docstrings on these would also be helpful for future maintenance
It doesn't need to be too complex for the internal functions, but some context would be useful
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.
done
|
||
|
||
def _parse_array_type(value: PBValue, metadata_type: SqlType.Array) -> list: | ||
return list( |
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.
docstrings here too
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.
done.
google/cloud/bigtable_v2/__init__.py
Outdated
@@ -122,6 +122,8 @@ | |||
"RowSet", | |||
"SampleRowKeysRequest", | |||
"SampleRowKeysResponse", | |||
"ExecuteQueryRequest", | |||
"ExecuteQueryResponse", |
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.
This file is autogenerated and doesn't need to be touched (These are already included in lines 87/88)
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.
removed.
tests/unit/data/test_byte_cursor.py
Outdated
@@ -0,0 +1,149 @@ | |||
# Copyright 2024 Google LLC |
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.
Previously, the test files mirrored the structure of the source files. It might make sense to throw these into an execute_query directory?
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.
fixed.
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.
done.
FYI, you can ignore the failing samples tests. There's a quota issue in the samples project we're looking in to |
@@ -212,13 +221,13 @@ class Timestamp(Type): | |||
DatetimeWithNanoseconds, | |||
) | |||
|
|||
def _to_value_pb_dict(self, value: Any) -> dict: | |||
def _to_value_pb_dict(self, value: Any) -> Any: |
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.
It's not too important, but do we have to use Any
for these? Does dict[str, Any]
not work?
query = ( | ||
"SELECT _key, os_build, connected_cell, connected_wifi " | ||
f"from {table_id} WHERE _key=@row_key" | ||
) |
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.
I know I said to ignore the samples tests, but it looks like there's actually an issue here:
google.api_core.exceptions.InvalidArgument: 400 Syntax error: Missing whitespace between literal and alias [at 1:87]
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.
Also, there's a snippet lint issue that can be addressed using
cd samples/snippets/data_client
nox -s blacken
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.
To fix the invalid argument do: f"from `{table_id}` WHERE _key=@row_key"
(wraps the table name in backticks)
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.
Daniel pointed out the column names here aren't working either. All of those are qualifiers.
We should update the first line of the query to SELECT _key, stats_summary['os_build'], stats_summary['connected_cell'], stats_summary['connected_wifi']
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.
fixed.
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.
blocking until sample is addressed
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.
LGTM
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:
Description
This PR introduces support for the newly added
executeQuery
RPC in the Bigtable async client.It handles executing parameterized queries and receiving streaming responses through an asynchronous iterator.
Most of the logic is located in
google.cloud.bigtable.data.execute_query
.Example usage is in
samples/snippets/data_client/data_client_snippets_async.py