google-cloud-bigtable 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +36 -0
  3. data/CONTRIBUTING.md +1 -1
  4. data/lib/google-cloud-bigtable.rb +19 -21
  5. data/lib/google/cloud/bigtable.rb +11 -17
  6. data/lib/google/cloud/bigtable/app_profile.rb +148 -82
  7. data/lib/google/cloud/bigtable/app_profile/job.rb +5 -8
  8. data/lib/google/cloud/bigtable/app_profile/list.rb +11 -5
  9. data/lib/google/cloud/bigtable/chunk_processor.rb +23 -35
  10. data/lib/google/cloud/bigtable/cluster.rb +38 -11
  11. data/lib/google/cloud/bigtable/cluster/job.rb +3 -7
  12. data/lib/google/cloud/bigtable/cluster/list.rb +20 -18
  13. data/lib/google/cloud/bigtable/column_family.rb +22 -229
  14. data/lib/google/cloud/bigtable/column_family_map.rb +426 -0
  15. data/lib/google/cloud/bigtable/column_range.rb +9 -1
  16. data/lib/google/cloud/bigtable/convert.rb +12 -4
  17. data/lib/google/cloud/bigtable/errors.rb +4 -1
  18. data/lib/google/cloud/bigtable/gc_rule.rb +184 -65
  19. data/lib/google/cloud/bigtable/instance.rb +136 -126
  20. data/lib/google/cloud/bigtable/instance/cluster_map.rb +9 -7
  21. data/lib/google/cloud/bigtable/instance/job.rb +4 -3
  22. data/lib/google/cloud/bigtable/instance/list.rb +14 -9
  23. data/lib/google/cloud/bigtable/longrunning_job.rb +6 -0
  24. data/lib/google/cloud/bigtable/mutation_entry.rb +19 -23
  25. data/lib/google/cloud/bigtable/mutation_operations.rb +82 -29
  26. data/lib/google/cloud/bigtable/policy.rb +9 -5
  27. data/lib/google/cloud/bigtable/project.rb +62 -140
  28. data/lib/google/cloud/bigtable/read_modify_write_rule.rb +9 -4
  29. data/lib/google/cloud/bigtable/read_operations.rb +28 -41
  30. data/lib/google/cloud/bigtable/routing_policy.rb +171 -0
  31. data/lib/google/cloud/bigtable/row.rb +18 -7
  32. data/lib/google/cloud/bigtable/row_filter.rb +49 -20
  33. data/lib/google/cloud/bigtable/row_filter/chain_filter.rb +71 -43
  34. data/lib/google/cloud/bigtable/row_filter/condition_filter.rb +4 -1
  35. data/lib/google/cloud/bigtable/row_filter/interleave_filter.rb +74 -43
  36. data/lib/google/cloud/bigtable/row_filter/simple_filter.rb +22 -7
  37. data/lib/google/cloud/bigtable/row_range.rb +5 -0
  38. data/lib/google/cloud/bigtable/rows_mutator.rb +14 -17
  39. data/lib/google/cloud/bigtable/rows_reader.rb +18 -14
  40. data/lib/google/cloud/bigtable/sample_row_key.rb +5 -2
  41. data/lib/google/cloud/bigtable/service.rb +161 -242
  42. data/lib/google/cloud/bigtable/status.rb +76 -0
  43. data/lib/google/cloud/bigtable/table.rb +141 -236
  44. data/lib/google/cloud/bigtable/table/cluster_state.rb +7 -1
  45. data/lib/google/cloud/bigtable/table/list.rb +14 -7
  46. data/lib/google/cloud/bigtable/value_range.rb +5 -0
  47. data/lib/google/cloud/bigtable/version.rb +1 -1
  48. metadata +27 -25
  49. data/lib/google/cloud/bigtable/table/column_family_map.rb +0 -70
@@ -18,6 +18,7 @@
18
18
  module Google
19
19
  module Cloud
20
20
  module Bigtable
21
+ ##
21
22
  # # ColumnRange
22
23
  #
23
24
  # Specifies a contiguous range of column qualifiers.
@@ -49,14 +50,16 @@ module Google
49
50
  # table.new_column_range("cf").between("user-001", "user-100")
