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