google-cloud-bigtable 0.6.2 → 0.7.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 (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
@@ -16,6 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Bigtable
19
+ ##
19
20
  # # Policy
20
21
  #
21
22
  # Represents a Cloud IAM Policy for Bigtable instance resources.
@@ -63,6 +64,7 @@ module Google
63
64
  @roles = roles
64
65
  end
65
66
 
67
+ ##
66
68
  # Convenience method for adding a member to a binding on this policy.
67
69
  # See [Understanding
68
70
  # Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
@@ -88,6 +90,7 @@ module Google
88
90
  role(role_name) << member
89
91
  end
90
92
 
93
+ ##
91
94
  # Convenience method for removing a member from a binding on this
92
95
  # policy. See [Understanding
93
96
  # Roles](https://cloud.google.com/iam/docs/understanding-roles) for a
@@ -101,7 +104,7 @@ module Google
101
104
  # `"user:owner@example.com"`.
102
105
  #
103
106
  # @example
104
- # require "google/cloud/Bigtable"
107
+ # require "google/cloud/bigtable"
105
108
  #
106
109
  # bigtable = Google::Cloud::Bigtable.new
107
110
  # instance = bigtable.instance "my-instance"
@@ -113,6 +116,7 @@ module Google
113
116
  role(role_name).delete member
114
117
  end
115
118
 
119
+ ##
116
120
  # Convenience method returning the array of members bound to a role in
117
121
  # this policy. Returns an empty array if no value is present for the role in
118
122
  # {#roles}. See [Understanding
@@ -124,7 +128,7 @@ module Google
124
128
  # @return [Array<String>] The members strings, or an empty array.
125
129
  #
126
130
  # @example
127
- # require "google/cloud/Bigtable"
131
+ # require "google/cloud/bigtable"
128
132
  #
129
133
  # bigtable = Google::Cloud::Bigtable.new
130
134
  # instance = bigtable.instance "my-instance"
@@ -142,11 +146,11 @@ module Google
142
146
  bindings = roles.keys.map do |role_name|
143
147
  next if roles[role_name].empty?
144
148
  Google::Iam::V1::Binding.new(
145
- role: role_name,
149
+ role: role_name,
146
150
  members: roles[role_name]
147
151
  )
148
152
  end
149
- Google::Iam::V1::Policy.new(etag: etag, bindings: bindings)
153
+ Google::Iam::V1::Policy.new etag: etag, bindings: bindings
150
154
  end
151
155
 
152
156
  # @private
@@ -155,7 +159,7 @@ module Google
155
159
  roles = grpc.bindings.each_with_object({}) do |binding, memo|
156
160
  memo[binding.role] = binding.members.to_a
157
161
  end
158
- new(grpc.etag, roles)
162
+ new grpc.etag, roles
159
163
  end
160
164
  end
161
165
  end
@@ -26,6 +26,7 @@ require "google/cloud/bigtable/table"
26
26
  module Google
27
27
  module Cloud
28
28
  module Bigtable
29
+ ##
29
30
  # # Project
30
31
  #
31
32
  # Projects are top-level containers in Google Cloud Platform. They store
@@ -42,7 +43,7 @@ module Google
42
43
  # {Google::Cloud#bigtable}.
43
44
  #
44
45
  # @example Obtaining an instance and the clusters from a project.
45
- # require "google/cloud"
46
+ # require "google/cloud/bigtable"
46
47
  #
47
48
  # bigtable = Google::Cloud::Bigtable.new
48
49
  #
@@ -62,12 +63,13 @@ module Google
62
63
  @service = service
63
64
  end
64
65
 
66
+ ##
65
67
  # The identifier for the Cloud Bigtable project.
66
68
  #
67
69
  # @return [String] Project ID.
68
70
  #
69
71
  # @example
70
- # require "google/cloud"
72
+ # require "google/cloud/bigtable"
71
73
  #
72
74
  # bigtable = Google::Cloud::Bigtable.new(
73
75
  # project_id: "my-project",
@@ -75,12 +77,13 @@ module Google
75
77
  # )
76
78
  #
77
79
  # bigtable.project_id #=> "my-project"
78
-
80
+ #
79
81
  def project_id
80
82
  ensure_service!
81
83
  service.project_id
82
84
  end
83
85
 
86
+ ##
84
87
  # Retrieves the list of Bigtable instances for the project.
85
88
  #
86
89
  # @param token [String] The `token` value returned by the last call to
@@ -98,13 +101,14 @@ module Google
98
101
  # instances.all do |instance|
99
102
  # puts instance.instance_id
100
103
  # end
101
-
104
+ #
102
105
  def instances token: nil
103
106
  ensure_service!
104
- grpc = service.list_instances(token: token)
105
- Instance::List.from_grpc(grpc, service)
107
+ grpc = service.list_instances token: token
108
+ Instance::List.from_grpc grpc, service
106
109
  end
107
110
 
111
+ ##
108
112
  # Get an existing Bigtable instance.
109
113
  #
110
114
  # @param instance_id [String] Existing instance id.
@@ -120,15 +124,16 @@ module Google
120
124
  # if instance
121
125
  # puts instance.instance_id
122
126
  # end
123
-
127
+ #
124
128
  def instance instance_id
125
129
  ensure_service!
126
- grpc = service.get_instance(instance_id)
127
- Instance.from_grpc(grpc, service)
130
+ grpc = service.get_instance instance_id
131
+ Instance.from_grpc grpc, service
128
132
  rescue Google::Cloud::NotFoundError
129
133
  nil
130
134
  end
131
135
 
136
+ ##
132
137
  # Create a Bigtable instance.
133
138
  #
134
139
  # @see https://cloud.google.com/compute/docs/regions-zones Cluster zone locations
@@ -186,7 +191,7 @@ module Google
186
191
  # job.done? #=> false
187
192
  #
188
193
  # # Reload job until completion.
189
- # job.wait_until_done
194
+ # job.wait_until_done!
190
195
  # job.done? #=> true
191
196
  #
192
197
  # if job.error?
@@ -211,7 +216,7 @@ module Google
211
216
  # job.done? #=> false
212
217
  #
213
218
  # # To block until the operation completes.
214
- # job.wait_until_done
219
+ # job.wait_until_done!
215
220
  # job.done? #=> true
216
221
  #
217
222
  # if job.error?
@@ -219,38 +224,24 @@ module Google
219
224
  # else
220
225
  # instance = job.instance
221
226
  # end
222
-
223
- def create_instance \
224
- instance_id,
225
- display_name: nil,
226
- type: nil,
227
- labels: nil,
228
- clusters: nil
227
+ #
228
+ def create_instance instance_id, display_name: nil, type: nil, labels: nil, clusters: nil
229
229
  labels = Hash[labels.map { |k, v| [String(k), String(v)] }] if labels
230
230
 
231
- instance_attrs = {
232
- display_name: display_name,
233
- type: type,
234
- labels: labels
235
- }.delete_if { |_, v| v.nil? }
236
- instance = Google::Bigtable::Admin::V2::Instance.new(instance_attrs)
231
+ instance_attrs = { display_name: display_name, type: type, labels: labels }.delete_if { |_, v| v.nil? }
232
+ instance = Google::Bigtable::Admin::V2::Instance.new instance_attrs
237
233
  clusters ||= Instance::ClusterMap.new
238
234
  yield clusters if block_given?
239
235
 
240
236
  clusters.each_value do |cluster|
241
- unless cluster.location == "".freeze
242
- cluster.location = service.location_path(cluster.location)
243
- end
237
+ cluster.location = service.location_path cluster.location unless cluster.location == ""
244
238
  end
245
239
 
246
- grpc = service.create_instance(
247
- instance_id,
248
- instance,
249
- clusters.to_h
250
- )
251
- Instance::Job.from_grpc(grpc, service)
240
+ grpc = service.create_instance instance_id, instance, clusters.to_h
241
+ Instance::Job.from_grpc grpc, service
252
242
  end
253
243
 
244
+ ##
254
245
  # List all clusters in project.
255
246
  #
256
247
  # @param token [String] The `token` value returned by the last call to
@@ -267,13 +258,14 @@ module Google
267
258
  # puts cluster.cluster_id
268
259
  # puts cluster.ready?
269
260
  # end
270
-
261
+ #
271
262
  def clusters token: nil
272
263
  ensure_service!
273
- grpc = service.list_clusters("-", token: token)
274
- Cluster::List.from_grpc(grpc, service, instance_id: "-")
264
+ grpc = service.list_clusters "-", token: token
265
+ Cluster::List.from_grpc grpc, service, instance_id: "-"
275
266
  end
276
267
 
268
+ ##
277
269
  # List all tables for given instance.
278
270
  #
279
271
  # @param instance_id [String] Existing instance Id.
@@ -289,16 +281,16 @@ module Google
289
281
  # puts table.name
290
282
  # puts table.column_families
291
283
  # end
292
-
284
+ #
293
285
  def tables instance_id
294
286
  ensure_service!
295
- grpc = service.list_tables(instance_id)
296
- Table::List.from_grpc(grpc, service)
287
+ grpc = service.list_tables instance_id
288
+ Table::List.from_grpc grpc, service
297
289
  end
298
290
 
291
+ ##
299
292
  # Get table information.
300
293
  #
301
- #
302
294
  # @param instance_id [String] Existing instance Id.
303
295
  # @param table_id [String] Existing table Id.
304
296
  # @param view [Symbol] Optional. Table view type. Default `:SCHEMA_VIEW`
@@ -325,8 +317,8 @@ module Google
325
317
  #
326
318
  # table = bigtable.table("my-instance", "my-table", perform_lookup: true, view: :SCHEMA_VIEW)
327
319
  # if table
328
- # p table.name
329
- # p table.column_families
320
+ # puts table.name
321
+ # puts table.column_families
330
322
  # end
331
323
  #
332
324
  # @example Get table object without calling get table admin api.
@@ -344,8 +336,8 @@ module Google
344
336
  # table = bigtable.table("my-instance", "my-table", view: :FULL, perform_lookup: true)
345
337
  # if table
346
338
  # puts table.name
347
- # p table.column_families
348
- # p table.cluster_states
339
+ # puts table.column_families
340
+ # puts table.cluster_states
349
341
  # end
350
342
  #
351
343
  # @example Mutate rows
@@ -374,23 +366,15 @@ module Google
374
366
  # table.read_rows(limit: 5).each do |row|
375
367
  # p row
376
368
  # end
377
-
378
- def table \
379
- instance_id,
380
- table_id,
381
- view: nil,
382
- perform_lookup: nil,
383
- app_profile_id: nil
369
+ #
370
+ def table instance_id, table_id, view: nil, perform_lookup: nil, app_profile_id: nil
384
371
  ensure_service!
385
372
 
386
373
  table = if perform_lookup
387
- grpc = service.get_table(instance_id, table_id, view: view)
388
- Table.from_grpc(grpc, service, view: view)
374
+ grpc = service.get_table instance_id, table_id, view: view
375
+ Table.from_grpc grpc, service, view: view
389
376
  else
390
- Table.from_path(
391
- service.table_path(instance_id, table_id),
392
- service
393
- )
377
+ Table.from_path service.table_path(instance_id, table_id), service
394
378
  end
395
379
 
396
380
  table.app_profile_id = app_profile_id
@@ -399,6 +383,7 @@ module Google
399
383
  nil
400
384
  end
401
385
 
386
+ ##
402
387
  # Creates a new table in the specified instance.
403
388
  # The table can be created with a full set of initial column families,
404
389
  # specified in the request.
@@ -408,9 +393,9 @@ module Google
408
393
  # @param table_id [String]
409
394
  # The ID by which the new table should be referred to within the
410
395
  # instance, e.g., `foobar`.
411
- # @param column_families [Hash{String => Google::Cloud::Bigtable::ColumnFamily}]
412
- # (See {Google::Cloud::Bigtable::Table::ColumnFamilyMap})
413
- # If unspecified, you may use a code block to add column families.
396
+ # @param column_families [Google::Cloud::Bigtable::ColumnFamilyMap]
397
+ # An object containing the column families for the table, mapped by
398
+ # column family name.
414
399
  # @param granularity [Symbol]
415
400
  # The granularity at which timestamps are stored in this table.
416
401
  # Timestamps not matching the granularity will be rejected.
@@ -434,15 +419,14 @@ module Google
434
419
  # * Tablet 5 : `[other, ) => {"other", "zz"}`
435
420
  # A hash in the form of `Google::Bigtable::Admin::V2::CreateTableRequest::Split`
436
421
  # can also be provided.
437
- # @yield [column_families] A block for adding column_families.
438
- # @yieldparam [Hash{String => Google::Cloud::Bigtable::ColumnFamily}]
439
- # Map of family name and column family object.
440
- # (See {Google::Cloud::Bigtable::Instance::ColumnFamilyMap})
441
- # (Read the GC Rules for column families at {Google::Cloud::Bigtable::GcRule})
422
+ # @yield [column_families] A block for adding column families.
423
+ # @yieldparam [Google::Cloud::Bigtable::ColumnFamilyMap] column_families
424
+ # A mutable object containing the column families for the table,
425
+ # mapped by column family name.
442
426
  #
443
427
  # @return [Google::Cloud::Bigtable::Table]
444
428
  #
445
- # @example Create a table without a column family
429
+ # @example Create a table without column families.
446
430
  # require "google/cloud/bigtable"
447
431
  #
448
432
  # bigtable = Google::Cloud::Bigtable.new
@@ -450,44 +434,39 @@ module Google
450
434
  # table = bigtable.create_table("my-instance", "my-table")
451
435
  # puts table.name
452
436
  #
453
- # @example Create table with column families and initial splits.
437
+ # @example Create a table with initial splits and column families.
454
438
  # require "google/cloud/bigtable"
455
439
  #
456
440
  # bigtable = Google::Cloud::Bigtable.new
457
441
  #
458
442
  # initial_splits = ["user-00001", "user-100000", "others"]
459
- # table = bigtable.create_table("my-instance", "my-table", initial_splits: initial_splits) do |column_families|
460
- # column_families.add('cf1', Google::Cloud::Bigtable::GcRule.max_versions(5))
461
- # column_families.add('cf2', Google::Cloud::Bigtable::GcRule.max_age(600))
443
+ # table = bigtable.create_table("my-instance", "my-table", initial_splits: initial_splits) do |cfm|
444
+ # cfm.add('cf1', gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5))
445
+ # cfm.add('cf2', gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600))
462
446
  #
463
447
  # gc_rule = Google::Cloud::Bigtable::GcRule.union(
464
448
  # Google::Cloud::Bigtable::GcRule.max_age(1800),
465
449
  # Google::Cloud::Bigtable::GcRule.max_versions(3)
466
450
  # )
467
- # column_families.add('cf3', gc_rule)
451
+ # cfm.add('cf3', gc_rule: gc_rule)
468
452
  # end
469
453
  #
470
- # p table
471
-
472
- def create_table \
473
- instance_id,
474
- table_id,
475
- column_families: nil,
476
- granularity: nil,
477
- initial_splits: nil,
478
- &block
454
+ # puts table
455
+ #
456
+ def create_table instance_id, table_id, column_families: nil, granularity: nil, initial_splits: nil, &block
479
457
  ensure_service!
480
458
  Table.create(
481
459
  service,
482
460
  instance_id,
483
461
  table_id,
484
462
  column_families: column_families,
485
- granularity: granularity,
486
- initial_splits: initial_splits,
463
+ granularity: granularity,
464
+ initial_splits: initial_splits,
487
465
  &block
488
466
  )
489
467
  end
490
468
 
469
+ ##
491
470
  # Permanently deletes a specified table and all of its data.
492
471
  #
493
472
  # @param instance_id [String]
@@ -504,67 +483,10 @@ module Google
504
483
  # bigtable.delete_table("my-instance", "my-table")
505
484
  #
506
485
  def delete_table instance_id, table_id
507
- service.delete_table(instance_id, table_id)
486
+ service.delete_table instance_id, table_id
508
487
  true
509
488
  end
510
489
 
511
- # Performs a series of column family modifications on the specified table.
512
- # Either all or none of the modifications will occur before this method
513
- # returns, but data requests received prior to that point may see a table
514
- # where only some modifications have taken effect.
515
- #
516
- # @param instance_id [String]
517
- # The unique ID of the instance the table is in.
518
- # @param table_id [String]
519
- # The unique Id of the table whose families should be modified.
520
- # @param modifications [Array<Google::Bigtable::Admin::V2::ModifyColumnFamiliesRequest::Modification> | Google::Bigtable::Admin::V2::ModifyColumnFamiliesRequest::Modification]
521
- # Modifications to be atomically applied to the specified table's families.
522
- # Entries are applied in order, meaning that earlier modifications can be
523
- # masked by later ones (in the case of repeated updates to the same family,
524
- # for example).
525
- # @return [Google::Cloud::Bigtable::Table] Table with updated column families.
526
- #
527
- # @example
528
- # require "google/cloud/bigtable"
529
- #
530
- # bigtable = Google::Cloud::Bigtable.new
531
- #
532
- # modifications = []
533
- # modifications << Google::Cloud::Bigtable::ColumnFamily.create_modification(
534
- # "cf1", Google::Cloud::Bigtable::GcRule.max_age(600))
535
- # )
536
- #
537
- # modifications << Google::Cloud::Bigtable::ColumnFamily.update_modification(
538
- # "cf2", Google::Cloud::Bigtable::GcRule.max_versions(5)
539
- # )
540
- #
541
- # gc_rule_1 = Google::Cloud::Bigtable::GcRule.max_versions(3)
542
- # gc_rule_2 = Google::Cloud::Bigtable::GcRule.max_age(600)
543
- # modifications << Google::Cloud::Bigtable::ColumnFamily.update_modification(
544
- # "cf3", Google::Cloud::Bigtable::GcRule.union(gc_rule_1, gc_rule_2)
545
- # )
546
- #
547
- # max_age_gc_rule = Google::Cloud::Bigtable::GcRule.max_age(300)
548
- # modifications << Google::Cloud::Bigtable::ColumnFamily.update_modification(
549
- # "cf4", Google::Cloud::Bigtable::GcRule.union(max_version_gc_rule)
550
- # )
551
- #
552
- # modifications << Google::Cloud::Bigtable::ColumnFamily.drop_modification("cf5")
553
- #
554
- # table = bigtable.modify_column_families("my-instance", "my-table", modifications)
555
- #
556
- # p table.column_families
557
-
558
- def modify_column_families instance_id, table_id, modifications
559
- ensure_service!
560
- Table.modify_column_families(
561
- service,
562
- instance_id,
563
- table_id,
564
- modifications
565
- )
566
- end
567
-
568
490
  protected
569
491
 
570
492
  # @private