50
51
  #
51
52
  class ColumnRange
53
+ ##
52
54
  # Create qualifier range instance.
53
55
  #
54
56
  # @param family [String] Column family name.
55
57
  #
56
58
  def initialize family
57
- @grpc = Google::Bigtable::V2::ColumnRange.new(family_name: family)
59
+ @grpc = Google::Bigtable::V2::ColumnRange.new family_name: family
58
60
  end
59
61
 
62
+ ##
60
63
  # Get column family name
61
64
  #
62
65
  # @return [String]
@@ -65,6 +68,7 @@ module Google
65
68
  @grpc.family_name
66
69
  end
67
70
 
71
+ ##
68
72
  # Set column family name
69
73
  #
70
74
  # @param name [String] Column family name
@@ -73,6 +77,7 @@ module Google
73
77
  @grpc.family_name = name
74
78
  end
75
79
 
80
+ ##
76
81
  # Set column range with the lower bound.
77
82
  #
78
83
  # @param qualifier [String] Column qualifier name. Required
@@ -105,6 +110,7 @@ module Google
105
110
  self
106
111
  end
107
112
 
113
+ ##
108
114
  # Set column range with the upper bound.
109
115
  #
110
116
  # @param qualifier [String] Column qualifier name. Required.
@@ -137,6 +143,7 @@ module Google
137
143
  self
138
144
  end
139
145
 
146
+ ##
140
147
  # Set column range with the inclusive upper and lower bound.
141
148
  #
142
149
  # @param from_qualifier [String] Inclusive from qualifier. Required.
@@ -155,6 +162,7 @@ module Google
155
162
  from(from_qualifier).to(to_qualifier, inclusive: true)
156
163
  end
157
164
 
165
+ ##
158
166
  # Set column range with the inclusive upper and the exclusive lower bound.
159
167
  #
160
168
  # @param from_qualifier [String] Inclusive from qualifier
@@ -26,48 +26,56 @@ module Google
26
26
  module Convert
27
27
  module_function
28
28
 
29
+ ##
29
30
  # Convert number to protobuf duration.
30
31
  #
31
32
  # @param number [Float] Seconds with nano seconds
32
33
  # @return [Google::Protobuf::Duration, nil]
34
+ #
33
35
  def number_to_duration number
34
36
  return unless number
35
37
 
36
38
  Google::Protobuf::Duration.new(
37
39
  seconds: number.to_i,
38
- nanos: (number.remainder(1) * 1000000000).round
40
+ nanos: (number.remainder(1) * 1_000_000_000).round
39
41
  )
40
42
  end
41
43
 
44
+ ##
42
45
  # Convert protobuf durations to float.
43
46
  #
44
47
  # @param duration [Google::Protobuf::Duration, nil]
45
48
  # @return [Float, Integer, nil] Seconds with nano seconds
49
+ #
46
50
  def duration_to_number duration
47
51
  return unless duration
48
52
  return duration.seconds if duration.nanos.zero?
49
53
 
50
- duration.seconds + (duration.nanos / 1000000000.0)
54
+ duration.seconds + (duration.nanos / 1_000_000_000.0)
51
55
  end
52
56
 
57
+ ##
53
58
  # Convert protobuf timestamp to Time object.
54
59
  #
55
60
  # @param timestamp [Google::Protobuf::Timestamp]
56
61
  # @return [Time, nil]
62
+ #
57
63
  def timestamp_to_time timestamp
58
64
  return unless timestamp
59
65
 
60
- Time.at(timestamp.seconds, timestamp.nanos / 1000.0)
66
+ Time.at timestamp.seconds, timestamp.nanos / 1000.0
61
67
  end
62
68
 
69
+ ##
63
70
  # Convert time to timestamp protobuf object.
64
71
  #
65
72
  # @param time [Time]
66
73
  # @return [Google::Protobuf::Timestamp, nil]
74
+ #
67
75
  def time_to_timestamp time
68
76
  return unless time
69
77
 
70
- Google::Protobuf::Timestamp.new(seconds: time.to_i, nanos: time.nsec)
78
+ Google::Protobuf::Timestamp.new seconds: time.to_i, nanos: time.nsec
71
79
  end
