This repository was archived by the owner on Apr 1, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 64
feat: Add support for Proto and Enum types #1202
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c85c31e
feat: Add support for Proto and Enum types
trollyxia 9132e80
Address review comments
trollyxia f65d45a
Minor change, address comments
trollyxia e1fac0c
Update docstring
trollyxia 13236e6
Address review comments
trollyxia d785b8b
Modify docstring to indicate message.DecodeError when proto parsing f…
trollyxia 7dea490
Disable proto/enum parsing for unnamed proto/enum fields inside a struct
trollyxia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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?
Contributor
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__") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.