Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit f6b90f7

Browse files
committed
Changed attribute mapping + moved ABC classes to test file + changed
__all__
1 parent 41dcace commit f6b90f7

2 files changed

Lines changed: 86 additions & 165 deletions

File tree

google/cloud/bigtable/row_filters.py

Lines changed: 59 additions & 129 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
import struct
1818

1919

20-
from google.cloud.bigtable.data.row_filters import (
20+
from google.cloud.bigtable.data.row_filters import ( # noqa: F401
2121
RowFilter,
2222
SinkFilter,
23-
_BoolFilter as _BaseBoolFilter,
23+
_BoolFilter,
2424
PassAllFilter,
2525
BlockAllFilter,
26-
_RegexFilter as _BaseRegexFilter,
26+
_RegexFilter,
2727
RowKeyRegexFilter,
2828
RowSampleFilter,
2929
FamilyNameRegexFilter,
@@ -33,55 +33,54 @@
3333
ColumnRangeFilter as BaseColumnRangeFilter,
3434
ValueRegexFilter,
3535
ValueRangeFilter,
36-
_CellCountFilter as _BaseCellCountFilter,
36+
_CellCountFilter,
3737
CellsRowOffsetFilter,
3838
CellsRowLimitFilter,
3939
CellsColumnLimitFilter,
4040
StripValueTransformerFilter,
4141
ApplyLabelFilter,
42-
_FilterCombination as _BaseFilterCombination,
42+
_FilterCombination,
4343
RowFilterChain,
4444
RowFilterUnion,
4545
ConditionalRowFilter as BaseConditionalRowFilter,
4646
)
4747

4848
_PACK_I64 = struct.Struct(">q").pack
4949

50-
# The classes defined below are to provide constructors and members
51-
# that have an interface that does not match the one used by the data
52-
# client, for backwards compatibility purposes.
53-
54-
# Each underscored class is an ABC. Make them into classes that can be
55-
# instantiated with a placeholder to_dict method for consistency.
5650

51+
class _MappableAttributesMixin:
52+
"""
53+
Mixin for classes that need some of their attribute names remapped.
5754
58-
class _BoolFilter(_BaseBoolFilter):
59-
"""Row filter that uses a boolean flag.
55+
This is for taking some of the classes from the data client row filters
56+
that are 1:1 with their legacy client counterparts but with some of their
57+
attributes renamed. To use in a class, override the base class with this mixin
58+
class and define a map _attribute_map from legacy client attributes to data client
59+
attributes.
6060
61-
:type flag: bool
62-
:param flag: An indicator if a setting is turned on or off.
61+
Attributes are remapped and redefined in __init__ as well as getattr/setattr.
6362
"""
6463

65-
def _to_dict(self):
66-
pass
67-
64+
def __init__(self, *args, **kwargs):
65+
new_kwargs = {self._attribute_map.get(k, k): v for (k, v) in kwargs.items()}
66+
super(_MappableAttributesMixin, self).__init__(*args, **new_kwargs)
6867

69-
class _RegexFilter(_BaseRegexFilter):
70-
"""Row filter that uses a regular expression.
68+
def __getattr__(self, name):
69+
if name not in self._attribute_map:
70+
raise AttributeError
71+
return getattr(self, self._attribute_map[name])
7172

72-
The ``regex`` must be valid RE2 patterns. See Google's
73-
`RE2 reference`_ for the accepted syntax.
73+
def __setattr__(self, name, value):
74+
attribute = self._attribute_map.get(name, name)
75+
super(_MappableAttributesMixin, self).__setattr__(attribute, value)
7476

75-
.. _RE2 reference: https://github.com/google/re2/wiki/Syntax
7677

77-
:type regex: bytes or str
78-
:param regex:
79-
A regular expression (RE2) for some row filter. String values
80-
will be encoded as ASCII.
81-
"""
78+
# The classes defined below are to provide constructors and members
79+
# that have an interface that does not match the one used by the data
80+
# client, for backwards compatibility purposes.
8281

83-
def _to_dict(self):
84-
pass
82+
# Each underscored class is an ABC. Make them into classes that can be
83+
# instantiated with a placeholder to_dict method for consistency.
8584

8685

8786
class TimestampRangeFilter(BaseTimestampRangeFilter):
@@ -111,21 +110,7 @@ def __init__(self, value):
111110
super(ExactValueFilter, self).__init__(value)
112111

113112

114-
class _CellCountFilter(_BaseCellCountFilter):
115-
"""Row filter that uses an integer count of cells.
116-
117-
The cell count is used as an offset or a limit for the number
118-
of results returned.
119-
120-
:type num_cells: int
121-
:param num_cells: An integer count / offset / limit.
122-
"""
123-
124-
def _to_dict(self):
125-
pass
126-
127-
128-
class ColumnRangeFilter(BaseColumnRangeFilter):
113+
class ColumnRangeFilter(_MappableAttributesMixin, BaseColumnRangeFilter):
129114
"""A row filter to restrict to a range of columns.
130115
131116
Both the start and end column can be included or excluded in the range.
@@ -162,63 +147,14 @@ class ColumnRangeFilter(BaseColumnRangeFilter):
162147
is set but no ``end_column`` is given
163148
"""
164149

165-
def __init__(
166-
self,
167-
column_family_id,
168-
start_column=None,
169-
end_column=None,
170-
inclusive_start=None,
171-
inclusive_end=None,
172-
):
173-
super(ColumnRangeFilter, self).__init__(
174-
family_id=column_family_id,
175-
start_qualifier=start_column,
176-
end_qualifier=end_column,
177-
inclusive_start=inclusive_start,
178-
inclusive_end=inclusive_end,
179-
)
180-
181-
@property
182-
def column_family_id(self):
183-
return self.family_id
184-
185-
@column_family_id.setter
186-
def column_family_id(self, column_family_id):
187-
self.family_id = column_family_id
188-
189-
@property
190-
def start_column(self):
191-
return self.start_qualifier
192-
193-
@start_column.setter
194-
def start_column(self, start_column):
195-
self.start_qualifier = start_column
196-
197-
@property
198-
def end_column(self):
199-
return self.end_qualifier
200-
201-
@end_column.setter
202-
def end_column(self, end_column):
203-
self.end_qualifier = end_column
204-
205-
206-
class _FilterCombination(_BaseFilterCombination):
207-
"""Chain of row filters.
208-
209-
Sends rows through several filters in sequence. The filters are "chained"
210-
together to process a row. After the first filter is applied, the second
211-
is applied to the filtered output and so on for subsequent filters.
212-
213-
:type filters: list
214-
:param filters: List of :class:`RowFilter`
215-
"""
150+
_attribute_map = {
151+
"column_family_id": "family_id",
152+
"start_column": "start_qualifier",
153+
"end_column": "end_qualifier",
154+
}
216155

217-
def _to_dict(self):
218-
pass
219156

220-
221-
class ConditionalRowFilter(BaseConditionalRowFilter):
157+
class ConditionalRowFilter(_MappableAttributesMixin, BaseConditionalRowFilter):
222158
"""Conditional row filter which exhibits ternary behavior.
223159
224160
Executes one of two filters based on another filter. If the ``base_filter``
@@ -248,36 +184,30 @@ class ConditionalRowFilter(BaseConditionalRowFilter):
248184
will be returned in the false case.
249185
"""
250186

251-
@property
252-
def base_filter(self):
253-
return self.predicate_filter
254-
255-
@base_filter.setter
256-
def base_filter(self, value: RowFilter):
257-
self.predicate_filter = value
187+
_attribute_map = {"base_filter": "predicate_filter"}
258188

259189

260190
__all__ = (
261-
RowFilter,
262-
SinkFilter,
263-
PassAllFilter,
264-
BlockAllFilter,
265-
RowKeyRegexFilter,
266-
RowSampleFilter,
267-
FamilyNameRegexFilter,
268-
ColumnQualifierRegexFilter,
269-
TimestampRange,
270-
TimestampRangeFilter,
271-
ColumnRangeFilter,
272-
ValueRegexFilter,
273-
ExactValueFilter,
274-
ValueRangeFilter,
275-
CellsRowOffsetFilter,
276-
CellsRowLimitFilter,
277-
CellsColumnLimitFilter,
278-
StripValueTransformerFilter,
279-
ApplyLabelFilter,
280-
RowFilterChain,
281-
RowFilterUnion,
282-
ConditionalRowFilter,
191+
"RowFilter",
192+
"SinkFilter",
193+
"PassAllFilter",
194+
"BlockAllFilter",
195+
"RowKeyRegexFilter",
196+
"RowSampleFilter",
197+
"FamilyNameRegexFilter",
198+
"ColumnQualifierRegexFilter",
199+
"TimestampRange",
200+
"TimestampRangeFilter",
201+
"ColumnRangeFilter",
202+
"ValueRegexFilter",
203+
"ExactValueFilter",
204+
"ValueRangeFilter",
205+
"CellsRowOffsetFilter",
206+
"CellsRowLimitFilter",
207+
"CellsColumnLimitFilter",
208+
"StripValueTransformerFilter",
209+
"ApplyLabelFilter",
210+
"RowFilterChain",
211+
"RowFilterUnion",
212+
"ConditionalRowFilter",
283213
)

0 commit comments

Comments
 (0)