72
80
  end
73
81
  end
@@ -16,17 +16,20 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Bigtable
19
+ ##
19
20
  # Invalid read row state error
20
21
  class InvalidRowStateError < Google::Cloud::Error
22
+ ##
21
23
  # Invalid row chunk data
22
24
  attr_reader :data
23
25
 
24
26
  def initialize message, data = nil
25
- super(message)
27
+ super message
26
28
  @data = data if data
27
29
  end
28
30
  end
29
31
 
32
+ ##
30
33
  # Row filter error.
31
34
  class RowFilterError < Google::Cloud::Error
32
35
  end
@@ -18,51 +18,49 @@
18
18
  module Google
19
19
  module Cloud
20
20
  module Bigtable
21
+ ##
21
22
  # # GcRule
22
23
  #
23
- # Rule for determining which cells to delete during garbage collection.
24
+ # A rule or rules for determining which cells to delete during garbage
25
+ # collection.
26
+ #
24
27
  # Garbage collection (GC) executes opportunistically in the background,
25
- # so it's possible for reads to return a cell even if it matches the active
26
- # GC expression for its family.
28
+ # so it is possible for reads to return a cell even if it matches the
29
+ # active GC expression for its column family.
27
30
  #
28
- # NOTE: GC Rule can hold only one type at a time.
29
31
  # GC Rule types:
30
- # * `max_num_versions` - Delete all cells in a column except the most recent N
31
- # * `max_age` - Delete cells in a column older than the given age.
32
- # * `union` - Delete cells that would be deleted by every nested rule.
33
- # It can have mutiple chainable GC Rules.
34
- # * `intersection` - Delete cells that would be deleted by any nested rule.
35
- # It can have multiple chainable GC Rules.
36
- #
37
- # @example Create GC rule instance with max version.
38
- #
39
- # gc_rule = Google::Cloud::Bigtable::GcRule.max_versions(3)
40
- #
41
- # # Change max verions
42
- # gc_rule.max_versions = 5
43
- #
44
- # @example Create GC rule instance with max age.
45
- #
46
- # gc_rule = Google::Cloud::Bigtable::GcRule.max_age(3)
32
+ # * `max_num_versions` - A garbage-collection rule that explicitly
33
+ # states the maximum number of cells to keep for all columns in a
34
+ # column family.
35
+ # * `max_age` - A garbage-collection rule based on the timestamp for
36
+ # each cell. With this type of garbage-collection rule, you set the
37
+ # time to live (TTL) for data. Cloud Bigtable looks at each column
38
+ # family during garbage collection and removes any cells that have
39
+ # expired.
40
+ # * `union` - A union garbage-collection policy will remove all data
41
+ # matching *any* of a set of given rules.
42
+ # * `intersection` - An intersection garbage-collection policy will
43
+ # remove all data matching *all* of a set of given rules.
47
44
  #
48
- # # Change max age
49
- # gc_rule.max_age = 600 # 10 minutes
45
+ # @example Create a table with column families.
46
+ # require "google/cloud/bigtable"
50
47
  #
51
- # @example Create GC rule instance with union.
48
+ # bigtable = Google::Cloud::Bigtable.new
52
49
  #
53
- # max_age_gc_rule = Google::Cloud::Bigtable::GcRule.max_age(180)
54
- # union_gc_rule = Google::Cloud::Bigtable::GcRule.union(max_age_gc_rule)
50
+ # table = bigtable.create_table("my-instance", "my-table") do |cfm|
51
+ # cfm.add("cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5))
52
+ # cfm.add("cf2", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600))
55
53
  #
56
- # # Change union GC rule
57
- # gc_rule.union = Google::Cloud::Bigtable::GcRule.max_age(600)
54
+ # gc_rule = Google::Cloud::Bigtable::GcRule.union(
55
+ # Google::Cloud::Bigtable::GcRule.max_age(1800),
56
+ # Google::Cloud::Bigtable::GcRule.max_versions(3)
57
+ # )
58
+ # cfm.add("cf3", gc_rule: gc_rule)
59
+ # end
58
60
  #
