| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| *, | ||
| retry=gapic_v1.method.DEFAULT, | ||
| timeout=gapic_v1.method.DEFAULT, | ||
| lazy_decode=False, |
There was a problem hiding this comment.
nit: add documentation for this new argument
Sorry, something went wrong.
| @@ -0,0 +1,128 @@ | |||
| # Copyright 2024 Google LLC All rights reserved. | |||
There was a problem hiding this comment.
nit: 2025
Sorry, something went wrong.
| def decode_row(self, row: []) -> []: | ||
| """Decodes a row from protobuf values to Python objects. This function | ||
| should only be called for result sets that use ``lazy_decoding=True``. | ||
| The array that is returned by this function is the same as the array | ||
| that would have been returned by the rows iterator if ``lazy_decoding=False``. | ||
|
|
||
| :returns: an array containing the decoded values of all the columns in the given row | ||
| """ | ||
| if not isinstance(row, (list, tuple)): | ||
| raise TypeError("row must be an array of protobuf values") | ||
| decoders = self._decoders | ||
| return [ | ||
| _parse_nullable(row[index], decoders[index]) for index in range(len(row)) | ||
| ] | ||
|
|
||
| def decode_column(self, row: [], column_index: int): | ||
| """Decodes a column from a protobuf value to a Python object. This function | ||
| should only be called for result sets that use ``lazy_decoding=True``. | ||
| The object that is returned by this function is the same as the object | ||
| that would have been returned by the rows iterator if ``lazy_decoding=False``. | ||
|
|
||
| :returns: the decoded column value | ||
| """ | ||
| if not isinstance(row, (list, tuple)): | ||
| raise TypeError("row must be an array of protobuf values") | ||
| decoders = self._decoders | ||
| return _parse_nullable(row[column_index], decoders[column_index]) | ||
|
|
||
| @property | ||
| def _decoders(self): | ||
| if self.metadata is None: | ||
| raise ValueError("iterator not started") | ||
| return [ | ||
| _get_type_decoder(field.type_, field.name, None) | ||
| for field in self.metadata.row_type.fields | ||
| ] |
There was a problem hiding this comment.
Is this code really needed? A MergedResultSet just delegates all underlying logic to the 'normal' ResultSets. Those already support lazy decoding. So could we not just call the decode_row/decode_column function of one of the underlying ResultSets instead?
Sorry, something went wrong.
| """ | ||
| if not isinstance(row, (list, tuple)): | ||
| raise TypeError("row must be an array of protobuf values") | ||
| decoders = self._decoders |
There was a problem hiding this comment.
Can we cache this instead of reconstructing it for every row?
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Add lazy decode to partitioned query
This commit introduces a lazy_decode option to BatchSnapshot.run_partitioned_query. When set to True, the result set yields raw protobuf objects instead of decoded Python objects.
This allows the CPU-intensive decoding work to be deferred and managed by the caller, which can significantly improve performance in multi-threaded applications by reducing GIL contention.
To support this, MergedResultSet now includes decode_row() and decode_column() methods for manual decoding of results.