-
Notifications
You must be signed in to change notification settings - Fork 61
feat: Add support for Proto and Enum types #1202
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
Changes from all commits
c85c31e
9132e80
f65d45a
e1fac0c
13236e6
d785b8b
7dea490
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,8 @@ | |
| from google.api_core.exceptions import DeadlineExceeded | ||
| from google.api_core.exceptions import ServiceUnavailable | ||
| from google.api_core.exceptions import Aborted | ||
| from google.protobuf.message import Message | ||
| from google.protobuf.internal.enum_type_wrapper import EnumTypeWrapper | ||
|
|
||
| import google.auth.credentials | ||
| import google.auth._default | ||
|
|
@@ -657,6 +659,7 @@ async def execute_query( | |
| DeadlineExceeded, | ||
| ServiceUnavailable, | ||
| ), | ||
| column_info: dict[str, Message | EnumTypeWrapper] | None = None, | ||
| ) -> "ExecuteQueryIteratorAsync": | ||
| """ | ||
| Executes an SQL query on an instance. | ||
|
|
@@ -705,6 +708,62 @@ async def execute_query( | |
| If None, defaults to prepare_operation_timeout. | ||
| prepare_retryable_errors: a list of errors that will be retried if encountered during prepareQuery. | ||
| Defaults to 4 (DeadlineExceeded) and 14 (ServiceUnavailable) | ||
| column_info: (Optional) A dictionary mapping column names to Protobuf message classes or EnumTypeWrapper objects. | ||
| This dictionary provides the necessary type information for deserializing PROTO and | ||
| ENUM column values from the query results. When an entry is provided | ||
| for a PROTO or ENUM column, the client library will attempt to deserialize the raw data. | ||
|
|
||
| - For PROTO columns: The value in the dictionary should be the | ||
| Protobuf Message class (e.g., ``my_pb2.MyMessage``). | ||
| - For ENUM columns: The value should be the Protobuf EnumTypeWrapper | ||
| object (e.g., ``my_pb2.MyEnum``). | ||
|
|
||
| Example:: | ||
|
|
||
| import my_pb2 | ||
|
|
||
| column_info = { | ||
| "my_proto_column": my_pb2.MyMessage, | ||
| "my_enum_column": my_pb2.MyEnum | ||
| } | ||
|
|
||
| If ``column_info`` is not provided, or if a specific column name is not found | ||
| in the dictionary: | ||
|
|
||
| - PROTO columns will be returned as raw bytes. | ||
| - ENUM columns will be returned as integers. | ||
|
|
||
| Note for Nested PROTO or ENUM Fields: | ||
|
|
||
| To specify types for PROTO or ENUM fields within STRUCTs or MAPs, use a dot-separated | ||
| path from the top-level column name. | ||
|
|
||
| - For STRUCTs: ``struct_column_name.field_name`` | ||
| - For MAPs: ``map_column_name.key`` or ``map_column_name.value`` to specify types | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the with_history maps that have nested struct values I assume this doesn't work? Or does it handle arbitrary nesting?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah cool it looks like this works. Can you add an example of that to the doc as well?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
| for the map keys or values, respectively. | ||
|
|
||
| Example:: | ||
|
|
||
| import my_pb2 | ||
|
|
||
| column_info = { | ||
| # Top-level column | ||
| "my_proto_column": my_pb2.MyMessage, | ||
| "my_enum_column": my_pb2.MyEnum, | ||
|
|
||
| # Nested field in a STRUCT column named 'my_struct' | ||
| "my_struct.nested_proto_field": my_pb2.OtherMessage, | ||
| "my_struct.nested_enum_field": my_pb2.AnotherEnum, | ||
|
|
||
| # Nested field in a MAP column named 'my_map' | ||
| "my_map.key": my_pb2.MapKeyEnum, # If map keys were enums | ||
| "my_map.value": my_pb2.MapValueMessage, | ||
|
|
||
| # PROTO field inside a STRUCT, where the STRUCT is the value in a MAP column | ||
| "struct_map.value.nested_proto_field": my_pb2.DeeplyNestedProto, | ||
| "struct_map.value.nested_enum_field": my_pb2.DeeplyNestedEnum | ||
| } | ||
|
|
||
| Returns: | ||
| ExecuteQueryIteratorAsync: an asynchronous iterator that yields rows returned by the query | ||
| Raises: | ||
|
|
@@ -714,6 +773,7 @@ async def execute_query( | |
| google.api_core.exceptions.GoogleAPIError: raised if the request encounters an unrecoverable error | ||
| google.cloud.bigtable.data.exceptions.ParameterTypeInferenceFailed: Raised if | ||
| a parameter is passed without an explicit type, and the type cannot be infered | ||
| google.protobuf.message.DecodeError: raised if the deserialization of a PROTO/ENUM value fails. | ||
| """ | ||
| instance_name = self._gapic_client.instance_path(self.project, instance_id) | ||
| converted_param_types = _to_param_types(parameters, parameter_types) | ||
|
|
@@ -771,6 +831,7 @@ async def execute_query( | |
| attempt_timeout, | ||
| operation_timeout, | ||
| retryable_excs=retryable_excs, | ||
| column_info=column_info, | ||
| ) | ||
|
|
||
| @CrossSync.convert(sync_name="__enter__") | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.