59
- # @example Create GC rule instance with intersection.
60
- #
61
- # max_versions_gc_rule = Google::Cloud::Bigtable::GcRule.max_versions(3)
62
- # gc_rule = Google::Cloud::Bigtable::GcRule.intersection(max_versions_gc_rule)
63
- #
64
- # # Change intersection GC rule
65
- # gc_rule.intersection = Google::Cloud::Bigtable::GcRule.max_age(600)
61
+ # puts table.column_families["cf1"].gc_rule.max_versions
62
+ # puts table.column_families["cf2"].gc_rule.max_age
63
+ # puts table.column_families["cf3"].gc_rule.union
66
64
  #
67
65
  class GcRule
68
66
  # @private
@@ -74,7 +72,9 @@ module Google
74
72
  @grpc = grpc || Google::Bigtable::Admin::V2::GcRule.new
75
73
  end
76
74
 
77
- # Delete all cells in a column except the most recent N.
75
+ ##
76
+ # Sets a garbage-collection rule that explicitly states the maximum
77
+ # number of cells to keep for all columns in a column family.
78
78
  #
79
79
  # @param versions [Integer]
80
80
  #
@@ -82,75 +82,156 @@ module Google
82
82
  @grpc.max_num_versions = versions
83
83
  end
84
84
 
85
- # Get max versions.
85
+ ##
86
+ # Gets the garbage-collection rule that explicitly states the maximum
87
+ # number of cells to keep for all columns in a column family.
86
88
  #
87
89
  # @return [Integer, nil]
88
90
  #
91
+ # @example
92
+ # require "google/cloud/bigtable"
93
+ #
94
+ # bigtable = Google::Cloud::Bigtable.new
95
+ #
96
+ # table = bigtable.create_table("my-instance", "my-table") do |cfm|
97
+ # cfm.add("cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5))
98
+ # end
99
+ #
100
+ # puts table.column_families["cf1"].gc_rule.max_versions
101
+ #
89
102
  def max_versions
90
103
  @grpc.max_num_versions
91
104
  end
92
105
 
93
- # Delete cells in a column older than the given age.
94
- # Values must be at least one millisecond, and will be truncated to
95
- # microsecond granularity.
106
+ ##
107
+ # Sets a garbage-collection rule based on the timestamp for each cell.
108
+ # With this type of garbage-collection rule, you set the time to live
109
+ # (TTL) for data. Cloud Bigtable looks at each column family during
110
+ # garbage collection and removes any cells that have expired.
96
111
  #
97
- # @param age [Integer] age in seconds
112
+ # @param age [Numeric] Max age in seconds. Values must be at least one
113
+ # millisecond, and will be truncated to microsecond granularity.
98
114
  #
99
115
  def max_age= age
100
- @grpc.max_age = Convert.number_to_duration(age)
116
+ @grpc.max_age = Convert.number_to_duration age
101
117
  end
102
118
 
103
- # Max age in seconds, if max age is set.
119
+ ##
120
+ # Gets the garbage-collection rule based on the timestamp for each cell.
121
+ # With this type of garbage-collection rule, you set the time to live
122
+ # (TTL) for data. Cloud Bigtable looks at each column family during
123
+ # garbage collection and removes any cells that have expired.
104
124
  #
105
- # @return [Integer, nil] Max age in seconds.
125
+ # @return [Numeric, nil] Max age in seconds.
126
+ #
127
+ # @example
128
+ # require "google/cloud/bigtable"
129
+ #
130
+ # bigtable = Google::Cloud::Bigtable.new
131
+ #
132
+ # table = bigtable.create_table("my-instance", "my-table") do |cfm|
133
+ # cfm.add("cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600))
134
+ # end
135
+ #
136
+ # puts table.column_families["cf1"].gc_rule.max_age
106
137
  #
107
138
  def max_age
108
- @grpc.max_age.seconds if @grpc.max_age
139
+ Convert.duration_to_number @grpc.max_age
109
140
  end
110
141
 
111
- # Delete cells that would be deleted by every nested rule.
142
+ ##
143
+ # Sets the intersection rules collection for this GcRule.
112
144
  #
113
145
  # @param rules [Array<Google::Cloud::Bigtable::GcRule>]
