google-cloud-bigtable 2.30.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. google/cloud/bigtable/__init__.py +25 -0
  2. google/cloud/bigtable/app_profile.py +377 -0
  3. google/cloud/bigtable/backup.py +490 -0
  4. google/cloud/bigtable/batcher.py +414 -0
  5. google/cloud/bigtable/client.py +475 -0
  6. google/cloud/bigtable/cluster.py +541 -0
  7. google/cloud/bigtable/column_family.py +362 -0
  8. google/cloud/bigtable/data/__init__.py +103 -0
  9. google/cloud/bigtable/data/_async/__init__.py +25 -0
  10. google/cloud/bigtable/data/_async/_mutate_rows.py +226 -0
  11. google/cloud/bigtable/data/_async/_read_rows.py +363 -0
  12. google/cloud/bigtable/data/_async/client.py +1522 -0
  13. google/cloud/bigtable/data/_async/mutations_batcher.py +534 -0
  14. google/cloud/bigtable/data/_cross_sync/__init__.py +20 -0
  15. google/cloud/bigtable/data/_cross_sync/_decorators.py +441 -0
  16. google/cloud/bigtable/data/_cross_sync/_mapping_meta.py +64 -0
  17. google/cloud/bigtable/data/_cross_sync/cross_sync.py +334 -0
  18. google/cloud/bigtable/data/_helpers.py +249 -0
  19. google/cloud/bigtable/data/_sync_autogen/_mutate_rows.py +182 -0
  20. google/cloud/bigtable/data/_sync_autogen/_read_rows.py +304 -0
  21. google/cloud/bigtable/data/_sync_autogen/client.py +1293 -0
  22. google/cloud/bigtable/data/_sync_autogen/mutations_batcher.py +449 -0
  23. google/cloud/bigtable/data/exceptions.py +340 -0
  24. google/cloud/bigtable/data/execute_query/__init__.py +43 -0
  25. google/cloud/bigtable/data/execute_query/_async/__init__.py +13 -0
  26. google/cloud/bigtable/data/execute_query/_async/execute_query_iterator.py +291 -0
  27. google/cloud/bigtable/data/execute_query/_byte_cursor.py +123 -0
  28. google/cloud/bigtable/data/execute_query/_checksum.py +43 -0
  29. google/cloud/bigtable/data/execute_query/_parameters_formatting.py +155 -0
  30. google/cloud/bigtable/data/execute_query/_query_result_parsing_utils.py +134 -0
  31. google/cloud/bigtable/data/execute_query/_reader.py +122 -0
  32. google/cloud/bigtable/data/execute_query/_sync_autogen/execute_query_iterator.py +239 -0
  33. google/cloud/bigtable/data/execute_query/metadata.py +399 -0
  34. google/cloud/bigtable/data/execute_query/values.py +123 -0
  35. google/cloud/bigtable/data/mutations.py +380 -0
  36. google/cloud/bigtable/data/read_modify_write_rules.py +112 -0
  37. google/cloud/bigtable/data/read_rows_query.py +536 -0
  38. google/cloud/bigtable/data/row.py +535 -0
  39. google/cloud/bigtable/data/row_filters.py +968 -0
  40. google/cloud/bigtable/encryption_info.py +64 -0
  41. google/cloud/bigtable/enums.py +223 -0
  42. google/cloud/bigtable/error.py +64 -0
  43. google/cloud/bigtable/gapic_version.py +16 -0
  44. google/cloud/bigtable/helpers.py +31 -0
  45. google/cloud/bigtable/instance.py +789 -0
  46. google/cloud/bigtable/policy.py +255 -0
  47. google/cloud/bigtable/row.py +1267 -0
  48. google/cloud/bigtable/row_data.py +380 -0
  49. google/cloud/bigtable/row_filters.py +838 -0
  50. google/cloud/bigtable/row_merger.py +250 -0
  51. google/cloud/bigtable/row_set.py +213 -0
  52. google/cloud/bigtable/table.py +1409 -0
  53. google/cloud/bigtable_admin/__init__.py +410 -0
  54. google/cloud/bigtable_admin/gapic_version.py +16 -0
  55. google/cloud/bigtable_admin/py.typed +2 -0
  56. google/cloud/bigtable_admin_v2/__init__.py +250 -0
  57. google/cloud/bigtable_admin_v2/gapic_metadata.json +962 -0
  58. google/cloud/bigtable_admin_v2/gapic_version.py +16 -0
  59. google/cloud/bigtable_admin_v2/py.typed +2 -0
  60. google/cloud/bigtable_admin_v2/services/__init__.py +15 -0
  61. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/__init__.py +22 -0
  62. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/async_client.py +3465 -0
  63. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/client.py +3944 -0
  64. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/pagers.py +681 -0
  65. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/__init__.py +40 -0
  66. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/base.py +751 -0
  67. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/grpc.py +1249 -0
  68. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/grpc_asyncio.py +1579 -0
  69. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/rest.py +6820 -0
  70. google/cloud/bigtable_admin_v2/services/bigtable_instance_admin/transports/rest_base.py +1746 -0
  71. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/__init__.py +22 -0
  72. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/async_client.py +3472 -0
  73. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/client.py +3949 -0
  74. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/pagers.py +669 -0
  75. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/__init__.py +40 -0
  76. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/base.py +708 -0
  77. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/grpc.py +1257 -0
  78. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/grpc_asyncio.py +1549 -0
  79. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/rest.py +6609 -0
  80. google/cloud/bigtable_admin_v2/services/bigtable_table_admin/transports/rest_base.py +1714 -0
  81. google/cloud/bigtable_admin_v2/types/__init__.py +248 -0
  82. google/cloud/bigtable_admin_v2/types/bigtable_instance_admin.py +1364 -0
  83. google/cloud/bigtable_admin_v2/types/bigtable_table_admin.py +1715 -0
  84. google/cloud/bigtable_admin_v2/types/common.py +81 -0
  85. google/cloud/bigtable_admin_v2/types/instance.py +819 -0
  86. google/cloud/bigtable_admin_v2/types/table.py +1028 -0
  87. google/cloud/bigtable_admin_v2/types/types.py +776 -0
  88. google/cloud/bigtable_v2/__init__.py +136 -0
  89. google/cloud/bigtable_v2/gapic_metadata.json +193 -0
  90. google/cloud/bigtable_v2/gapic_version.py +16 -0
  91. google/cloud/bigtable_v2/py.typed +2 -0
  92. google/cloud/bigtable_v2/services/__init__.py +15 -0
  93. google/cloud/bigtable_v2/services/bigtable/__init__.py +22 -0
  94. google/cloud/bigtable_v2/services/bigtable/async_client.py +1741 -0
  95. google/cloud/bigtable_v2/services/bigtable/client.py +2194 -0
  96. google/cloud/bigtable_v2/services/bigtable/transports/__init__.py +38 -0
  97. google/cloud/bigtable_v2/services/bigtable/transports/base.py +343 -0
  98. google/cloud/bigtable_v2/services/bigtable/transports/grpc.py +660 -0
  99. google/cloud/bigtable_v2/services/bigtable/transports/grpc_asyncio.py +762 -0
  100. google/cloud/bigtable_v2/services/bigtable/transports/rest.py +2489 -0
  101. google/cloud/bigtable_v2/services/bigtable/transports/rest_base.py +711 -0
  102. google/cloud/bigtable_v2/types/__init__.py +138 -0
  103. google/cloud/bigtable_v2/types/bigtable.py +1531 -0
  104. google/cloud/bigtable_v2/types/data.py +1612 -0
  105. google/cloud/bigtable_v2/types/feature_flags.py +119 -0
  106. google/cloud/bigtable_v2/types/request_stats.py +171 -0
  107. google/cloud/bigtable_v2/types/response_params.py +64 -0
  108. google/cloud/bigtable_v2/types/types.py +579 -0
  109. google_cloud_bigtable-2.30.0.data/scripts/fixup_bigtable_admin_v2_keywords.py +233 -0
  110. google_cloud_bigtable-2.30.0.data/scripts/fixup_bigtable_v2_keywords.py +186 -0
  111. google_cloud_bigtable-2.30.0.dist-info/LICENSE +202 -0
  112. google_cloud_bigtable-2.30.0.dist-info/METADATA +154 -0
  113. google_cloud_bigtable-2.30.0.dist-info/RECORD +115 -0
  114. google_cloud_bigtable-2.30.0.dist-info/WHEEL +5 -0
  115. google_cloud_bigtable-2.30.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,838 @@
