google-cloud-bigtable 0.1.0

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