114
146
  # List of GcRule with nested rules.
115
147
  #
116
148
  def intersection= rules
117
- @grpc.intersection = \
118
- Google::Bigtable::Admin::V2::GcRule::Intersection.new(
119
- rules: rules.map(&:to_grpc)
120
- )
149
+ @grpc.intersection = Google::Bigtable::Admin::V2::GcRule::Intersection.new rules: rules.map(&:to_grpc)
121
150
  end
122
151
 
123
- # Get intersection GC rules
152
+ ##
153
+ #
154
+ # Gets the intersection rules collection for this GcRule.
155
+ #
156
+ # @return [Array<Google::Cloud::Bigtable::GcRule>, nil]
124
157
  #
125
- # @return [Google::Bigtable::Admin::V2::GcRule::Intersection, nil]
158
+ # @example
159
+ # require "google/cloud/bigtable"
160
+ #
161
+ # bigtable = Google::Cloud::Bigtable.new
162
+ #
163
+ # table = bigtable.create_table("my-instance", "my-table") do |cfm|
164
+ # gc_rule = Google::Cloud::Bigtable::GcRule.intersection(
165
+ # Google::Cloud::Bigtable::GcRule.max_age(1800),
166
+ # Google::Cloud::Bigtable::GcRule.max_versions(3)
167
+ # )
168
+ # cfm.add("cf1", gc_rule: gc_rule)
169
+ # end
170
+ #
171
+ # puts table.column_families["cf1"].gc_rule.intersection
126
172
  #
127
173
  def intersection
128
- @grpc.intersection
174
+ return nil unless @grpc.intersection
175
+ @grpc.intersection.rules.map do |gc_rule_grpc|
176
+ self.class.from_grpc gc_rule_grpc
177
+ end
129
178
  end
130
179
 
131
- # Delete cells that would be deleted by any nested rule.
180
+ ##
181
+ # Sets the union rules collection for this GcRule. A union
182
+ # garbage-collection policy will remove all data matching *any* of its
183
+ # set of given rules.
132
184
  #
133
185
  # @param rules [Array<Google::Cloud::Bigtable::GcRule>]
134
186
  # List of GcRule with nested rules.
135
187
  #
136
188
  def union= rules
137
- @grpc.union = Google::Bigtable::Admin::V2::GcRule::Union.new(
138
- rules: rules.map(&:to_grpc)
139
- )
189
+ @grpc.union = Google::Bigtable::Admin::V2::GcRule::Union.new rules: rules.map(&:to_grpc)
140
190
  end
141
191
 
142
- # Get union GC rules
192
+ ##
193
+ # Gets the union rules collection for this GcRule. A union
194
+ # garbage-collection policy will remove all data matching *any* of its
195
+ # set of given rules.
196
+ #
197
+ # @return [Array<Google::Cloud::Bigtable::GcRule>, nil]
198
+ #
199
+ # @example
200
+ # require "google/cloud/bigtable"
143
201
  #
144
- # @return [Google::Bigtable::Admin::V2::GcRule::Union, nil]
202
+ # bigtable = Google::Cloud::Bigtable.new
203
+ #
204
+ # table = bigtable.create_table("my-instance", "my-table") do |cfm|
205
+ # gc_rule = Google::Cloud::Bigtable::GcRule.union(
206
+ # Google::Cloud::Bigtable::GcRule.max_age(1800),
207
+ # Google::Cloud::Bigtable::GcRule.max_versions(3)
208
+ # )
209
+ # cfm.add("cf1", gc_rule: gc_rule)
210
+ # end
211
+ #
212
+ # puts table.column_families["cf1"].gc_rule.union
145
213
  #
146
214
  def union
147
- @grpc.union
215
+ return nil unless @grpc.union
216
+ @grpc.union.rules.map do |gc_rule_grpc|
217
+ self.class.from_grpc gc_rule_grpc
218
+ end
148
219
  end
149
220
 
221
+ ##
150
222
  # Create GcRule instance with max number of versions.
151
223
  #
152
224
  # @param versions [Integer] Max number of versions