1
+ # Copyright 2016 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Filters for Google Cloud Bigtable Row classes."""
16
+
17
+ import struct
18
+
19
+
20
+ from google.cloud._helpers import _microseconds_from_datetime # type: ignore
21
+ from google.cloud._helpers import _to_bytes # type: ignore
22
+ from google.cloud.bigtable_v2.types import data as data_v2_pb2
23
+
24
+ _PACK_I64 = struct.Struct(">q").pack
25
+
26
+
27
+ class RowFilter(object):
28
+ """Basic filter to apply to cells in a row.
29
+
30
+ These values can be combined via :class:`RowFilterChain`,
31
+ :class:`RowFilterUnion` and :class:`ConditionalRowFilter`.
32
+
33
+ .. note::
34
+
35
+ This class is a do-nothing base class for all row filters.
36
+ """
37
+
38
+
39
+ class _BoolFilter(RowFilter):
40
+ """Row filter that uses a boolean flag.
41
+
42
+ :type flag: bool
43
+ :param flag: An indicator if a setting is turned on or off.
44
+ """
45
+
46
+ def __init__(self, flag):
47
+ self.flag = flag
48
+
49
+ def __eq__(self, other):
50
+ if not isinstance(other, self.__class__):
51
+ return NotImplemented
52
+ return other.flag == self.flag
53
+
54
+ def __ne__(self, other):
55
+ return not self == other
56
+
57
+
58
+ class SinkFilter(_BoolFilter):
59
+ """Advanced row filter to skip parent filters.
60
+
61
+ :type flag: bool
62
+ :param flag: ADVANCED USE ONLY. Hook for introspection into the row filter.
63
+ Outputs all cells directly to the output of the read rather
64
+ than to any parent filter. Cannot be used within the
65
+ ``predicate_filter``, ``true_filter``, or ``false_filter``
66
+ of a :class:`ConditionalRowFilter`.
67
+ """
68
+
69
+ def to_pb(self):
70
+ """Converts the row filter to a protobuf.
71
+
72
+ :rtype: :class:`.data_v2_pb2.RowFilter`
73
+ :returns: The converted current object.
74
+ """
75
+ return data_v2_pb2.RowFilter(sink=self.flag)
76
+
77
+
78
+ class PassAllFilter(_BoolFilter):
79
+ """Row filter equivalent to not filtering at all.
80
+
81
+ :type flag: bool
82
+ :param flag: Matches all cells, regardless of input. Functionally
83
+ equivalent to leaving ``filter`` unset, but included for
84
+ completeness.
85
+ """
86
+
87
+ def to_pb(self):
88
+ """Converts the row filter to a protobuf.
89
+
90
+ :rtype: :class:`.data_v2_pb2.RowFilter`
91
+ :returns: The converted current object.
92
+ """
93
+ return data_v2_pb2.RowFilter(pass_all_filter=self.flag)
94
+
95
+
96
+ class BlockAllFilter(_BoolFilter):
97
+ """Row filter that doesn't match any cells.
98
+
99
+ :type flag: bool
100
+ :param flag: Does not match any cells, regardless of input. Useful for
101
+ temporarily disabling just part of a filter.
102
+ """
103
+
104
+ def to_pb(self):
105
+ """Converts the row filter to a protobuf.
106
+
107
+ :rtype: :class:`.data_v2_pb2.RowFilter`
108
+ :returns: The converted current object.
109
+ """
110
+ return data_v2_pb2.RowFilter(block_all_filter=self.flag)
111
+
112
+
113
+ class _RegexFilter(RowFilter):
114
+ """Row filter that uses a regular expression.
115
+
116
+ The ``regex`` must be valid RE2 patterns. See Google's
117
+ `RE2 reference`_ for the accepted syntax.
118
+
119
+ .. _RE2 reference: https://github.com/google/re2/wiki/Syntax
120
+
121
+ :type regex: bytes or str
122
+ :param regex:
123
+ A regular expression (RE2) for some row filter. String values
124
+ will be encoded as ASCII.
125
+ """
126
+
127
+ def __init__(self, regex):
128
+ self.regex = _to_bytes(regex)
129
+
130
+ def __eq__(self, other):
131
+ if not isinstance(other, self.__class__):
132
+ return NotImplemented
133
+ return other.regex == self.regex
134
+
135
+ def __ne__(self, other):
136
+ return not self == other
137
+
138
+
139
+ class RowKeyRegexFilter(_RegexFilter):
140
+ """Row filter for a row key regular expression.
141
+
142
+ The ``regex`` must be valid RE2 patterns. See Google's
143
+ `RE2 reference`_ for the accepted syntax.
144
+
145
+ .. _RE2 reference: https://github.com/google/re2/wiki/Syntax
146
+
147
+ .. note::
148
+
149
+ Special care need be used with the expression used. Since
150
+ each of these properties can contain arbitrary bytes, the ``\\C``
151
+ escape sequence must be used if a true wildcard is desired. The ``.``
152
+ character will not match the new line character ``\\n``, which may be
153
+ present in a binary value.
154
+
155
+ :type regex: bytes
156
+ :param regex: A regular expression (RE2) to match cells from rows with row
157
+ keys that satisfy this regex. For a
158
+ ``CheckAndMutateRowRequest``, this filter is unnecessary
159
+ since the row key is already specified.
160
+ """
161
+
162
+ def to_pb(self):
163
+ """Converts the row filter to a protobuf.
164
+
165
+ :rtype: :class:`.data_v2_pb2.RowFilter`
166
+ :returns: The converted current object.
167
+ """
168
+ return data_v2_pb2.RowFilter(row_key_regex_filter=self.regex)
169
+
170
+
171
+ class RowSampleFilter(RowFilter):
172
+ """Matches all cells from a row with probability p.
173
+
174
+ :type sample: float
175
+ :param sample: The probability of matching a cell (must be in the
176
+ interval ``(0, 1)`` The end points are excluded).
177
+ """
178
+
179
+ def __init__(self, sample):
180
+ self.sample = sample
181
+
182
+ def __eq__(self, other):
183
+ if not isinstance(other, self.__class__):
184
+ return NotImplemented
185
+ return other.sample == self.sample
186
+
187
+ def __ne__(self, other):
188
+ return not self == other
189
+
190
+ def to_pb(self):
191
+ """Converts the row filter to a protobuf.
192
+
193
+ :rtype: :class:`.data_v2_pb2.RowFilter`
194
+ :returns: The converted current object.
195
+ """
196
+ return data_v2_pb2.RowFilter(row_sample_filter=self.sample)
197
+
198
+
199
+ class FamilyNameRegexFilter(_RegexFilter):
200
+ """Row filter for a family name regular expression.
201
+
202
+ The ``regex`` must be valid RE2 patterns. See Google's
203
+ `RE2 reference`_ for the accepted syntax.
204
+
205
+ .. _RE2 reference: https://github.com/google/re2/wiki/Syntax
206
+
207
+ :type regex: str
208
+ :param regex: A regular expression (RE2) to match cells from columns in a
209
+ given column family. For technical reasons, the regex must
210
+ not contain the ``':'`` character, even if it is not being
211
+ used as a literal.
212
+ """
213
+
214
+ def to_pb(self):
215
+ """Converts the row filter to a protobuf.
216
+
217
+ :rtype: :class:`.data_v2_pb2.RowFilter`
218
+ :returns: The converted current object.
219
+ """
220
+ return data_v2_pb2.RowFilter(family_name_regex_filter=self.regex)
221
+
222
+
223
+ class ColumnQualifierRegexFilter(_RegexFilter):
224
+ """Row filter for a column qualifier regular expression.
225
+
226
+ The ``regex`` must be valid RE2 patterns. See Google's
227
+ `RE2 reference`_ for the accepted syntax.
228
+
229
+ .. _RE2 reference: https://github.com/google/re2/wiki/Syntax
230
+
231
+ .. note::
232
+
233
+ Special care need be used with the expression used. Since
234
+ each of these properties can contain arbitrary bytes, the ``\\C``
235
+ escape sequence must be used if a true wildcard is desired. The ``.``
236
+ character will not match the new line character ``\\n``, which may be
237
+ present in a binary value.
238
+
239
+ :type regex: bytes
240
+ :param regex: A regular expression (RE2) to match cells from column that
241
+ match this regex (irrespective of column family).
242
+ """
243
+
244
+ def to_pb(self):
245
+ """Converts the row filter to a protobuf.
246
+
247
+ :rtype: :class:`.data_v2_pb2.RowFilter`
248
+ :returns: The converted current object.
249
+ """
250
+ return data_v2_pb2.RowFilter(column_qualifier_regex_filter=self.regex)
251
+
252
+
253
+ class TimestampRange(object):
254
+ """Range of time with inclusive lower and exclusive upper bounds.
255
+
256
+ :type start: :class:`datetime.datetime`
257
+ :param start: (Optional) The (inclusive) lower bound of the timestamp
258
+ range. If omitted, defaults to Unix epoch.
259
+
260
+ :type end: :class:`datetime.datetime`
261
+ :param end: (Optional) The (exclusive) upper bound of the timestamp
262
+ range. If omitted, no upper bound is used.
263
+ """
264
+
265
+ def __init__(self, start=None, end=None):
266
+ self.start = start
267
+ self.end = end
268
+
269
+ def __eq__(self, other):
270
+ if not isinstance(other, self.__class__):
271
+ return NotImplemented
272
+ return other.start == self.start and other.end == self.end
273
+
274
+ def __ne__(self, other):
275
+ return not self == other
276
+
277
+ def to_pb(self):
278
+ """Converts the :class:`TimestampRange` to a protobuf.
279
+
280
+ :rtype: :class:`.data_v2_pb2.TimestampRange`
281
+ :returns: The converted current object.
282
+ """
283
+ timestamp_range_kwargs = {}
284
+ if self.start is not None:
285
+ timestamp_range_kwargs["start_timestamp_micros"] = (
286
+ _microseconds_from_datetime(self.start) // 1000 * 1000
287
+ )
288
+ if self.end is not None:
289
+ end_time = _microseconds_from_datetime(self.end)
290
+ if end_time % 1000 != 0:
291
+ end_time = end_time // 1000 * 1000 + 1000
292
+ timestamp_range_kwargs["end_timestamp_micros"] = end_time
293
+ return data_v2_pb2.TimestampRange(**timestamp_range_kwargs)
294
+
295
+
296
+ class TimestampRangeFilter(RowFilter):
297
+ """Row filter that limits cells to a range of time.
298
+
299
+ :type range_: :class:`TimestampRange`
300
+ :param range_: Range of time that cells should match against.
301
+ """
302
+
303
+ def __init__(self, range_):
304
+ self.range_ = range_
305
+
306
+ def __eq__(self, other):
307
+ if not isinstance(other, self.__class__):
308
+ return NotImplemented
309
+ return other.range_ == self.range_
310
+
311
+ def __ne__(self, other):
312
+ return not self == other
313
+
314
+ def to_pb(self):
315
+ """Converts the row filter to a protobuf.
316
+
317
+ First converts the ``range_`` on the current object to a protobuf and
318
+ then uses it in the ``timestamp_range_filter`` field.
319
+
320
+ :rtype: :class:`.data_v2_pb2.RowFilter`
321
+ :returns: The converted current object.
322
+ """
323
+ return data_v2_pb2.RowFilter(timestamp_range_filter=self.range_.to_pb())
324
+
325
+
326
+ class ColumnRangeFilter(RowFilter):
327
+ """A row filter to restrict to a range of columns.
328
+
329
+ Both the start and end column can be included or excluded in the range.
330
+ By default, we include them both, but this can be changed with optional
331
+ flags.
332
+
333
+ :type column_family_id: str
334
+ :param column_family_id: The column family that contains the columns. Must
335
+ be of the form ``[_a-zA-Z0-9][-_.a-zA-Z0-9]*``.
336
+
337
+ :type start_column: bytes
338
+ :param start_column: The start of the range of columns. If no value is
339
+ used, the backend applies no upper bound to the
340
+ values.
341
+
342
+ :type end_column: bytes
343
+ :param end_column: The end of the range of columns. If no value is used,
344
+ the backend applies no upper bound to the values.
345
+
346
+ :type inclusive_start: bool
347
+ :param inclusive_start: Boolean indicating if the start column should be
348
+ included in the range (or excluded). Defaults
349
+ to :data:`True` if ``start_column`` is passed and
350
+ no ``inclusive_start`` was given.
351
+
352
+ :type inclusive_end: bool
353
+ :param inclusive_end: Boolean indicating if the end column should be
354
+ included in the range (or excluded). Defaults
355
+ to :data:`True` if ``end_column`` is passed and
356
+ no ``inclusive_end`` was given.
357
+
358
+ :raises: :class:`ValueError <exceptions.ValueError>` if ``inclusive_start``
359
+ is set but no ``start_column`` is given or if ``inclusive_end``
360
+ is set but no ``end_column`` is given
361
+ """
362
+
363
+ def __init__(
364
+ self,
365
+ column_family_id,
366
+ start_column=None,
367
+ end_column=None,
368
+ inclusive_start=None,
369
+ inclusive_end=None,
370
+ ):
371
+ self.column_family_id = column_family_id
372
+
373
+ if inclusive_start is None:
374
+ inclusive_start = True
375
+ elif start_column is None:
376
+ raise ValueError(
377
+ "Inclusive start was specified but no " "start column was given."
378
+ )
379
+ self.start_column = start_column
380
+ self.inclusive_start = inclusive_start
381
+
382
+ if inclusive_end is None:
383
+ inclusive_end = True
384
+ elif end_column is None:
385
+ raise ValueError(
386
+ "Inclusive end was specified but no " "end column was given."
387
+ )
388
+ self.end_column = end_column
389
+ self.inclusive_end = inclusive_end
390
+
391
+ def __eq__(self, other):
392
+ if not isinstance(other, self.__class__):
393
+ return NotImplemented
394
+ return (
395
+ other.column_family_id == self.column_family_id
396
+ and other.start_column == self.start_column
397
+ and other.end_column == self.end_column
398
+ and other.inclusive_start == self.inclusive_start
399
+ and other.inclusive_end == self.inclusive_end
400
+ )
401
+
402
+ def __ne__(self, other):
403
+ return not self == other
404
+
405
+ def to_pb(self):
406
+ """Converts the row filter to a protobuf.
407
+
408
+ First converts to a :class:`.data_v2_pb2.ColumnRange` and then uses it
409
+ in the ``column_range_filter`` field.
410
+
411
+ :rtype: :class:`.data_v2_pb2.RowFilter`
412
+ :returns: The converted current object.
413
+ """
414
+ column_range_kwargs = {"family_name": self.column_family_id}
415
+ if self.start_column is not None:
416
+ if self.inclusive_start:
417
+ key = "start_qualifier_closed"
418
+ else:
419
+ key = "start_qualifier_open"
420
+ column_range_kwargs[key] = _to_bytes(self.start_column)
421
+ if self.end_column is not None:
422
+ if self.inclusive_end:
423
+ key = "end_qualifier_closed"
424
+ else:
425
+ key = "end_qualifier_open"
426
+ column_range_kwargs[key] = _to_bytes(self.end_column)
427
+
428
+ column_range = data_v2_pb2.ColumnRange(**column_range_kwargs)
429
+ return data_v2_pb2.RowFilter(column_range_filter=column_range)
430
+
431
+
432
+ class ValueRegexFilter(_RegexFilter):
433
+ """Row filter for a value regular expression.
434
+
435
+ The ``regex`` must be valid RE2 patterns. See Google's
436
+ `RE2 reference`_ for the accepted syntax.
437
+
438
+ .. _RE2 reference: https://github.com/google/re2/wiki/Syntax
439
+
440
+ .. note::
441
+
442
+ Special care need be used with the expression used. Since
443
+ each of these properties can contain arbitrary bytes, the ``\\C``
444
+ escape sequence must be used if a true wildcard is desired. The ``.``
445
+ character will not match the new line character ``\\n``, which may be
446
+ present in a binary value.
447
+
448
+ :type regex: bytes or str
449
+ :param regex: A regular expression (RE2) to match cells with values that
450
+ match this regex. String values will be encoded as ASCII.
451
+ """
452
+
453
+ def to_pb(self):
454
+ """Converts the row filter to a protobuf.
455
+
456
+ :rtype: :class:`.data_v2_pb2.RowFilter`
457
+ :returns: The converted current object.
458
+ """
459
+ return data_v2_pb2.RowFilter(value_regex_filter=self.regex)
460
+
461
+
462
+ class ExactValueFilter(ValueRegexFilter):
463
+ """Row filter for an exact value.
464
+
465
+
466
+ :type value: bytes or str or int
467
+ :param value:
468
+ a literal string encodable as ASCII, or the
469
+ equivalent bytes, or an integer (which will be packed into 8-bytes).
470
+ """
471
+
472
+ def __init__(self, value):
473
+ if isinstance(value, int):
474
+ value = _PACK_I64(value)
475
+ super(ExactValueFilter, self).__init__(value)
476
+
477
+
478
+ class ValueRangeFilter(RowFilter):
479
+ """A range of values to restrict to in a row filter.
480
+
481
+ Will only match cells that have values in this range.
482
+
483
+ Both the start and end value can be included or excluded in the range.
484
+ By default, we include them both, but this can be changed with optional
485
+ flags.
486
+
487
+ :type start_value: bytes
488
+ :param start_value: The start of the range of values. If no value is used,
489
+ the backend applies no lower bound to the values.
490
+
491
+ :type end_value: bytes
492
+ :param end_value: The end of the range of values. If no value is used,
493
+ the backend applies no upper bound to the values.
494
+
495
+ :type inclusive_start: bool
496
+ :param inclusive_start: Boolean indicating if the start value should be
497
+ included in the range (or excluded). Defaults
498
+ to :data:`True` if ``start_value`` is passed and
499
+ no ``inclusive_start`` was given.
500
+
501
+ :type inclusive_end: bool
502
+ :param inclusive_end: Boolean indicating if the end value should be
503
+ included in the range (or excluded). Defaults
504
+ to :data:`True` if ``end_value`` is passed and
505
+ no ``inclusive_end`` was given.
506
+
507
+ :raises: :class:`ValueError <exceptions.ValueError>` if ``inclusive_start``
508
+ is set but no ``start_value`` is given or if ``inclusive_end``
509
+ is set but no ``end_value`` is given
510
+ """
511
+
512
+ def __init__(
513
+ self, start_value=None, end_value=None, inclusive_start=None, inclusive_end=None
514
+ ):
515
+ if inclusive_start is None:
516
+ inclusive_start = True
517
+ elif start_value is None:
518
+ raise ValueError(
519
+ "Inclusive start was specified but no " "start value was given."
520
+ )
521
+ if isinstance(start_value, int):
522
+ start_value = _PACK_I64(start_value)
523
+ self.start_value = start_value
524
+ self.inclusive_start = inclusive_start
525
+
526
+ if inclusive_end is None:
527
+ inclusive_end = True
528
+ elif end_value is None:
529
+ raise ValueError(
530
+ "Inclusive end was specified but no " "end value was given."
531
+ )
532
+ if isinstance(end_value, int):
533
+ end_value = _PACK_I64(end_value)
534
+ self.end_value = end_value
535
+ self.inclusive_end = inclusive_end
536
+
537
+ def __eq__(self, other):
538
+ if not isinstance(other, self.__class__):
539
+ return NotImplemented
540
+ return (
541
+ other.start_value == self.start_value
542
+ and other.end_value == self.end_value
543
+ and other.inclusive_start == self.inclusive_start
544
+ and other.inclusive_end == self.inclusive_end
545
+ )
546
+
547
+ def __ne__(self, other):
548
+ return not self == other
549
+
550
+ def to_pb(self):
551
+ """Converts the row filter to a protobuf.
552
+
553
+ First converts to a :class:`.data_v2_pb2.ValueRange` and then uses
554
+ it to create a row filter protobuf.
555
+
556
+ :rtype: :class:`.data_v2_pb2.RowFilter`
557
+ :returns: The converted current object.
558
+ """
559
+ value_range_kwargs = {}
560
+ if self.start_value is not None:
561
+ if self.inclusive_start:
562
+ key = "start_value_closed"
563
+ else:
564
+ key = "start_value_open"
565
+ value_range_kwargs[key] = _to_bytes(self.start_value)
566
+ if self.end_value is not None:
567
+ if self.inclusive_end:
568
+ key = "end_value_closed"
569
+ else:
570
+ key = "end_value_open"
571
+ value_range_kwargs[key] = _to_bytes(self.end_value)
572
+
573
+ value_range = data_v2_pb2.ValueRange(**value_range_kwargs)
574
+ return data_v2_pb2.RowFilter(value_range_filter=value_range)
575
+
576
+
577
+ class _CellCountFilter(RowFilter):
578
+ """Row filter that uses an integer count of cells.
579
+
580
+ The cell count is used as an offset or a limit for the number
581
+ of results returned.
582
+
583
+ :type num_cells: int
584
+ :param num_cells: An integer count / offset / limit.
585
+ """
586
+
587
+ def __init__(self, num_cells):
588
+ self.num_cells = num_cells
589
+
590
+ def __eq__(self, other):
591
+ if not isinstance(other, self.__class__):
592
+ return NotImplemented
593
+ return other.num_cells == self.num_cells
594
+
595
+ def __ne__(self, other):
596
+ return not self == other
597
+
598
+
599
+ class CellsRowOffsetFilter(_CellCountFilter):
600
+ """Row filter to skip cells in a row.
601
+
602
+ :type num_cells: int
603
+ :param num_cells: Skips the first N cells of the row.
604
+ """
605
+
606
+ def to_pb(self):
607
+ """Converts the row filter to a protobuf.
608
+
609
+ :rtype: :class:`.data_v2_pb2.RowFilter`
610
+ :returns: The converted current object.
611
+ """
612
+ return data_v2_pb2.RowFilter(cells_per_row_offset_filter=self.num_cells)
613
+
614
+
615
+ class CellsRowLimitFilter(_CellCountFilter):
616
+ """Row filter to limit cells in a row.
617
+
618
+ :type num_cells: int
619
+ :param num_cells: Matches only the first N cells of the row.
620
+ """
621
+
622
+ def to_pb(self):
623
+ """Converts the row filter to a protobuf.
624
+
625
+ :rtype: :class:`.data_v2_pb2.RowFilter`
626
+ :returns: The converted current object.
627
+ """
628
+ return data_v2_pb2.RowFilter(cells_per_row_limit_filter=self.num_cells)
629
+
630
+
631
+ class CellsColumnLimitFilter(_CellCountFilter):
632
+ """Row filter to limit cells in a column.
633
+
634
+ :type num_cells: int
635
+ :param num_cells: Matches only the most recent N cells within each column.
636
+ This filters a (family name, column) pair, based on
637
+ timestamps of each cell.
638
+ """
639
+
640
+ def to_pb(self):
641
+ """Converts the row filter to a protobuf.
642
+
643
+ :rtype: :class:`.data_v2_pb2.RowFilter`
644
+ :returns: The converted current object.
645
+ """
646
+ return data_v2_pb2.RowFilter(cells_per_column_limit_filter=self.num_cells)
647
+
648
+
649
+ class StripValueTransformerFilter(_BoolFilter):
650
+ """Row filter that transforms cells into empty string (0 bytes).
651
+
652
+ :type flag: bool
653
+ :param flag: If :data:`True`, replaces each cell's value with the empty
654
+ string. As the name indicates, this is more useful as a
655
+ transformer than a generic query / filter.
656
+ """
657
+
658
+ def to_pb(self):
659
+ """Converts the row filter to a protobuf.
660
+
661
+ :rtype: :class:`.data_v2_pb2.RowFilter`
662
+ :returns: The converted current object.
663
+ """
664
+ return data_v2_pb2.RowFilter(strip_value_transformer=self.flag)
665
+
666
+
667
+ class ApplyLabelFilter(RowFilter):
668
+ """Filter to apply labels to cells.
669
+
670
+ Intended to be used as an intermediate filter on a pre-existing filtered
671
+ result set. This way if two sets are combined, the label can tell where
672
+ the cell(s) originated.This allows the client to determine which results
673
+ were produced from which part of the filter.
674
+
675
+ .. note::
676
+
677
+ Due to a technical limitation of the backend, it is not currently
678
+ possible to apply multiple labels to a cell.
679
+
680
+ :type label: str
681
+ :param label: Label to apply to cells in the output row. Values must be
682
+ at most 15 characters long, and match the pattern
683
+ ``[a-z0-9\\-]+``.
684
+ """
685
+
686
+ def __init__(self, label):
687
+ self.label = label
688
+
689
+ def __eq__(self, other):
690
+ if not isinstance(other, self.__class__):
691
+ return NotImplemented
692
+ return other.label == self.label
693
+
694
+ def __ne__(self, other):
695
+ return not self == other
696
+
697
+ def to_pb(self):
698
+ """Converts the row filter to a protobuf.
699
+
700
+ :rtype: :class:`.data_v2_pb2.RowFilter`
701
+ :returns: The converted current object.
702
+ """
703
+ return data_v2_pb2.RowFilter(apply_label_transformer=self.label)
704
+
705
+
706
+ class _FilterCombination(RowFilter):
707
+ """Chain of row filters.
708
+
709
+ Sends rows through several filters in sequence. The filters are "chained"
710
+ together to process a row. After the first filter is applied, the second
711
+ is applied to the filtered output and so on for subsequent filters.
712
+
713
+ :type filters: list
714
+ :param filters: List of :class:`RowFilter`
715
+ """
716
+
717
+ def __init__(self, filters=None):
718
+ if filters is None:
719
+ filters = []
720
+ self.filters = filters
721
+
722
+ def __eq__(self, other):
723
+ if not isinstance(other, self.__class__):
724
+ return NotImplemented
725
+ return other.filters == self.filters
726
+
727
+ def __ne__(self, other):
728
+ return not self == other
729
+
730
+
731
+ class RowFilterChain(_FilterCombination):
732
+ """Chain of row filters.
733
+
734
+ Sends rows through several filters in sequence. The filters are "chained"
735
+ together to process a row. After the first filter is applied, the second
736
+ is applied to the filtered output and so on for subsequent filters.
737
+
738
+ :type filters: list
739
+ :param filters: List of :class:`RowFilter`
740
+ """
741
+
742
+ def to_pb(self):
743
+ """Converts the row filter to a protobuf.
744
+
745
+ :rtype: :class:`.data_v2_pb2.RowFilter`
746
+ :returns: The converted current object.
747
+ """
748
+ chain = data_v2_pb2.RowFilter.Chain(
749
+ filters=[row_filter.to_pb() for row_filter in self.filters]
750
+ )
751
+ return data_v2_pb2.RowFilter(chain=chain)
752
+
753
+
754
+ class RowFilterUnion(_FilterCombination):
755
+ """Union of row filters.
756
+
757
+ Sends rows through several filters simultaneously, then
758
+ merges / interleaves all the filtered results together.
759
+
760
+ If multiple cells are produced with the same column and timestamp,
761
+ they will all appear in the output row in an unspecified mutual order.
762
+
763
+ :type filters: list
764
+ :param filters: List of :class:`RowFilter`
765
+ """
766
+
767
+ def to_pb(self):
768
+ """Converts the row filter to a protobuf.
769
+
770
+ :rtype: :class:`.data_v2_pb2.RowFilter`
771
+ :returns: The converted current object.
772
+ """
773
+ interleave = data_v2_pb2.RowFilter.Interleave(
774
+ filters=[row_filter.to_pb() for row_filter in self.filters]
775
+ )
776
+ return data_v2_pb2.RowFilter(interleave=interleave)
777
+
778
+
779
+ class ConditionalRowFilter(RowFilter):
780
+ """Conditional row filter which exhibits ternary behavior.
781
+
782
+ Executes one of two filters based on another filter. If the ``base_filter``
783
+ returns any cells in the row, then ``true_filter`` is executed. If not,
784
+ then ``false_filter`` is executed.
785
+
786
+ .. note::
787
+
788
+ The ``base_filter`` does not execute atomically with the true and false
789
+ filters, which may lead to inconsistent or unexpected results.
790
+
791
+ Additionally, executing a :class:`ConditionalRowFilter` has poor
792
+ performance on the server, especially when ``false_filter`` is set.
793
+
794
+ :type base_filter: :class:`RowFilter`
795
+ :param base_filter: The filter to condition on before executing the
796
+ true/false filters.
797
+
798
+ :type true_filter: :class:`RowFilter`
799
+ :param true_filter: (Optional) The filter to execute if there are any cells
800
+ matching ``base_filter``. If not provided, no results
801
+ will be returned in the true case.
802
+
803
+ :type false_filter: :class:`RowFilter`
804
+ :param false_filter: (Optional) The filter to execute if there are no cells
805
+ matching ``base_filter``. If not provided, no results
806
+ will be returned in the false case.
807
+ """
808
+
809
+ def __init__(self, base_filter, true_filter=None, false_filter=None):
810
+ self.base_filter = base_filter
811
+ self.true_filter = true_filter
812
+ self.false_filter = false_filter
813
+
814
+ def __eq__(self, other):
815
+ if not isinstance(other, self.__class__):
816
+ return NotImplemented
817
+ return (
818
+ other.base_filter == self.base_filter
819
+ and other.true_filter == self.true_filter
820
+ and other.false_filter == self.false_filter
821
+ )
822
+
823
+ def __ne__(self, other):
824
+ return not self == other
825
+
826
+ def to_pb(self):
827
+ """Converts the row filter to a protobuf.
828
+
829
+ :rtype: :class:`.data_v2_pb2.RowFilter`
830
+ :returns: The converted current object.
831
+ """
832
+ condition_kwargs = {"predicate_filter": self.base_filter.to_pb()}
833
+ if self.true_filter is not None:
834
+ condition_kwargs["true_filter"] = self.true_filter.to_pb()
835
+ if self.false_filter is not None:
836
+ condition_kwargs["false_filter"] = self.false_filter.to_pb()
837
+ condition = data_v2_pb2.RowFilter.Condition(**condition_kwargs)
838
+ return data_v2_pb2.RowFilter(condition=condition)