Repository navigation
feat(bigquery): add column data policies to SchemaField - #18710
AliAbouelazm wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for column-level data policies in BigQuery schemas by adding a data_policies property to SchemaField, along with documentation and comprehensive unit tests. The review feedback suggests two key improvements: adding a type check to prevent strings or bytes from being silently iterated character-by-character when passed to data_policies, and replacing fragile index slicing ([:-1]) in the __repr__ method with dynamic filtering based on the named tuple's fields to ensure future-proof code.
| rounding_mode: Union[enums.RoundingMode, str, None] = None, | ||
| foreign_type_definition: Optional[str] = None, | ||
| timestamp_precision: Optional[enums.TimestampPrecision] = None, | ||
| data_policies: Union[Iterable[str], None, _DefaultSentinel] = _DEFAULT_VALUE, |
There was a problem hiding this comment.
To prevent accidental breaking changes in the future, let's use forced kwarg arguments here.
| data_policies: Union[Iterable[str], None, _DefaultSentinel] = _DEFAULT_VALUE, | |
| *, | |
| data_policies: Union[Iterable[str], None, _DefaultSentinel] = _DEFAULT_VALUE, |
There was a problem hiding this comment.
Done, made data_policies keyword only and added a test to check that existing positional arguments still work.
| adjusted_key = tuple( | ||
| getattr(key_to_show, field) | ||
| for field in key_to_show._fields | ||
| if field != "data_policies" |
There was a problem hiding this comment.
let's create a kwarg_only_args tuple so that we can add to this in the future.
There was a problem hiding this comment.
Added kwarg_only_args and used it to handle the keyword arguments in repr.
| """ | ||
| resource = self._properties.get("dataPolicies") | ||
| return ( | ||
| tuple(policy["name"] for policy in resource) |
There was a problem hiding this comment.
It worries me to extract just a single field from this when the REST represention is an object. Is there any chance that we might add keys to this in the future? If so, let's create a class for DataPolicy.
There was a problem hiding this comment.
Good point. Added a DataPolicy class with API conversion methods that preserve the full object. Updated the docs and tests too.
Adds data_policies to SchemaField so callers can read and set column data policy names without using _properties. Names are serialized as dataPolicies entries, and equality and hashing account for them regardless of order.
The tests cover unset, null, empty, multiple and nested policies, API round trips, repr, and schemas that use policy tags on other columns. The usage guide explains the API representation and the limits around removing the last policy and dataPolicyList precedence.
Validation on Python 3.12: 2,859 unit tests passed, 2 skipped. Black, flake8, mypy and the documentation build passed. The test process used default OpenTelemetry sampling because the inherited setting caused the same seven failures on unmodified main.
Fixes #17617.