153
- # @return [Google::Bigtable::Admin::V2::GcRule]
225
+ # @return [Google::Cloud::Bigtable::GcRule]
226
+ #
227
+ # @example Create a table with column families.
228
+ # require "google/cloud/bigtable"
229
+ #
230
+ # bigtable = Google::Cloud::Bigtable.new
231
+ #
232
+ # table = bigtable.create_table("my-instance", "my-table") do |cfm|
233
+ # cfm.add("cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5))
234
+ # end
154
235
  #
155
236
  def self.max_versions versions
156
237
  new.tap do |gc_rule|
@@ -158,10 +239,20 @@ module Google
158
239
  end
159
240
  end
160
241
 
242
+ ##
161
243
  # Create GcRule instance with max age.
162
244
  #
163
245
  # @param age [Integer] Max age in seconds.
164
- # @return [Google::Bigtable::Admin::V2::GcRule]
246
+ # @return [Google::Cloud::Bigtable::GcRule]
247
+ #
248
+ # @example Create a table with column families.
249
+ # require "google/cloud/bigtable"
250
+ #
251
+ # bigtable = Google::Cloud::Bigtable.new
252
+ #
253
+ # table = bigtable.create_table("my-instance", "my-table") do |cfm|
254
+ # cfm.add("cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600))
255
+ # end
165
256
  #
166
257
  def self.max_age age
167
258
  new.tap do |gc_rule|
@@ -169,11 +260,25 @@ module Google
169
260
  end
170
261
  end
171
262
 
263
+ ##
172
264
  # Create union GcRule instance.
173
265
  #
174
266
  # @param rules [Google::Cloud::Bigtable::GcRule, Array<Google::Cloud::Bigtable::GcRule>]
175
267
  # List of GcRule with nested rules.
176
- # @return [Google::Bigtable::Admin::V2::GcRule]
268
+ # @return [Google::Cloud::Bigtable::GcRule]
269
+ #
270
+ # @example Create a table with column families.
271
+ # require "google/cloud/bigtable"
272
+ #
273
+ # bigtable = Google::Cloud::Bigtable.new
274
+ #
275
+ # table = bigtable.create_table("my-instance", "my-table") do |cfm|
276
+ # gc_rule = Google::Cloud::Bigtable::GcRule.union(
277
+ # Google::Cloud::Bigtable::GcRule.max_age(1800),
278
+ # Google::Cloud::Bigtable::GcRule.max_versions(3)
279
+ # )
280
+ # cfm.add("cf1", gc_rule: gc_rule)
281
+ # end
177
282
  #
178
283
  def self.union *rules
179
284
  new.tap do |gc_rule|
@@ -181,11 +286,25 @@ module Google
181
286
  end
182
287
  end
183
288
 
289
+ ##
184
290
  # Create intersection GCRule instance.
185
291
  #
186
292
  # @param rules [Google::Cloud::Bigtable::GcRule, Array<Google::Cloud::Bigtable::GcRule>]
187
293
  # List of GcRule with nested rules.
188
- # @return [Google::Bigtable::Admin::V2::GcRule]
294
+ # @return [Google::Cloud::Bigtable::GcRule]
295
+ #
296
+ # @example Create a table with column families.
297
+ # require "google/cloud/bigtable"
298
+ #
299
+ # bigtable = Google::Cloud::Bigtable.new
300
+ #
301
+ # table = bigtable.create_table("my-instance", "my-table") do |cfm|
302
+ # gc_rule = Google::Cloud::Bigtable::GcRule.intersection(
303
+ # Google::Cloud::Bigtable::GcRule.max_age(1800),
304
+ # Google::Cloud::Bigtable::GcRule.max_versions(3)
305
+ # )
306
+ # cfm.add("cf1", gc_rule: gc_rule)
307
+ # end
189
308
  #
190
309
  def self.intersection *rules
191
310
  new.tap do |gc_rule|
@@ -207,7 +326,7 @@ module Google
207
326
  # @param grpc [Google::Bigtable::Admin::V2::GcRule]
208
327
  # @return [Google::Cloud::Bigtable::GcRule]
209
328
  def self.from_grpc grpc
210
- new(grpc)
329
+ new grpc
211
330
  end
212
331
  end
213
332
  end