google-cloud-bigtable 2.1.0 → 2.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +38 -0
  3. data/CONTRIBUTING.md +2 -2
  4. data/LOGGING.md +1 -1
  5. data/OVERVIEW.md +4 -4
  6. data/lib/google/cloud/bigtable/app_profile/list.rb +2 -2
  7. data/lib/google/cloud/bigtable/backup.rb +121 -0
  8. data/lib/google/cloud/bigtable/backup/list.rb +2 -2
  9. data/lib/google/cloud/bigtable/chunk_processor.rb +4 -3
  10. data/lib/google/cloud/bigtable/cluster/list.rb +2 -2
  11. data/lib/google/cloud/bigtable/column_family.rb +4 -0
  12. data/lib/google/cloud/bigtable/column_family_map.rb +2 -0
  13. data/lib/google/cloud/bigtable/convert.rb +12 -0
  14. data/lib/google/cloud/bigtable/gc_rule.rb +2 -0
  15. data/lib/google/cloud/bigtable/instance.rb +3 -2
  16. data/lib/google/cloud/bigtable/instance/list.rb +2 -2
  17. data/lib/google/cloud/bigtable/mutation_entry.rb +12 -9
  18. data/lib/google/cloud/bigtable/mutation_operations.rb +6 -5
  19. data/lib/google/cloud/bigtable/policy.rb +2 -1
  20. data/lib/google/cloud/bigtable/project.rb +4 -3
  21. data/lib/google/cloud/bigtable/routing_policy.rb +3 -1
  22. data/lib/google/cloud/bigtable/row.rb +5 -1
  23. data/lib/google/cloud/bigtable/row_filter/simple_filter.rb +6 -1
  24. data/lib/google/cloud/bigtable/rows_reader.rb +6 -6
  25. data/lib/google/cloud/bigtable/service.rb +41 -0
  26. data/lib/google/cloud/bigtable/status.rb +4 -1
  27. data/lib/google/cloud/bigtable/table.rb +32 -12
  28. data/lib/google/cloud/bigtable/table/list.rb +2 -2
  29. data/lib/google/cloud/bigtable/table/restore_job.rb +1 -1
  30. data/lib/google/cloud/bigtable/value_range.rb +24 -6
  31. data/lib/google/cloud/bigtable/version.rb +1 -1
  32. metadata +6 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a096cf8d1c1d26e38753da0ac165bdec3491bd821ce49da374b35362d5dc32a2
4
- data.tar.gz: b7c9b2b6832514c1861f8cd9c6af2e73b1c4c7c2fa1ce3354ff7dd125c769dea
3
+ metadata.gz: 1d2ceaa917a67e31cae160f8cfb03ecb1617aebf24c634d89a3f5805589d3f46
4
+ data.tar.gz: c2c614ffbd788256c15037c22ff9f7fd09208399a49ee85149e9515e0976f0f9
5
5
  SHA512:
6
- metadata.gz: b40689f9ab7ef728fa6e156e2cd3c2aa8dbaa0e23adb957501ec2b016fc1dff0235485c2c95f2a9d2398bee9a070455fc36f55f2fcdd5cc4ebabb971c3155e66
7
- data.tar.gz: 33383bc875ced164d0f32e230653c03b2786ffaa00f024145bfb3ee1e067412e60eedb28814a2571d904e1c3706bea34c3cbc9129b7063c7259050ccd38eb2bb
6
+ metadata.gz: 6e019a7ad97017938d2960b52951dda90911d5f84c6d3c95cd09abd0086d35b68f8f4139d5626c92065928eec8493758aa0fb6d6185cf89a149eadde53c54675
7
+ data.tar.gz: f3eeec0098bd030dad2a8cd07b08dae4d58d02753ead572d552eaf7543a93776ca48576bb7c37199a7cd181f6f23e98f989778a0f7ee8e9e614522f97fbf23e8
data/CHANGELOG.md CHANGED
@@ -1,5 +1,43 @@
1
1
  # Release History
2
2
 
3
+ ### 2.4.1 / 2021-04-01
4
+
5
+ #### Bug Fixes
6
+
7
+ * Update internal management of view states in Table
8
+
9
+ ### 2.4.0 / 2021-03-10
10
+
11
+ #### Features
12
+
13
+ * Drop support for Ruby 2.4 and add support for Ruby 3.0
14
+
15
+ #### Documentation
16
+
17
+ * Add link to Garbage collection docs
18
+
19
+ ### 2.3.0 / 2021-02-04
20
+
21
+ #### Features
22
+
23
+ * Add integer support to RowFilter#value and ValueRange
24
+ * Encode Integer arguments as 64-bit signed big-endian integer data
25
+
26
+ ### 2.2.1 / 2021-01-13
27
+
28
+ #### Documentation
29
+
30
+ * Use consistent column family and field names in samples
31
+
32
+ ### 2.2.0 / 2020-11-11
33
+
34
+ #### Features
35
+
36
+ * Add Backup-level IAM Policy support
37
+ * Add Backup#policy
38
+ * Add Backup#update_policy
39
+ * Add Backup#test_iam_permissions
40
+
3
41
  ### 2.1.0 / 2020-09-17
4
42
 
5
43
  #### Features
data/CONTRIBUTING.md CHANGED
@@ -24,7 +24,7 @@ be able to accept your pull requests.
24
24
  In order to use the google-cloud-bigtable console and run the project's tests,
25
25
  there is a small amount of setup:
26
26
 
27
- 1. Install Ruby. google-cloud-bigtable requires Ruby 2.4+. You may choose to
27
+ 1. Install Ruby. google-cloud-bigtable requires Ruby 2.5+. You may choose to
28
28
  manage your Ruby and gem installations with [RVM](https://rvm.io/),
29
29
  [rbenv](https://github.com/rbenv/rbenv), or
30
30
  [chruby](https://github.com/postmodern/chruby).
@@ -45,7 +45,7 @@ there is a small amount of setup:
45
45
 
46
46
  ```sh
47
47
  $ cd google-cloud-bigtable/
48
- $ bundle exec rake bundleupdate
48
+ $ bundle install
49
49
  ```
50
50
 
51
51
  ## Console
data/LOGGING.md CHANGED
@@ -3,7 +3,7 @@
3
3
  To enable logging for this library, set the logger for the underlying
4
4
  [gRPC](https://github.com/grpc/grpc/tree/master/src/ruby) library. The logger
5
5
  that you set may be a Ruby stdlib
6
- [`Logger`](https://ruby-doc.org/stdlib-2.5.0/libdoc/logger/rdoc/Logger.html) as
6
+ [`Logger`](https://ruby-doc.org/stdlib/libdoc/logger/rdoc/Logger.html) as
7
7
  shown below, or a
8
8
  [`Google::Cloud::Logging::Logger`](https://googleapis.dev/ruby/google-cloud-logging/latest)
9
9
  that will write logs to [Stackdriver
data/OVERVIEW.md CHANGED
@@ -194,8 +194,8 @@ table = bigtable.table("my-instance", "my-table")
194
194
 
195
195
  entry = table.new_mutation_entry("user-1")
196
196
  entry.set_cell(
197
- "cf-1",
198
- "field-1",
197
+ "cf1",
198
+ "field1",
199
199
  "XYZ",
200
200
  timestamp: (Time.now.to_f * 1000000).round(-3) # microseconds
201
201
  ).delete_cells("cf2", "field02")
@@ -245,8 +245,8 @@ table = bigtable.table("my-instance", "my-table")
245
245
  predicate_filter = Google::Cloud::Bigtable::RowFilter.key("user-10")
246
246
  on_match_mutations = Google::Cloud::Bigtable::MutationEntry.new
247
247
  on_match_mutations.set_cell(
248
- "cf-1",
249
- "field-1",
248
+ "cf1",
249
+ "field1",
250
250
  "XYZ",
251
251
  timestamp: (Time.now.to_f * 1000000).round(-3) # microseconds
252
252
  ).delete_cells("cf2", "field02")
@@ -122,12 +122,12 @@ module Google
122
122
  # app_profile.name
123
123
  # end
124
124
  #
125
- def all
125
+ def all &block
126
126
  return enum_for :all unless block_given?
127
127
 
128
128
  results = self
129
129
  loop do
130
- results.each { |r| yield r }
130
+ results.each(&block)
131
131
  break unless next?
132
132
  grpc.next_page
133
133
  results = self.class.from_grpc grpc, service
@@ -18,6 +18,7 @@
18
18
  require "google/cloud/bigtable/backup/job"
19
19
  require "google/cloud/bigtable/backup/list"
20
20
  require "google/cloud/bigtable/convert"
21
+ require "google/cloud/bigtable/policy"
21
22
  require "google/cloud/bigtable/table/restore_job"
22
23
 
23
24
 
@@ -206,6 +207,126 @@ module Google
206
207
  state == :READY
207
208
  end
208
209
 
210
+ ##
211
+ # Gets the [Cloud IAM](https://cloud.google.com/iam/) access control
212
+ # policy for the backup.
213
+ #
214
+ # @see https://cloud.google.com/bigtable/docs/access-control
215
+ #
216
+ # @yield [policy] A block for updating the policy. The latest policy
217
+ # will be read from the Bigtable service and passed to the block. After
218
+ # the block completes, the modified policy will be written to the
219
+ # service.
220
+ # @yieldparam [Policy] policy the current Cloud IAM Policy for this
221
+ # backup.
222
+ #
223
+ # @return [Policy] The current Cloud IAM Policy for the backup.
224
+ #
225
+ # @example
226
+ # require "google/cloud/bigtable"
227
+ #
228
+ # bigtable = Google::Cloud::Bigtable.new
229
+ # instance = bigtable.instance("my-instance")
230
+ # cluster = instance.cluster("my-cluster")
231
+ #
232
+ # backup = cluster.backup("my-backup")
233
+ #
234
+ # policy = backup.policy
235
+ #
236
+ # @example Update the policy by passing a block.
237
+ # require "google/cloud/bigtable"
238
+ #
239
+ # bigtable = Google::Cloud::Bigtable.new
240
+ # instance = bigtable.instance("my-instance")
241
+ # cluster = instance.cluster("my-cluster")
242
+ #
243
+ # backup = cluster.backup("my-backup")
244
+ #
245
+ # backup.policy do |p|
246
+ # p.add("roles/owner", "user:owner@example.com")
247
+ # end # 2 API calls
248
+ #
249
+ def policy
250
+ ensure_service!
251
+ grpc = service.get_backup_policy instance_id, cluster_id, backup_id
252
+ policy = Policy.from_grpc grpc
253
+ return policy unless block_given?
254
+ yield policy
255
+ update_policy policy
256
+ end
257
+
258
+ ##
259
+ # Updates the [Cloud IAM](https://cloud.google.com/iam/) access control
260
+ # policy for the backup. The policy should be read from {#policy}.
261
+ # See {Google::Cloud::Bigtable::Policy} for an explanation of the policy
262
+ # `etag` property and how to modify policies.
263
+ #
264
+ # You can also update the policy by passing a block to {#policy}, which
265
+ # will call this method internally after the block completes.
266
+ #
267
+ # @param new_policy [Policy] a new or modified Cloud IAM Policy for this
268
+ # backup
269
+ #
270
+ # @return [Policy] The policy returned by the API update operation.
271
+ #
272
+ # @example
273
+ # require "google/cloud/bigtable"
274
+ #
275
+ # bigtable = Google::Cloud::Bigtable.new
276
+ # instance = bigtable.instance("my-instance")
277
+ # cluster = instance.cluster("my-cluster")
278
+ #
279
+ # backup = cluster.backup("my-backup")
280
+ #
281
+ # policy = backup.policy
282
+ # policy.add("roles/owner", "user:owner@example.com")
283
+ # updated_policy = backup.update_policy(policy)
284
+ #
285
+ # puts updated_policy.roles
286
+ #
287
+ def update_policy new_policy
288
+ ensure_service!
289
+ grpc = service.set_backup_policy instance_id, cluster_id, backup_id, new_policy.to_grpc
290
+ Policy.from_grpc grpc
291
+ end
292
+ alias policy= update_policy
293
+
294
+ ##
295
+ # Tests the specified permissions against the [Cloud
296
+ # IAM](https://cloud.google.com/iam/) access control policy.
297
+ #
298
+ # @see https://cloud.google.com/iam/docs/managing-policies Managing Policies
299
+ # @see https://cloud.google.com/bigtable/docs/access-control Access Control
300
+ #
301
+ # @param permissions [String, Array<String>] permissions The set of permissions to
302
+ # check access for. Permissions with wildcards (such as `*` or `bigtable.*`) are
303
+ # not allowed.
304
+ # See [Access Control](https://cloud.google.com/bigtable/docs/access-control).
305
+ #
306
+ # @return [Array<String>] The permissions that are configured for the policy.
307
+ #
308
+ # @example
309
+ # require "google/cloud/bigtable"
310
+ #
311
+ # bigtable = Google::Cloud::Bigtable.new
312
+ # instance = bigtable.instance("my-instance")
313
+ # cluster = instance.cluster("my-cluster")
314
+ #
315
+ # backup = cluster.backup("my-backup")
316
+ #
317
+ # permissions = backup.test_iam_permissions(
318
+ # "bigtable.backups.delete",
319
+ # "bigtable.backups.get"
320
+ # )
321
+ # permissions.include? "bigtable.backups.delete" #=> false
322
+ # permissions.include? "bigtable.backups.get" #=> true
323
+ #
324
+ def test_iam_permissions *permissions
325
+ ensure_service!
326
+ grpc = service.test_backup_permissions instance_id, cluster_id, backup_id, permissions.flatten
327
+ grpc.permissions.to_a
328
+ end
329
+
209
330
  ##
210
331
  # Creates a new table by restoring from a completed backup.
211
332
  #
@@ -124,12 +124,12 @@ module Google
124
124
  # backup.backup_id
125
125
  # end
126
126
  #
127
- def all
127
+ def all &block
128
128
  return enum_for :all unless block_given?
129
129
 
130
130
  results = self
131
131
  loop do
132
- results.each { |r| yield r }
132
+ results.each(&block)
133
133
  break unless next?
134
134
  grpc.next_page
135
135
  results = self.class.from_grpc grpc, service
@@ -57,11 +57,12 @@ module Google
57
57
 
58
58
  raise_if chunk.value_size.positive?, "Commit rows cannot have a non-zero value_size." if chunk.commit_row
59
59
 
60
- if state == NEW_ROW
60
+ case state
61
+ when NEW_ROW
61
62
  process_new_row
62
- elsif state == CELL_IN_PROGRESS
63
+ when CELL_IN_PROGRESS
63
64
  process_cell_in_progress
64
- elsif state == ROW_IN_PROGRESS
65
+ when ROW_IN_PROGRESS
65
66
  process_row_in_progress
66
67
  end
67
68
  end
@@ -129,12 +129,12 @@ module Google
129
129
  # puts cluster.cluster_id
130
130
  # end
131
131
  #
132
- def all
132
+ def all &block
133
133
  return enum_for :all unless block_given?
134
134
 
135
135
  results = self
136
136
  loop do
137
- results.each { |r| yield r }
137
+ results.each(&block)
138
138
  break unless results.next?
139
139
  results = results.next
140
140
  end
@@ -45,7 +45,11 @@ module Google
45
45
  ##
46
46
  # The garbage collection rule to be used for the column family.
47
47
  # Optional. The service default value will be used when not specified.
48
+ #
49
+ # @see https://cloud.google.com/bigtable/docs/garbage-collection Garbage collection
50
+ #
48
51
  # @return [Google::Cloud::Bigtable::GcRule, nil]
52
+ #
49
53
  attr_accessor :gc_rule
50
54
 
51
55
  # @private
@@ -222,6 +222,8 @@ module Google
222
222
  ##
223
223
  # Updates an existing column family in the table.
224
224
  #
225
+ # @see https://cloud.google.com/bigtable/docs/garbage-collection Garbage collection
226
+ #
225
227
  # @param name [String] Column family name.
226
228
  # @param gc_rule [Google::Cloud::Bigtable::GcRule] The new garbage
227
229
  # collection rule to be used for the column family. Optional. The
@@ -77,6 +77,18 @@ module Google
77
77
 
78
78
  Google::Protobuf::Timestamp.new seconds: time.to_i, nanos: time.nsec
79
79
  end
80
+
81
+ ##
82
+ # Converts an Integer to 64-bit signed big-endian integer data.
83
+ # Returns a string argument unchanged.
84
+ #
85
+ # @param value [String, Integer]
86
+ # @return [String]
87
+ #
88
+ def integer_to_signed_be_64 value
89
+ return [value].pack "q>" if value.is_a? Integer
90
+ value
91
+ end
80
92
  end
81
93
  end
82
94
  end
@@ -28,6 +28,8 @@ module Google
28
28
  # so it is possible for reads to return a cell even if it matches the
29
29
  # active GC expression for its column family.
30
30
  #
31
+ # @see https://cloud.google.com/bigtable/docs/garbage-collection Garbage collection
32
+ #
31
33
  # GC Rule types:
32
34
  # * `max_num_versions` - A garbage-collection rule that explicitly
33
35
  # states the maximum number of cells to keep for all columns in a
@@ -509,8 +509,8 @@ module Google
509
509
  #
510
510
  # entry = table.new_mutation_entry("user-1")
511
511
  # entry.set_cell(
512
- # "cf-1",
513
- # "field-1",
512
+ # "cf1",
513
+ # "field1",
514
514
  # "XYZ",
515
515
  # timestamp: (Time.now.to_f * 1000000).round(-3) # microseconds
516
516
  # ).delete_cells("cf2", "field02")
@@ -520,6 +520,7 @@ module Google
520
520
  def table table_id, view: nil, perform_lookup: nil, app_profile_id: nil
521
521
  ensure_service!
522
522
 
523
+ view ||= :SCHEMA_VIEW
523
524
  table = if perform_lookup
524
525
  grpc = service.get_table instance_id, table_id, view: view
525
526
  Table.from_grpc grpc, service, view: view
@@ -126,12 +126,12 @@ module Google
126
126
  # puts instance.instance_id
127
127
  # end
128
128
  #
129
- def all
129
+ def all &block
130
130
  return enum_for :all unless block_given?
131
131
 
132
132
  results = self
133
133
  loop do
134
- results.each { |r| yield r }
134
+ results.each(&block)
135
135
  break unless results.next?
136
136
  results = results.next
137
137
  end
@@ -15,6 +15,8 @@
15
15
  # limitations under the License.
16
16
 
17
17
 
18
+ require "google/cloud/bigtable/convert"
19
+
18
20
  module Google
19
21
  module Cloud
20
22
  module Bigtable
@@ -84,8 +86,9 @@ module Google
84
86
  # @param qualifier [String] Column qualifier name.
85
87
  # The qualifier of the column into which new data should be written.
86
88
  # Can be any byte string, including an empty string.
87
- # @param value [String, Integer] Cell value data.
88
- # The value to be written into the specified cell.
89
+ # @param value [String, Integer] Cell value data. The value to be written
90
+ # into the specified cell. If the argument is an Integer, it will be
91
+ # encoded as a 64-bit signed big-endian integer.
89
92
  # @param timestamp [Integer] Timestamp value in microseconds.
90
93
  # The timestamp of the cell into which new data should be written.
91
94
  # Use -1 for current Bigtable server time.
@@ -104,15 +107,15 @@ module Google
104
107
  # @example With timestamp.
105
108
  # entry = Google::Cloud::Bigtable::MutationEntry.new("user-1")
106
109
  # entry.set_cell(
107
- # "cf-1",
108
- # "field-1",
110
+ # "cf1",
111
+ # "field1",
109
112
  # "XYZ",
110
113
  # timestamp: (Time.now.to_f * 1000000).round(-3) # microseconds
111
114
  # )
112
115
  #
113
116
  def set_cell family, qualifier, value, timestamp: nil
114
117
  # If value is integer, covert it to a 64-bit signed big-endian integer.
115
- value = [value].pack "q>" if value.is_a? Integer
118
+ value = Convert.integer_to_signed_be_64 value
116
119
  options = {
117
120
  family_name: family,
118
121
  column_qualifier: qualifier,
@@ -156,14 +159,14 @@ module Google
156
159
  #
157
160
  # @example Without timestamp range.
158
161
  # entry = Google::Cloud::Bigtable::MutationEntry.new("user-1")
159
- # entry.delete_cells("cf-1", "field-1")
162
+ # entry.delete_cells("cf1", "field1")
160
163
  #
161
164
  # @example With timestamp range.
162
165
  # entry = Google::Cloud::Bigtable::MutationEntry.new("user-1")
163
166
  # timestamp_micros = (Time.now.to_f * 1000000).round(-3)
164
167
  # entry.delete_cells(
165
168
  # "cf1",
166
- # "field-1",
169
+ # "field1",
167
170
  # timestamp_from: timestamp_micros - 5000000,
168
171
  # timestamp_to: timestamp_micros
169
172
  # )
@@ -172,7 +175,7 @@ module Google
172
175
  # timestamp_micros = (Time.now.to_f * 1000000).round(-3)
173
176
  # entry.delete_cells(
174
177
  # "cf1",
175
- # "field-1",
178
+ # "field1",
176
179
  # timestamp_from: timestamp_micros - 5000000
177
180
  # )
178
181
  #
@@ -201,7 +204,7 @@ module Google
201
204
  #
202
205
  # @example
203
206
  # entry = Google::Cloud::Bigtable::MutationEntry.new("user-1")
204
- # entry.delete_from_family("cf-1")
207
+ # entry.delete_from_family("cf1")
205
208
  #
206
209
  def delete_from_family family
207
210
  @mutations << Google::Cloud::Bigtable::V2::Mutation.new(delete_from_family: { family_name: family })
@@ -65,8 +65,8 @@ module Google
65
65
  #
66
66
  # entry = table.new_mutation_entry("user-1")
67
67
  # entry.set_cell(
68
- # "cf-1",
69
- # "field-1",
68
+ # "cf1",
69
+ # "field1",
70
70
  # "XYZ",
71
71
  # timestamp: (Time.now.to_f * 1000000).round(-3) # microseconds
72
72
  # ).delete_cells("cf2", "field02")
@@ -219,8 +219,8 @@ module Google
219
219
  # predicate_filter = Google::Cloud::Bigtable::RowFilter.key("user-10")
220
220
  # on_match_mutations = Google::Cloud::Bigtable::MutationEntry.new
221
221
  # on_match_mutations.set_cell(
222
- # "cf-1",
223
- # "field-1",
222
+ # "cf1",
223
+ # "field1",
224
224
  # "XYZ",
225
225
  # timestamp: (Time.now.to_f * 1000000).round(-3) # microseconds
226
226
  # ).delete_cells("cf2", "field02")
@@ -335,7 +335,8 @@ module Google
335
335
  # end
336
336
  #
337
337
  class Response
338
- attr_reader :index, :status
338
+ attr_reader :index
339
+ attr_reader :status
339
340
 
340
341
  ##
341
342
  # @private Creates a MutationEntry::Response object.
@@ -54,7 +54,8 @@ module Google
54
54
  # policy.roles["roles/viewer"] = ["allUsers"]
55
55
  #
56
56
  class Policy
57
- attr_reader :etag, :roles
57
+ attr_reader :etag
58
+ attr_reader :roles
58
59
 
59
60
  # Creates a Policy instance.
60
61
  # @param etag [String]
@@ -316,18 +316,18 @@ module Google
316
316
  #
317
317
  # table = bigtable.table("my-instance", "my-table")
318
318
  #
319
- # @example Get a table with schema-only view.
319
+ # @example Retrieve a table with a schema-only view.
320
320
  # require "google/cloud/bigtable"
321
321
  #
322
322
  # bigtable = Google::Cloud::Bigtable.new
323
323
  #
324
- # table = bigtable.table("my-instance", "my-table", perform_lookup: true, view: :SCHEMA_VIEW)
324
+ # table = bigtable.table("my-instance", "my-table", perform_lookup: true)
325
325
  # if table
326
326
  # puts table.name
327
327
  # puts table.column_families
328
328
  # end
329
329
  #
330
- # @example Get a table with all fields, cluster states, and column families.
330
+ # @example Retrieve a table with all fields, cluster states, and column families.
331
331
  # require "google/cloud/bigtable"
332
332
  #
333
333
  # bigtable = Google::Cloud::Bigtable.new
@@ -342,6 +342,7 @@ module Google
342
342
  def table instance_id, table_id, view: nil, perform_lookup: nil, app_profile_id: nil
343
343
  ensure_service!
344
344
 
345
+ view ||= :SCHEMA_VIEW
345
346
  table = if perform_lookup
346
347
  grpc = service.get_table instance_id, table_id, view: view
347
348
  Table.from_grpc grpc, service, view: view
@@ -141,7 +141,8 @@ module Google
141
141
  # Default value is false.
142
142
  #
143
143
  class SingleClusterRouting < RoutingPolicy
144
- attr_reader :cluster_id, :allow_transactional_writes
144
+ attr_reader :cluster_id
145
+ attr_reader :allow_transactional_writes
145
146
 
146
147
  ##
147
148
  # Creates a new single-cluster routing policy.
@@ -155,6 +156,7 @@ module Google
155
156
  # Default value is false.
156
157
  #
157
158
  def initialize cluster_id, allow_transactional_writes
159
+ super()
158
160
  @cluster_id = cluster_id
159
161
  @allow_transactional_writes = allow_transactional_writes
160
162
  end
@@ -30,7 +30,11 @@ module Google
30
30
  # Row cell built from data chunks.
31
31
  #
32
32
  class Cell
33
- attr_reader :family, :qualifier, :value, :labels, :timestamp
33
+ attr_reader :family
34
+ attr_reader :qualifier
35
+ attr_reader :value
36
+ attr_reader :labels
37
+ attr_reader :timestamp
34
38
 
35
39
  ##
36
40
  # Creates a row cell instance.
@@ -15,6 +15,8 @@
15
15
  # limitations under the License.
16
16
 
17
17
 
18
+ require "google/cloud/bigtable/convert"
19
+
18
20
  module Google
19
21
  module Cloud
20
22
  module Bigtable
@@ -147,10 +149,13 @@ module Google
147
149
  # will not match the new line character `\n`, which may be present in a
148
150
  # binary value.
149
151
  #
150
- # @param regex [String] Regex to match cell value.
152
+ # @param regex [String, Integer] Regex to match cell value, or an Integer
153
+ # value to be encoded as a 64-bit signed big-endian integer.
151
154
  # @return [Google::Cloud::Bigtable::RowFilter::SimpleFilter]
152
155
  #
153
156
  def value regex
157
+ # If regex is integer, covert it to a 64-bit signed big-endian integer.
158
+ regex = Convert.integer_to_signed_be_64 regex
154
159
  @grpc.value_regex_filter = regex
155
160
  self
156
161
  end
@@ -170,10 +170,10 @@ module Google
170
170
  # @return [Boolean]
171
171
  #
172
172
  def start_key_read? range
173
- start_key = if !range.start_key_closed.empty?
174
- range.start_key_closed
175
- else
173
+ start_key = if range.start_key_closed.empty?
176
174
  range.start_key_open
175
+ else
176
+ range.start_key_closed
177
177
  end
178
178
 
179
179
  start_key.empty? || last_key >= start_key
@@ -186,10 +186,10 @@ module Google
186
186
  # @return [Boolean]
187
187
  #
188
188
  def end_key_read? range
189
- end_key = if !range.end_key_closed.empty?
190
- range.end_key_closed
191
- else
189
+ end_key = if range.end_key_closed.empty?
192
190
  range.end_key_open
191
+ else
192
+ range.end_key_closed
193
193
  end
194
194
 
195
195
  end_key && end_key <= last_key
@@ -515,6 +515,47 @@ module Google
515
515
  ignore_warnings: ignore_warnings
516
516
  end
517
517
 
518
+ ##
519
+ # Gets the access control policy for an backup resource. Returns an empty
520
+ # policy if an backup exists but does not have a policy set.
521
+ #
522
+ # @return [Google::Iam::V1::Policy]
523
+ #
524
+ def get_backup_policy instance_id, cluster_id, backup_id
525
+ tables.get_iam_policy resource: backup_path(instance_id, cluster_id, backup_id)
526
+ end
527
+
528
+ ##
529
+ # Sets the access control policy on an backup resource. Replaces any
530
+ # existing policy.
531
+ #
532
+ # @param policy [Google::Iam::V1::Policy | Hash]
533
+ # REQUIRED: The complete policy to be applied to the +resource+. The size of
534
+ # the policy is limited to a few 10s of KB. An empty policy is valid
535
+ # for Cloud Bigtable, but certain Cloud Platform services (such as Projects)
536
+ # might reject an empty policy.
537
+ # Alternatively, provide a hash similar to `Google::Iam::V1::Policy`.
538
+ # @return [Google::Iam::V1::Policy]
539
+ #
540
+ def set_backup_policy instance_id, cluster_id, backup_id, policy
541
+ tables.set_iam_policy resource: backup_path(instance_id, cluster_id, backup_id), policy: policy
542
+ end
543
+
544
+ ##
545
+ # Returns permissions that the caller has for the specified backup resource.
546
+ #
547
+ # @param permissions [Array<String>]
548
+ # The set of permissions to check for the +resource+. Permissions with
549
+ # wildcards (such as '*' or 'storage.*') are not allowed. For more
550
+ # information see
551
+ # [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions).
552
+ # @return [Google::Iam::V1::TestIamPermissionsResponse]
553
+ #
554
+ def test_backup_permissions instance_id, cluster_id, backup_id, permissions
555
+ tables.test_iam_permissions resource: backup_path(instance_id, cluster_id, backup_id),
556
+ permissions: permissions
557
+ end
558
+
518
559
  ##
519
560
  # Gets the access control policy for an instance resource. Returns an empty
520
561
  # policy if an instance exists but does not have a policy set.
@@ -47,7 +47,10 @@ module Google
47
47
  # end
48
48
  #
49
49
  class Status
50
- attr_reader :code, :description, :message, :details
50
+ attr_reader :code
51
+ attr_reader :description
52
+ attr_reader :message
53
+ attr_reader :details
51
54
 
52
55
  ##
53
56
  # @private Creates a Status object.
@@ -56,6 +56,14 @@ module Google
56
56
  # The gRPC Service object.
57
57
  attr_accessor :service
58
58
 
59
+ # @private
60
+ # The current gRPC resource, for testing only.
61
+ attr_accessor :grpc
62
+
63
+ # @private
64
+ # The current loaded_views, for testing only. See #check_view_and_load, below.
65
+ attr_reader :loaded_views
66
+
59
67
  ##
60
68
  # @return [String] App profile ID for request routing.
61
69
  #
@@ -64,10 +72,11 @@ module Google
64
72
  # @private
65
73
  #
66
74
  # Creates a new Table instance.
67
- def initialize grpc, service, view: nil
75
+ def initialize grpc, service, view:
68
76
  @grpc = grpc
69
77
  @service = service
70
- @view = view || :SCHEMA_VIEW
78
+ raise ArgumentError, "view must not be nil" if view.nil?
79
+ @loaded_views = Set[view]
71
80
  end
72
81
 
73
82
  ##
@@ -109,7 +118,8 @@ module Google
109
118
  end
110
119
 
111
120
  ##
112
- # Reloads table data.
121
+ # Reloads table data with the provided `view`, or with `SCHEMA_VIEW`
122
+ # if none is provided. Previously loaded data is not retained.
113
123
  #
114
124
  # @param view [Symbol] Table view type.
115
125
  # Default view type is `:SCHEMA_VIEW`.
@@ -123,8 +133,9 @@ module Google
123
133
  # @return [Google::Cloud::Bigtable::Table]
124
134
  #
125
135
  def reload! view: nil
126
- @view = view || :SCHEMA_VIEW
136
+ view ||= :SCHEMA_VIEW
127
137
  @grpc = service.get_table instance_id, name, view: view
138
+ @loaded_views = Set[view]
128
139
  self
129
140
  end
130
141
 
@@ -133,7 +144,10 @@ module Google
133
144
  # If it could not be determined whether or not the table has data in a
134
145
  # particular cluster (for example, if its zone is unavailable), then
135
146
  # there will be an entry for the cluster with UNKNOWN `replication_status`.
136
- # Views: `FULL`.
147
+ #
148
+ # Reloads the table if necessary to retrieve the cluster states data,
149
+ # since it is only available in a table with view type `REPLICATION_VIEW`
150
+ # or `FULL`. Previously loaded data is retained.
137
151
  #
138
152
  # @return [Array<Google::Cloud::Bigtable::Table::ClusterState>]
139
153
  #
@@ -146,15 +160,19 @@ module Google
146
160
 
147
161
  ##
148
162
  # Returns a frozen object containing the column families configured for
149
- # the table, mapped by column family name. Reloads the table if
150
- # necessary to retrieve the column families data, since it is only
151
- # available in a table with view type `SCHEMA_VIEW` or `FULL`.
163
+ # the table, mapped by column family name.
164
+ #
165
+ # Reloads the table if necessary to retrieve the column families data,
166
+ # since it is only available in a table with view type `SCHEMA_VIEW`
167
+ # or `FULL`. Previously loaded data is retained.
152
168
  #
153
169
  # Also accepts a block for making modifications to the table's column
154
170
  # families. After the modifications are completed, the table will be
155
171
  # updated with the changes, and the updated column families will be
156
172
  # returned.
157
173
  #
174
+ # @see https://cloud.google.com/bigtable/docs/garbage-collection Garbage collection
175
+ #
158
176
  # @yield [column_families] A block for modifying the table's column
159
177
  # families. Applies multiple column modifications. Performs a series
160
178
  # of column family modifications on the specified table. Either all or
@@ -222,7 +240,10 @@ module Google
222
240
  # The granularity (e.g. `MILLIS`, `MICROS`) at which timestamps are stored in
223
241
  # this table. Timestamps not matching the granularity will be rejected.
224
242
  # If unspecified at creation time, the value will be set to `MILLIS`.
225
- # Views: `SCHEMA_VIEW`, `FULL`.
243
+ #
244
+ # Reloads the table if necessary to retrieve the column families data,
245
+ # since it is only available in a table with view type `SCHEMA_VIEW`
246
+ # or `FULL`. Previously loaded data is retained.
226
247
  #
227
248
  # @return [Symbol]
228
249
  #
@@ -437,7 +458,7 @@ module Google
437
458
  }.delete_if { |_, v| v.nil? })
438
459
 
439
460
  grpc = service.create_table instance_id, table_id, table, initial_splits: initial_splits
440
- from_grpc grpc, service
461
+ from_grpc grpc, service, view: :SCHEMA_VIEW
441
462
  end
442
463
 
443
464
  ##
@@ -623,7 +644,7 @@ module Google
623
644
  # @param view [Symbol] View type.
624
645
  # @return [Google::Cloud::Bigtable::Table]
625
646
  #
626
- def self.from_grpc grpc, service, view: nil
647
+ def self.from_grpc grpc, service, view:
627
648
  new grpc, service, view: view
628
649
  end
629
650
 
@@ -664,7 +685,6 @@ module Google
664
685
  #
665
686
  def check_view_and_load view
666
687
  ensure_service!
667
- @loaded_views ||= Set.new [@view]
668
688
 
669
689
  return if @loaded_views.include?(view) || @loaded_views.include?(:FULL)
670
690
 
@@ -114,12 +114,12 @@ module Google
114
114
  # puts table.table_id
115
115
  # end
116
116
  #
117
- def all
117
+ def all &block
118
118
  return enum_for :all unless block_given?
119
119
 
120
120
  results = self
121
121
  loop do
122
- results.each { |r| yield r }
122
+ results.each(&block)
123
123
  break unless next?
124
124
  grpc.next_page
125
125
  results = self.class.from_grpc grpc, service
@@ -108,7 +108,7 @@ module Google
108
108
  # end
109
109
  #
110
110
  def table
111
- Table.from_grpc results, service if results
111
+ Table.from_grpc results, service, view: :NAME_ONLY if results
112
112
  end
113
113
  end
114
114
  end
@@ -15,6 +15,8 @@
15
15
  # limitations under the License.
16
16
 
17
17
 
18
+ require "google/cloud/bigtable/convert"
19
+
18
20
  module Google
19
21
  module Cloud
20
22
  module Bigtable
@@ -65,7 +67,9 @@ module Google
65
67
  ##
66
68
  # Sets the row range with the lower bound.
67
69
  #
68
- # @param value [String] The value. Required.
70
+ # @param value [String, Integer] The value. Required. If the argument
71
+ # is an Integer, it will be encoded as a 64-bit signed big-endian
72
+ # integer.
69
73
  # @param inclusive [Boolean] Whether the value is an inclusive or
70
74
  # exclusive lower bound. Default is `true`, an inclusive lower bound.
71
75
  # @return [Google::Cloud::Bigtable::ValueRange]
@@ -87,6 +91,8 @@ module Google
87
91
  # range = table.new_value_range.from("value-001", inclusive: false)
88
92
  #
89
93
  def from value, inclusive: true
94
+ # If value is integer, covert it to a 64-bit signed big-endian integer.
95
+ value = Convert.integer_to_signed_be_64 value
90
96
  if inclusive
91
97
  @grpc.start_value_closed = value
92
98
  else
@@ -98,7 +104,9 @@ module Google
98
104
  ##
99
105
  # Sets the value range with upper bound.
100
106
  #
101
- # @param value [String] value. Required
107
+ # @param value [String, Integer] value. Required. If the argument
108
+ # is an Integer, it will be encoded as a 64-bit signed big-endian
109
+ # integer.
102
110
  # @param inclusive [Boolean] Whether the value is an inclusive or
103
111
  # exclusive lower bound. Default is `false`, an exclusive lower bound.
104
112
  # @return [Google::Cloud::Bigtable::ValueRange]
@@ -120,6 +128,8 @@ module Google
120
128
  # range = table.new_value_range.to("value-010")
121
129
  #
122
130
  def to value, inclusive: false
131
+ # If value is integer, covert it to a 64-bit signed big-endian integer.
132
+ value = Convert.integer_to_signed_be_64 value
123
133
  if inclusive
124
134
  @grpc.end_value_closed = value
125
135
  else
@@ -131,8 +141,12 @@ module Google
131
141
  ##
132
142
  # Sets the value range with inclusive lower and upper bounds.
133
143
  #
134
- # @param from_value [String] Inclusive from value. Required
135
- # @param to_value [String] Inclusive to value. Required
144
+ # @param from_value [String, Integer] Inclusive from value. Required.
145
+ # If the argument is an Integer, it will be encoded as a 64-bit
146
+ # signed big-endian integer.
147
+ # @param to_value [String, Integer] Inclusive to value. Required.
148
+ # If the argument is an Integer, it will be encoded as a 64-bit
149
+ # signed big-endian integer.
136
150
  # @return [Google::Cloud::Bigtable::ValueRange]
137
151
  # Range with inclusive from and to values.
138
152
  #
@@ -151,8 +165,12 @@ module Google
151
165
  ##
152
166
  # Set value range with an inclusive lower bound and an exclusive upper bound.
153
167
  #
154
- # @param from_value [String] Inclusive from value
155
- # @param to_value [String] Exclusive to value
168
+ # @param from_value [String, Integer] Inclusive from value. Required.
169
+ # If the argument is an Integer, it will be encoded as a 64-bit
170
+ # signed big-endian integer.
171
+ # @param to_value [String, Integer] Exclusive to value. Required.
172
+ # If the argument is an Integer, it will be encoded as a 64-bit
173
+ # signed big-endian integer.
156
174
  # @return [Google::Cloud::Bigtable::ValueRange]
157
175
  # Range with an inclusive from value and an exclusive to value.
158
176
  #
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Bigtable
19
- VERSION = "2.1.0".freeze
19
+ VERSION = "2.4.1".freeze
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-bigtable
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Google LLC
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-17 00:00:00.000000000 Z
11
+ date: 2021-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-cloud-bigtable-admin-v2
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 1.24.0
61
+ version: 1.25.1
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: 1.24.0
68
+ version: 1.25.1
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: minitest
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -241,14 +241,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
241
241
  requirements:
242
242
  - - ">="
243
243
  - !ruby/object:Gem::Version
244
- version: '2.4'
244
+ version: '2.5'
245
245
  required_rubygems_version: !ruby/object:Gem::Requirement
246
246
  requirements:
247
247
  - - ">="
248
248
  - !ruby/object:Gem::Version
249
249
  version: '0'
250
250
  requirements: []
251
- rubygems_version: 3.1.4
251
+ rubygems_version: 3.2.13
252
252
  signing_key:
253
253
  specification_version: 4
254
254
  summary: API Client library for Cloud Bigtable API