Skip to content

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

Merged
merged 10 commits into from
Aug 8, 2024

Conversation

kboroszko
Copy link
Contributor

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:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

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

Copy link

snippet-bot bot commented Aug 5, 2024

Here is the summary of changes.

You are about to add 1 region tag.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

Copy link
Contributor

@daniel-sanche daniel-sanche left a 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
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

)


class ExecuteQueryIteratorAsync:
Copy link
Contributor

Choose a reason for hiding this comment

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

docstring?

Copy link
Contributor Author

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]:
Copy link
Contributor

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

Copy link
Contributor Author

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:
Copy link
Contributor

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

Copy link
Contributor Author

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(
Copy link
Contributor

Choose a reason for hiding this comment

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

docstrings here too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@@ -122,6 +122,8 @@
"RowSet",
"SampleRowKeysRequest",
"SampleRowKeysResponse",
"ExecuteQueryRequest",
"ExecuteQueryResponse",
Copy link
Contributor

@daniel-sanche daniel-sanche Aug 5, 2024

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed.

@@ -0,0 +1,149 @@
# Copyright 2024 Google LLC
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@daniel-sanche
Copy link
Contributor

FYI, you can ignore the failing samples tests. There's a quota issue in the samples project we're looking in to

@product-auto-label product-auto-label bot added the api: bigtable Issues related to the googleapis/python-bigtable API. label Aug 6, 2024
@daniel-sanche daniel-sanche added the kokoro:run Add this label to force Kokoro to re-run the tests. label Aug 6, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Aug 6, 2024
@daniel-sanche daniel-sanche added the owlbot:run Add this label to trigger the Owlbot post processor. label Aug 6, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Aug 6, 2024
@product-auto-label product-auto-label bot added the size: xl Pull request size is extra large. label Aug 7, 2024
@@ -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:
Copy link
Contributor

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?

@jackdingilian jackdingilian added the kokoro:run Add this label to force Kokoro to re-run the tests. label Aug 8, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Aug 8, 2024
query = (
"SELECT _key, os_build, connected_cell, connected_wifi "
f"from {table_id} WHERE _key=@row_key"
)
Copy link
Contributor

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]

Copy link
Contributor

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

Copy link
Contributor

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)

Copy link
Contributor

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']

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

Copy link
Contributor

@daniel-sanche daniel-sanche left a 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

@daniel-sanche daniel-sanche added kokoro:run Add this label to force Kokoro to re-run the tests. owlbot:run Add this label to trigger the Owlbot post processor. labels Aug 8, 2024
@gcf-owl-bot gcf-owl-bot bot removed the owlbot:run Add this label to trigger the Owlbot post processor. label Aug 8, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Aug 8, 2024
@daniel-sanche daniel-sanche added the kokoro:run Add this label to force Kokoro to re-run the tests. label Aug 8, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Aug 8, 2024
Copy link
Contributor

@daniel-sanche daniel-sanche left a comment

Choose a reason for hiding this comment

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

LGTM

@daniel-sanche daniel-sanche merged commit 45bc8c4 into googleapis:main Aug 8, 2024
29 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: bigtable Issues related to the googleapis/python-bigtable API. size: xl Pull request size is extra large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants