google-cloud-bigtable 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +19 -0
  3. data/AUTHENTICATION.md +177 -0
  4. data/CHANGELOG.md +223 -0
  5. data/CODE_OF_CONDUCT.md +40 -0
  6. data/CONTRIBUTING.md +188 -0
  7. data/EMULATOR.md +30 -0
  8. data/LICENSE +201 -0
  9. data/LOGGING.md +32 -0
  10. data/OVERVIEW.md +400 -0
  11. data/TROUBLESHOOTING.md +31 -0
  12. data/lib/google-cloud-bigtable.rb +171 -0
  13. data/lib/google/bigtable/admin/v2/bigtable_instance_admin_pb.rb +145 -0
  14. data/lib/google/bigtable/admin/v2/bigtable_instance_admin_services_pb.rb +90 -0
  15. data/lib/google/bigtable/admin/v2/bigtable_table_admin_pb.rb +208 -0
  16. data/lib/google/bigtable/admin/v2/bigtable_table_admin_services_pb.rb +154 -0
  17. data/lib/google/bigtable/admin/v2/common_pb.rb +30 -0
  18. data/lib/google/bigtable/admin/v2/instance_pb.rb +74 -0
  19. data/lib/google/bigtable/admin/v2/table_pb.rb +127 -0
  20. data/lib/google/bigtable/v2/bigtable_pb.rb +113 -0
  21. data/lib/google/bigtable/v2/bigtable_services_pb.rb +68 -0
  22. data/lib/google/bigtable/v2/data_pb.rb +156 -0
  23. data/lib/google/cloud/bigtable.rb +184 -0
  24. data/lib/google/cloud/bigtable/admin.rb +202 -0
  25. data/lib/google/cloud/bigtable/admin/credentials.rb +27 -0
  26. data/lib/google/cloud/bigtable/admin/v2.rb +223 -0
  27. data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client.rb +1451 -0
  28. data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client_config.json +139 -0
  29. data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client.rb +1734 -0
  30. data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client_config.json +163 -0
  31. data/lib/google/cloud/bigtable/admin/v2/credentials.rb +51 -0
  32. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_instance_admin.rb +297 -0
  33. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_table_admin.rb +587 -0
  34. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/instance.rb +193 -0
  35. data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/table.rb +303 -0
  36. data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/iam_policy.rb +64 -0
  37. data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/options.rb +33 -0
  38. data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/policy.rb +151 -0
  39. data/lib/google/cloud/bigtable/admin/v2/doc/google/longrunning/operations.rb +51 -0
  40. data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/any.rb +131 -0
  41. data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/duration.rb +91 -0
  42. data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/empty.rb +29 -0
  43. data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/field_mask.rb +222 -0
  44. data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/timestamp.rb +113 -0
  45. data/lib/google/cloud/bigtable/admin/v2/doc/google/rpc/status.rb +39 -0
  46. data/lib/google/cloud/bigtable/admin/v2/doc/google/type/expr.rb +45 -0
  47. data/lib/google/cloud/bigtable/app_profile.rb +439 -0
  48. data/lib/google/cloud/bigtable/app_profile/job.rb +99 -0
  49. data/lib/google/cloud/bigtable/app_profile/list.rb +165 -0
  50. data/lib/google/cloud/bigtable/backup.rb +324 -0
  51. data/lib/google/cloud/bigtable/backup/job.rb +87 -0
  52. data/lib/google/cloud/bigtable/backup/list.rb +167 -0
  53. data/lib/google/cloud/bigtable/chunk_processor.rb +241 -0
  54. data/lib/google/cloud/bigtable/cluster.rb +390 -0
  55. data/lib/google/cloud/bigtable/cluster/job.rb +88 -0
  56. data/lib/google/cloud/bigtable/cluster/list.rb +171 -0
  57. data/lib/google/cloud/bigtable/column_family.rb +73 -0
  58. data/lib/google/cloud/bigtable/column_family_map.rb +426 -0
  59. data/lib/google/cloud/bigtable/column_range.rb +194 -0
  60. data/lib/google/cloud/bigtable/convert.rb +83 -0
  61. data/lib/google/cloud/bigtable/credentials.rb +25 -0
  62. data/lib/google/cloud/bigtable/errors.rb +38 -0
  63. data/lib/google/cloud/bigtable/gc_rule.rb +334 -0
  64. data/lib/google/cloud/bigtable/instance.rb +935 -0
  65. data/lib/google/cloud/bigtable/instance/cluster_map.rb +74 -0
  66. data/lib/google/cloud/bigtable/instance/job.rb +98 -0
  67. data/lib/google/cloud/bigtable/instance/list.rb +164 -0
  68. data/lib/google/cloud/bigtable/longrunning_job.rb +122 -0
  69. data/lib/google/cloud/bigtable/mutation_entry.rb +256 -0
  70. data/lib/google/cloud/bigtable/mutation_operations.rb +357 -0
  71. data/lib/google/cloud/bigtable/policy.rb +167 -0
  72. data/lib/google/cloud/bigtable/project.rb +471 -0
  73. data/lib/google/cloud/bigtable/read_modify_write_rule.rb +134 -0
  74. data/lib/google/cloud/bigtable/read_operations.rb +328 -0
  75. data/lib/google/cloud/bigtable/routing_policy.rb +172 -0
  76. data/lib/google/cloud/bigtable/row.rb +136 -0
  77. data/lib/google/cloud/bigtable/row_filter.rb +639 -0
  78. data/lib/google/cloud/bigtable/row_filter/chain_filter.rb +590 -0
  79. data/lib/google/cloud/bigtable/row_filter/condition_filter.rb +114 -0
  80. data/lib/google/cloud/bigtable/row_filter/interleave_filter.rb +621 -0
  81. data/lib/google/cloud/bigtable/row_filter/simple_filter.rb +287 -0
  82. data/lib/google/cloud/bigtable/row_range.rb +179 -0
  83. data/lib/google/cloud/bigtable/rows_mutator.rb +113 -0
  84. data/lib/google/cloud/bigtable/rows_reader.rb +200 -0
  85. data/lib/google/cloud/bigtable/sample_row_key.rb +85 -0
  86. data/lib/google/cloud/bigtable/service.rb +913 -0
  87. data/lib/google/cloud/bigtable/status.rb +76 -0
  88. data/lib/google/cloud/bigtable/table.rb +686 -0
  89. data/lib/google/cloud/bigtable/table/cluster_state.rb +125 -0
  90. data/lib/google/cloud/bigtable/table/list.rb +154 -0
  91. data/lib/google/cloud/bigtable/table/restore_job.rb +117 -0
  92. data/lib/google/cloud/bigtable/v2.rb +146 -0
  93. data/lib/google/cloud/bigtable/v2/bigtable_client.rb +591 -0
  94. data/lib/google/cloud/bigtable/v2/bigtable_client_config.json +83 -0
  95. data/lib/google/cloud/bigtable/v2/credentials.rb +46 -0
  96. data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/bigtable.rb +290 -0
  97. data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/data.rb +493 -0
  98. data/lib/google/cloud/bigtable/v2/doc/google/protobuf/any.rb +131 -0
  99. data/lib/google/cloud/bigtable/v2/doc/google/protobuf/wrappers.rb +34 -0
  100. data/lib/google/cloud/bigtable/v2/doc/google/rpc/status.rb +39 -0
  101. data/lib/google/cloud/bigtable/value_range.rb +181 -0
  102. data/lib/google/cloud/bigtable/version.rb +22 -0
  103. metadata +337 -0
@@ -0,0 +1,590 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2018 Google LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # https:#www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+
18
+ module Google
19
+ module Cloud
20
+ module Bigtable
21
+ module RowFilter
22
+ ##
23
+ # # ChainFilter
24
+ #
25
+ # A RowFilter that sends rows through several RowFilters in sequence.
26
+ #
27
+ # The elements of "filters" are chained together to process the input row:
28
+ #
29
+ # in row -> f(0) -> intermediate row -> f(1) -> ... -> f(N) -> out row
30
+ #
31
+ # The full chain is executed atomically.
32
+ #
33
+ # @example
34
+ # require "google/cloud/bigtable"
35
+ #
36
+ # chain = Google::Cloud::Bigtable::RowFilter.chain
37
+ # # Add filters to chain filter
38
+ # chain.key("user-*").label("users")
39
+ #
40
+ class ChainFilter
41
+ # @private
42
+ # Creates an instance of a chain filter.
43
+ def initialize
44
+ @filters = []
45
+ end
46
+
47
+ ##
48
+ # Adds a chain filter.
49
+ #
50
+ # A Chain RowFilter that sends rows through several RowFilters in sequence.
51
+ #
52
+ # The elements of "filters" are chained together to process the input row:
53
+ #
54
+ # in row -> f(0) -> intermediate row -> f(1) -> ... -> f(N) -> out row
55
+ #
56
+ # The full chain is executed atomically.
57
+ #
58
+ # @param filter [SimpleFilter, ChainFilter, InterleaveFilter, ConditionFilter]
59
+ # @return [Google::Cloud::Bigtable::RowFilter::ChainFilter]
60
+ # `self` instance of chain filter.
61
+ #
62
+ # @example Create a chain filter and add a chain filter.
63
+ # require "google/cloud/bigtable"
64
+ #
65
+ # chain_1 = Google::Cloud::Bigtable::RowFilter.chain
66
+ #
67
+ # # Add filters to chain filter
68
+ # chain_1.key("user-*").cells_per_row(5)
69
+ #
70
+ # filter = Google::Cloud::Bigtable::RowFilter.chain
71
+ # filter.chain(chain_1)
72
+ #
73
+ # # OR
74
+ # filter = Google::Cloud::Bigtable::RowFilter.chain.chain(chain_1)
75
+ #
76
+ def chain filter
77
+ raise RowFilterError, "Filter type must be ChainFilter" unless filter.instance_of? ChainFilter
78
+ add filter
79
+ end
80
+
81
+ ##
82
+ # Adds an interleave filter.
83
+ #
84
+ # A RowFilter that sends each row to each of several component
85
+ # RowFilters and interleaves the results.
86
+ #
87
+ # The elements of "filters" all process a copy of the input row, and the
88
+ # results are pooled, sorted, and combined into a single output row.
89
+ # If multiple cells are produced with the same column and timestamp,
90
+ # they will all appear in the output row in an unspecified mutual order.
91
+ # Consider the following example, with three filters:
92
+ #
93
+ # input row
94
+ # |
95
+ # -----------------------------------------------------
96
+ # | | |
97
+ # f(0) f(1) f(2)
98
+ # | | |
99
+ # 1: foo,bar,10,x foo,bar,10,z far,bar,7,a
100
+ # 2: foo,blah,11,z far,blah,5,x far,blah,5,x
101
+ # | | |
102
+ # -----------------------------------------------------
103
+ # |
104
+ # 1: foo,bar,10,z # could have switched with #2
105
+ # 2: foo,bar,10,x # could have switched with #1
106
+ # 3: foo,blah,11,z
107
+ # 4: far,bar,7,a
108
+ # 5: far,blah,5,x # identical to #6
109
+ # 6: far,blah,5,x # identical to #5
110
+ #
111
+ # All interleaved filters are executed atomically.
112
+ #
113
+ # See {Google::Cloud::Bigtable::RowFilter::InterleaveFilter}
114
+ #
115
+ # @param filter [SimpleFilter, ChainFilter, InterleaveFilter, ConditionFilter]
116
+ # @return [Google::Cloud::Bigtable::RowFilter::ChainFilter]
117
+ # `self` instance of chain filter.
118
+ #
119
+ # @example Add an interleave filter to the chain filter.
120
+ # require "google/cloud/bigtable"
121
+ #
122
+ # interleave = Google::Cloud::Bigtable::RowFilter.interleave
123
+ #
124
+ # # Add filters to interleave filter
125
+ # interleave.key("user-*").cells_per_column(3)
126
+ #
127
+ # chain = Google::Cloud::Bigtable::RowFilter.chain.interleave(interleave)
128
+ #
129
+ def interleave filter
130
+ raise RowFilterError, "Filter type must be InterleaveFilter" unless filter.instance_of? InterleaveFilter
131
+ add filter
132
+ end
133
+
134
+ ##
135
+ # Adds a condition filter.
136
+ #
137
+ # A RowFilter that evaluates one of two possible RowFilters, depending on
138
+ # whether or not a predicate RowFilter outputs any cells from the input row.
139
+ #
140
+ # IMPORTANT NOTE: The predicate filter does not execute atomically with the
141
+ # true and false filters, which may lead to inconsistent or unexpected
142
+ # results. Additionally, condition filters have poor performance, especially
143
+ # when filters are set for the false condition.
144
+ #
145
+ # Cannot be used within the `predicate_filter`, `true_filter`, or `false_filter`.
146
+ #
147
+ # @param filter [Google::Cloud::Bigtable::RowFilter::ConditionFilter]
148
+ # @return [Google::Cloud::Bigtable::RowFilter::ChainFilter]
149
+ # `self` instance of chain filter.
150
+ #
151
+ # @example
152
+ # require "google/cloud/bigtable"
153
+ #
154
+ # predicate = Google::Cloud::Bigtable::RowFilter.key("user-*")
155
+ #
156
+ # label = Google::Cloud::Bigtable::RowFilter.label("user")
157
+ # strip_value = Google::Cloud::Bigtable::RowFilter.strip_value
158
+ #
159
+ # condition_filter = Google::Cloud::Bigtable::RowFilter.
160
+ # condition(predicate).on_match(label).otherwise(strip_value)
161
+ #
162
+ # filter = Google::Cloud::Bigtable::RowFilter.chain.condition(condition_filter)
163
+ #
164
+ def condition filter
165
+ raise RowFilterError, "Filter type must be ConditionFilter" unless filter.instance_of? ConditionFilter
166
+ add filter
167
+ end
168
+
169
+ ##
170
+ # Adds a pass filter.
171
+ #
172
+ # Matches all cells, regardless of input. Functionally equivalent to
173
+ # leaving `filter` unset, but included for completeness.
174
+ #
175
+ # @return [Google::Cloud::Bigtable::RowFilter::ChainFilter]
176
+ # `self` instance of chain filter.
177
+ #
178
+ # @example
179
+ # require "google/cloud/bigtable"
180
+ #
181
+ # filter = Google::Cloud::Bigtable::RowFilter.chain.pass
182
+ #
183
+ def pass
184
+ add RowFilter.pass
185
+ end
186
+
187
+ ##
188
+ # Adds a block-all filter.
189
+ #
190
+ # Does not match any cells, regardless of input. Useful for temporarily
191
+ # disabling just part of a filter.
192
+ #
193
+ # @return [Google::Cloud::Bigtable::RowFilter::ChainFilter]
194
+ # `self` instance of chain filter.
195
+ #
196
+ # @example
197
+ # require "google/cloud/bigtable"
198
+ #
199
+ # filter = Google::Cloud::Bigtable::RowFilter.chain.block
200
+ #
201
+ def block
202
+ add RowFilter.block
203
+ end
204
+
205
+ ##
206
+ # Adds a sink filter.
207
+ #
208
+ # Outputs all cells directly to the output of the read rather than to any parent filter.
209
+ #
210
+ # @return [Google::Cloud::Bigtable::RowFilter::ChainFilter]
211
+ # `self` instance of chain filter.
212
+ #
213
+ # @example
214
+ # require "google/cloud/bigtable"
215
+ #
216
+ # filter = Google::Cloud::Bigtable::RowFilter.chain.sink
217
+ #
218
+ def sink
219
+ add RowFilter.sink
220
+ end
221
+
222
+ ##
223
+ # Adds a strip-value filter.
224
+ #
225
+ # Replaces each cell's value with an empty string.
226
+ #
227
+ # @return [Google::Cloud::Bigtable::RowFilter::ChainFilter]
228
+ # `self` instance of chain filter.
229
+ #
230
+ # @example
231
+ # require "google/cloud/bigtable"
232
+ #
233
+ # filter = Google::Cloud::Bigtable::RowFilter.chain.strip_value
234
+ #
235
+ def strip_value
236
+ add RowFilter.strip_value
237
+ end
238
+
239
+ ##
240
+ # Adds a key-filter instance to match keys using a regular expression.
241
+ #
242
+ # Matches only cells from rows whose keys satisfy the given RE2 regex. In
243
+ # other words, passes through the entire row when the key matches, and
244
+ # otherwise produces an empty row.
245
+ # Note that, since row keys can contain arbitrary bytes, the `\C` escape
246
+ # sequence must be used if a true wildcard is desired. The `.` character
247
+ # will not match the new line character `\n`, which may be present in a
248
+ # binary key.
249
+ #
250
+ # For Regex syntax:
251
+ # @see https://github.com/google/re2/wiki/Syntax
252
+ #
253
+ # @param regex [String] Regex to match row keys.
254
+ # @return [Google::Cloud::Bigtable::RowFilter::ChainFilter]
255
+ # `self` instance of chain filter.
256
+ #
257
+ # @example
258
+ # require "google/cloud/bigtable"
259
+ #
260
+ # filter = Google::Cloud::Bigtable::RowFilter.chain.key("user-*")
261
+ #
262
+ def key regex
263
+ add RowFilter.key(regex)
264
+ end
265
+
266
+ ##
267
+ # Adds a sample-probability filter.
268
+ #
269
+ # Matches all cells from a row with probability p, and matches no cells
270
+ # from the row with probability 1-p.
271
+ #
272
+ # @param probability [Float] Probability value.
273
+ # Probability must be greater than 0 and less than 1.0.
274
+ # @return [Google::Cloud::Bigtable::RowFilter::ChainFilter]
275
+ # `self` instance of chain filter.
276
+ #
277
+ # @example
278
+ # require "google/cloud/bigtable"
279
+ #
280
+ # filter = Google::Cloud::Bigtable::RowFilter.chain.sample(0.5)
281
+ #
282
+ def sample probability
283
+ add RowFilter.sample(probability)
284
+ end
285
+
286
+ ##
287
+ # Adds a family-name-match filter using a regular expression.
288
+ #
289
+ # Matches only cells from columns whose families satisfy the given RE2
290
+ # regex. For technical reasons, the regex must not contain the `:`
291
+ # character, even if it is not being used as a literal.
292
+ # Note that, since column families cannot contain the new line character
293
+ # `\n`, it is sufficient to use `.` as a full wildcard when matching
294
+ # column family names.
295
+ #
296
+ # For Regex syntax:
297
+ # @see https://github.com/google/re2/wiki/Syntax
298
+ #
299
+ # @param regex [String] Regex to match family name.
300
+ # @return [Google::Cloud::Bigtable::RowFilter::ChainFilter]
301
+ # `self` instance of chain filter.
302
+ #
303
+ # @example
304
+ # require "google/cloud/bigtable"
305
+ #
306
+ # filter = Google::Cloud::Bigtable::RowFilter.chain.family("cf-*")
307
+ #
308
+ def family regex
309
+ add RowFilter.family(regex)
310
+ end
311
+
312
+ ##
313
+ # Adds a column-qualifier-match filter using a regular expression.
314
+ #
315
+ # Matches only cells from columns whose qualifiers satisfy the given RE2
316
+ # regex.
317
+ # Note that, since column qualifiers can contain arbitrary bytes, the `\C`
318
+ # escape sequence must be used if a true wildcard is desired. The `.`
319
+ # character will not match the new line character `\n`, which may be
320
+ # present in a binary qualifier.
321
+ #
322
+ # For Regex syntax:
323
+ # @see https://github.com/google/re2/wiki/Syntax
324
+ #
325
+ # @param regex [String] Regex to match column qualifier name.
326
+ # @return [Google::Cloud::Bigtable::RowFilter::ChainFilter]
327
+ # `self` instance of chain filter.
328
+ #
329
+ # @example
330
+ # require "google/cloud/bigtable"
331
+ #
332
+ # filter = Google::Cloud::Bigtable::RowFilter.chain.qualifier("user-name*")
333
+ #
334
+ def qualifier regex
335
+ add RowFilter.qualifier(regex)
336
+ end
337
+
338
+ ##
339
+ # Adds a value-match filter using a regular expression.
340
+ #
341
+ # Matches only cells with values that satisfy the given regular expression.
342
+ # Note that, since cell values can contain arbitrary bytes, the `\C` escape
343
+ # sequence must be used if a true wildcard is desired. The `.` character
344
+ # will not match the new line character `\n`, which may be present in a
345
+ # binary value.
346
+ #
347
+ # For Regex syntax:
348
+ # @see https://github.com/google/re2/wiki/Syntax
349
+ #
350
+ # @param regex [String] Regex to match cell value.
351
+ # @return [Google::Cloud::Bigtable::RowFilter::ChainFilter]
352
+ # `self` instance of chain filter.
353
+ #
354
+ # @example
355
+ # require "google/cloud/bigtable"
356
+ #
357
+ # filter = Google::Cloud::Bigtable::RowFilter.chain.value("abc*")
358
+ #
359
+ def value regex
360
+ add RowFilter.value(regex)
361
+ end
362
+
363
+ ##
364
+ # Adds a label filter instance to apply a label based on the result of read rows.
365
+ #
366
+ # Applies the given label to all cells in the output row. This allows
367
+ # the client to determine which results were produced from which part of
368
+ # the filter.
369
+ #
370
+ # Values must be at most 15 characters and match the RE2
371
+ # pattern `[a-z0-9\\-]+`
372
+ #
373
+ # Due to a technical limitation, it is not possible to apply
374
+ # multiple labels to a cell. As a result, a chain may have no more than
375
+ # one sub-filter that contains an `apply_label_transformer`. It is okay for
376
+ # an Interleave to contain multiple `apply_label_transformers`, as they
377
+ # will be applied to separate copies of the input.
378
+ #
379
+ # @param value [String] Label name
380
+ # @return [Google::Cloud::Bigtable::RowFilter::ChainFilter]
381
+ # `self` instance of chain filter.
382
+ #
383
+ # @example
384
+ # require "google/cloud/bigtable"
385
+ #
386
+ # filter = Google::Cloud::Bigtable::RowFilter.chain.label("user-detail")
387
+ #
388
+ def label value
389
+ add RowFilter.label(value)
390
+ end
391
+
392
+ ##
393
+ # Adds a cell-per-row-offset filter instance to skip the first N cells.
394
+ #
395
+ # Skips the first N cells of each row, matching all subsequent cells.
396
+ # If duplicate cells are present, as is possible when using an Interleave,
397
+ # each copy of the cell is counted separately.
398
+ #
399
+ # @param offset [Integer] Offset value.
400
+ # @return [Google::Cloud::Bigtable::RowFilter::ChainFilter]
401
+ # `self` instance of chain filter.
402
+ #
403
+ # @example
404
+ # require "google/cloud/bigtable"
405
+ #
406
+ # filter = Google::Cloud::Bigtable::RowFilter.chain.cells_per_row_offset(3)
407
+ #
408
+ def cells_per_row_offset offset
409
+ add RowFilter.cells_per_row_offset(offset)
410
+ end
411
+
412
+ ##
413
+ # Adds a cells-per-row-limit filter.
414
+ #
415
+ # Matches only the first N cells of each row.
416
+ # If duplicate cells are present, as is possible when using an Interleave,
417
+ # each copy of the cell is counted separately.
418
+ #
419
+ # @param limit [String] Max cell match per row limit.
420
+ # @return [Google::Cloud::Bigtable::RowFilter::ChainFilter]
421
+ # `self` instance of chain filter.
422
+ #
423
+ # @example
424
+ # require "google/cloud/bigtable"
425
+ #
426
+ # filter = Google::Cloud::Bigtable::RowFilter.chain.cells_per_row(5)
427
+ #
428
+ def cells_per_row limit
429
+ add RowFilter.cells_per_row(limit)
430
+ end
431
+
432
+ ##
433
+ # Adds a cells-per-column filter.
434
+ #
435
+ # Matches only the most recent N cells within each column. For example,
436
+ # if N=2, this filter would match column `foo:bar` at timestamps 10 and 9,
437
+ # skip all earlier cells in `foo:bar`, and then begin matching again in
438
+ # column `foo:bar2`.
439
+ # If duplicate cells are present, as is possible when using an Interleave,
440
+ # each copy of the cell is counted separately.
441
+ #
442
+ # @param limit [String] Max cell match per column limit.
443
+ # @return [Google::Cloud::Bigtable::RowFilter::ChainFilter]
444
+ # `self` instance of chain filter.
445
+ #
446
+ # @example
447
+ # require "google/cloud/bigtable"
448
+ #
449
+ # filter = Google::Cloud::Bigtable::RowFilter.chain.cells_per_column(5)
450
+ #
451
+ def cells_per_column limit
452
+ add RowFilter.cells_per_column(limit)
453
+ end
454
+
455
+ ##
456
+ # Adds a timestamp-range filter.
457
+ #
458
+ # Matches only cells with timestamps within the given range.
459
+ # Specifies a contiguous range of timestamps.
460
+ #
461
+ # @param from [Integer] Inclusive lower bound.
462
+ # If left empty, interpreted as 0.
463
+ # @param to [Integer] Exclusive upper bound.
464
+ # If left empty, interpreted as infinity.
465
+ # @return [Google::Cloud::Bigtable::RowFilter::ChainFilter]
466
+ # `self` instance of chain filter.
467
+ #
468
+ # @example
469
+ # require "google/cloud/bigtable"
470
+ #
471
+ # timestamp_micros = (Time.now.to_f * 1000000).round(-3)
472
+ # from = timestamp_micros - 300000000
473
+ # to = timestamp_micros
474
+ #
475
+ # filter = Google::Cloud::Bigtable::RowFilter.chain.timestamp_range(from: from, to: to)
476
+ #
477
+ def timestamp_range from: nil, to: nil
478
+ add RowFilter.timestamp_range(from: from, to: to)
479
+ end
480
+
481
+ ##
482
+ # Adds a value-range filter.
483
+ #
484
+ # Matches only cells with values that fall within the given range.
485
+ #
486
+ # See {Google::Cloud::Bigtable::ValueRange#from} and { Google::Cloud::Bigtable::ValueRange#to} for range
487
+ # option inclusive/exclusive options.
488
+ #
489
+ # * The value at which to start the range. If neither field is set, interpreted as an empty string, inclusive.
490
+ # * The value at which to end the range. If neither field is set, interpreted as the infinite string,
491
+ # exclusive.
492
+ #
493
+ # @param range [Google::Cloud::Bigtable::ValueRange]
494
+ # @return [Google::Cloud::Bigtable::RowFilter::ChainFilter]
495
+ # `self` instance of chain filter.
496
+ #
497
+ # @example Start to end range.
498
+ # require "google/cloud/bigtable"
499
+ #
500
+ # bigtable = Google::Cloud::Bigtable.new
501
+ # table = bigtable.table("my-instance", "my-table")
502
+ #
503
+ # range = table.new_value_range.from("value-001").to("value-005")
504
+ # filter = Google::Cloud::Bigtable::RowFilter.chain.value_range(range)
505
+ #
506
+ # @example Start exclusive to infinite end range.
507
+ # require "google/cloud/bigtable"
508
+ #
509
+ # bigtable = Google::Cloud::Bigtable.new
510
+ # table = bigtable.table("my-instance", "my-table")
511
+ #
512
+ # range = table.new_value_range.from("value-001", inclusive: false)
513
+ # filter = Google::Cloud::Bigtable::RowFilter.chain.value_range(range)
514
+ #
515
+ def value_range range
516
+ add RowFilter.value_range(range)
517
+ end
518
+
519
+ ##
520
+ # Adds a column-range filter.
521
+ #
522
+ # Matches only cells from columns within the given range.
523
+ #
524
+ # @param range [Google::Cloud::Bigtable::ColumnRange]
525
+ # @return [Google::Cloud::Bigtable::RowFilter::ChainFilter]
526
+ # `self` instance of chain filter.
527
+ #
528
+ # @example
529
+ # require "google/cloud/bigtable"
530
+ #
531
+ # range = Google::Cloud::Bigtable::ColumnRange.new("cf").from("field0").to('field5')
532
+ #
533
+ # filter = Google::Cloud::Bigtable::RowFilter.chain.column_range(range)
534
+ #
535
+ def column_range range
536
+ add RowFilter.column_range(range)
537
+ end
538
+
539
+ ##
540
+ # Gets the number of filters in the chain.
541
+ #
542
+ # @return [Integer]
543
+ #
544
+ # @example
545
+ # require "google/cloud/bigtable"
546
+ #
547
+ # filter = Google::Cloud::Bigtable::RowFilter.chain.key("user-1*").label("user")
548
+ # filter.length # 2
549
+ #
550
+ def length
551
+ @filters.length
552
+ end
553
+
554
+ ##
555
+ # Returns a frozen copy of the filters array.
556
+ #
557
+ # @return [Array<SimpleFilter|ChainFilter|InterleaveFilter|ConditionFilter>]
558
+ #
559
+ def filters
560
+ @filters.dup.freeze
561
+ end
562
+
563
+ # @private
564
+ #
565
+ # Gets a gRPC object of RowFilter with a chain filter.
566
+ #
567
+ # @return [Google::Bigtable::V2::RowFilter]
568
+ #
569
+ def to_grpc
570
+ Google::Bigtable::V2::RowFilter.new(
571
+ chain: Google::Bigtable::V2::RowFilter::Chain.new(filters: @filters.map(&:to_grpc))
572
+ )
573
+ end
574
+
575
+ private
576
+
577
+ # @private
578
+ # Adds a filter to a chain.
579
+ #
580
+ # @param filter [SimpleFilter, ChainFilter, InterleaveFilter, ConditionFilter]
581
+ #
582
+ def add filter
583
+ @filters << filter
584
+ self
585
+ end
586
+ end
587
+ end
588
+ end
589
+ end
590
+ end