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