google-cloud-bigtable 0.6.1 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHENTICATION.md +4 -26
  3. data/CHANGELOG.md +85 -0
  4. data/CONTRIBUTING.md +1 -1
  5. data/OVERVIEW.md +388 -19
  6. data/lib/google-cloud-bigtable.rb +19 -22
  7. data/lib/google/bigtable/admin/v2/bigtable_table_admin_services_pb.rb +1 -1
  8. data/lib/google/bigtable/v2/bigtable_pb.rb +3 -0
  9. data/lib/google/bigtable/v2/bigtable_services_pb.rb +1 -1
  10. data/lib/google/cloud/bigtable.rb +11 -17
  11. data/lib/google/cloud/bigtable/admin.rb +1 -1
  12. data/lib/google/cloud/bigtable/admin/v2.rb +1 -1
  13. data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client.rb +1 -1
  14. data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/policy.rb +42 -21
  15. data/lib/google/cloud/bigtable/app_profile.rb +162 -96
  16. data/lib/google/cloud/bigtable/app_profile/job.rb +5 -8
  17. data/lib/google/cloud/bigtable/app_profile/list.rb +18 -12
  18. data/lib/google/cloud/bigtable/chunk_processor.rb +24 -36
  19. data/lib/google/cloud/bigtable/cluster.rb +45 -18
  20. data/lib/google/cloud/bigtable/cluster/job.rb +3 -7
  21. data/lib/google/cloud/bigtable/cluster/list.rb +22 -20
  22. data/lib/google/cloud/bigtable/column_family.rb +18 -231
  23. data/lib/google/cloud/bigtable/column_family_map.rb +426 -0
  24. data/lib/google/cloud/bigtable/column_range.rb +15 -7
  25. data/lib/google/cloud/bigtable/convert.rb +12 -4
  26. data/lib/google/cloud/bigtable/errors.rb +4 -1
  27. data/lib/google/cloud/bigtable/gc_rule.rb +188 -69
  28. data/lib/google/cloud/bigtable/instance.rb +209 -189
  29. data/lib/google/cloud/bigtable/instance/cluster_map.rb +17 -13
  30. data/lib/google/cloud/bigtable/instance/job.rb +6 -5
  31. data/lib/google/cloud/bigtable/instance/list.rb +18 -13
  32. data/lib/google/cloud/bigtable/longrunning_job.rb +7 -1
  33. data/lib/google/cloud/bigtable/mutation_entry.rb +36 -39
  34. data/lib/google/cloud/bigtable/mutation_operations.rb +90 -73
  35. data/lib/google/cloud/bigtable/policy.rb +9 -5
  36. data/lib/google/cloud/bigtable/project.rb +87 -196
  37. data/lib/google/cloud/bigtable/read_modify_write_rule.rb +15 -10
  38. data/lib/google/cloud/bigtable/read_operations.rb +42 -59
  39. data/lib/google/cloud/bigtable/routing_policy.rb +172 -0
  40. data/lib/google/cloud/bigtable/row.rb +32 -21
  41. data/lib/google/cloud/bigtable/row_filter.rb +80 -35
  42. data/lib/google/cloud/bigtable/row_filter/chain_filter.rb +119 -68
  43. data/lib/google/cloud/bigtable/row_filter/condition_filter.rb +8 -2
  44. data/lib/google/cloud/bigtable/row_filter/interleave_filter.rb +117 -66
  45. data/lib/google/cloud/bigtable/row_filter/simple_filter.rb +24 -9
  46. data/lib/google/cloud/bigtable/row_range.rb +5 -0
  47. data/lib/google/cloud/bigtable/rows_mutator.rb +14 -21
  48. data/lib/google/cloud/bigtable/rows_reader.rb +23 -18
  49. data/lib/google/cloud/bigtable/sample_row_key.rb +6 -3
  50. data/lib/google/cloud/bigtable/service.rb +200 -253
  51. data/lib/google/cloud/bigtable/status.rb +76 -0
  52. data/lib/google/cloud/bigtable/table.rb +158 -262
  53. data/lib/google/cloud/bigtable/table/cluster_state.rb +17 -6
  54. data/lib/google/cloud/bigtable/table/list.rb +16 -9
  55. data/lib/google/cloud/bigtable/v2.rb +1 -1
  56. data/lib/google/cloud/bigtable/v2/bigtable_client.rb +12 -12
  57. data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/bigtable.rb +16 -13
  58. data/lib/google/cloud/bigtable/value_range.rb +19 -13
  59. data/lib/google/cloud/bigtable/version.rb +1 -1
  60. metadata +67 -25
  61. data/lib/google/cloud/bigtable/table/column_family_map.rb +0 -70
@@ -19,16 +19,18 @@ module Google
19
19
  module Cloud
20
20
  module Bigtable
21
21
  class Instance
22
- # Instance::ClusterMap is a hash with cluster name and gRPC object.
23
- # It is used to create an instance.
24
- # @example Create
22
+ ##
23
+ # Instance::ClusterMap is a hash with cluster ID keys and cluster configuration values.
24
+ # It is used to create a cluster.
25
+ #
26
+ # @example
25
27
  #
26
28
  # clusters = Google::Cloud::Bigtable::Instance::ClusterMap.new
27
29
  #
28
- # clusters.add("cluster-1", 3, location: "us-east1-b", storage_type: :SSD)
30
+ # clusters.add("cluster-1", "us-east1-b", nodes: 3, storage_type: :SSD)
29
31
  #
30
32
  # # Or
31
- # cluster.add("cluster-2", 1)
33
+ # clusters.add("cluster-2", "us-east1-b")
32
34
  #
33
35
  class ClusterMap < DelegateClass(::Hash)
34
36
  # @private
@@ -36,32 +38,34 @@ module Google
36
38
  # Creates a new Instance::ClusterMap with an hash of Cluster name and
37
39
  # cluster grpc instances.
38
40
  def initialize value = {}
39
- super(value)
41
+ super value
40
42
  end
41
43
 
42
- # Adds a cluster to a map
44
+ ##
45
+ # Adds a cluster to the cluster map.
43
46
  #
44
- # @param name [String] Cluster name
47
+ # @param name [String] The unique identifier for the cluster.
45
48
  # @param location [String]
46
49
  # The location where this cluster's nodes and storage reside. For best
47
50
  # performance, clients should be located as close as possible to this
48
51
  # cluster. Currently only zones are supported.
49
- # @param nodes [Integer] Number of nodes
52
+ # @param nodes [Integer] Number of nodes for the cluster. When creating
53
+ # an instance of type `:DEVELOPMENT`, `nodes` must not be set.
50
54
  # @param storage_type [Symbol]
51
55
  # Valid values are:
52
56
  # * `:SSD`(Flash (SSD) storage should be used),
53
57
  # *`:HDD`(Magnetic drive (HDD) storage should be used)
54
58
  #
55
59
  # If not set then default will set to `:STORAGE_TYPE_UNSPECIFIED`
56
-
60
+ #
57
61
  def add name, location, nodes: nil, storage_type: nil
58
62
  attrs = {
59
- serve_nodes: nodes,
60
- location: location,
63
+ serve_nodes: nodes,
64
+ location: location,
61
65
  default_storage_type: storage_type
62
66
  }.delete_if { |_, v| v.nil? }
63
67
 
64
- self[name] = Google::Bigtable::Admin::V2::Cluster.new(attrs)
68
+ self[name] = Google::Bigtable::Admin::V2::Cluster.new attrs
65
69
  end
66
70
  end
67
71
  end
@@ -17,6 +17,7 @@ module Google
17
17
  module Cloud
18
18
  module Bigtable
19
19
  class Instance
20
+ ##
20
21
  # # Job
21
22
  #
22
23
  # A resource representing the long-running, asynchronous processing of
@@ -39,7 +40,7 @@ module Google
39
40
  # type: :DEVELOPMENT,
40
41
  # labels: { "env" => "dev"}
41
42
  # ) do |clusters|
42
- # clusters.add("test-cluster", "us-east1-b", nodes: 1)
43
+ # clusters.add("test-cluster", "us-east1-b") # nodes not allowed
43
44
  # end
44
45
  #
45
46
  # # Check and reload.
@@ -57,8 +58,8 @@ module Google
57
58
  # instance = job.instance
58
59
  # end
59
60
  #
60
- #
61
61
  class Job < LongrunningJob
62
+ ##
62
63
  # Get the instance object from operation results.
63
64
  #
64
65
  # @return [Google::Cloud::Bigtable::Instance, nil] The Instance instance, or
@@ -71,11 +72,11 @@ module Google
71
72
  #
72
73
  # job = bigtable.create_instance(
73
74
  # "my-instance",
74
- # "Instance for user data",
75
+ # display_name: "Instance for user data",
75
76
  # type: :DEVELOPMENT,
76
77
  # labels: { "env" => "dev"}
77
78
  # ) do |clusters|
78
- # clusters.add("test-cluster", "us-east1-b", nodes: 1)
79
+ # clusters.add("test-cluster", "us-east1-b") # nodes not allowed
79
80
  # end
80
81
  #
81
82
  # job.done? #=> false
@@ -88,7 +89,7 @@ module Google
88
89
  # instance = job.instance
89
90
  #
90
91
  def instance
91
- Instance.from_grpc(results, service) if results
92
+ Instance.from_grpc results, service if results
92
93
  end
93
94
  end
94
95
  end
@@ -21,6 +21,7 @@ module Google
21
21
  module Cloud
22
22
  module Bigtable
23
23
  class Instance
24
+ ##
24
25
  # Instance::List is a special-case array with additional
25
26
  # values and failed_locations.
26
27
  class List < DelegateClass(::Array)
@@ -28,24 +29,27 @@ module Google
28
29
  # The gRPC Service object.
29
30
  attr_accessor :service
30
31
 
32
+ ##
31
33
  # If not empty, indicates that more records match
32
34
  # the request and this value should be passed to continue.
33
35
  attr_accessor :token
34
36
 
35
- # Locations from which Instance information could not be retrieved,
37
+ ##
38
+ # Locations from which instance information could not be retrieved,
36
39
  # due to an outage or some other transient condition.
37
- # Instances whose Clusters are all in one of the failed locations
38
- # may be missing from `instances`, and Instances with at least one
39
- # Cluster in a failed location may only have partial information returned.
40
+ # Instances whose clusters are all in one of the failed locations
41
+ # may be missing from `instances`, and instances with at least one
42
+ # cluster in a failed location may only have partial information returned.
40
43
  attr_accessor :failed_locations
41
44
 
42
45
  # @private
43
46
  # Creates a new Instance::List with an array of
44
47
  # Instance instances.
45
48
  def initialize arr = []
46
- super(arr)
49
+ super arr
47
50
  end
48
51
 
52
+ ##
49
53
  # Whether there is a next page of instances.
50
54
  #
51
55
  # @return [Boolean]
@@ -59,10 +63,12 @@ module Google
59
63
  # if instances.next?
60
64
  # next_instances = instances.next
61
65
  # end
66
+ #
62
67
  def next?
63
68
  !token.nil?
64
69
  end
65
70
 
71
+ ##
66
72
  # Retrieves the next page of instances.
67
73
  #
68
74
  # @return [Instance::List] The list of instances.
@@ -80,14 +86,13 @@ module Google
80
86
  def next
81
87
  return nil unless next?
82
88
  ensure_service!
83
- grpc = service.list_instances(token: token)
84
- next_list = self.class.from_grpc(grpc, service)
85
- if failed_locations
86
- next_list.failed_locations.concat(failed_locations.map(&:to_s))
87
- end
89
+ grpc = service.list_instances token: token
90
+ next_list = self.class.from_grpc grpc, service
91
+ next_list.failed_locations.concat(failed_locations.map(&:to_s)) if failed_locations
88
92
  next_list
89
93
  end
90
94
 
95
+ ##
91
96
  # Retrieves remaining results by repeatedly invoking {#next} until
92
97
  # {#next?} returns `false`. Calls the given block once for each
93
98
  # result, which is passed as the argument to the block.
@@ -122,7 +127,7 @@ module Google
122
127
  # end
123
128
  #
124
129
  def all
125
- return enum_for(:all) unless block_given?
130
+ return enum_for :all unless block_given?
126
131
 
127
132
  results = self
128
133
  loop do
@@ -136,10 +141,10 @@ module Google
136
141
  # New Instance::List from a Google::Bigtable::Admin::V2::Instance object.
137
142
  def self.from_grpc grpc, service
138
143
  instances = List.new(Array(grpc.instances).map do |instance|
139
- Instance.from_grpc(instance, service)
144
+ Instance.from_grpc instance, service
140
145
  end)
141
146
  token = grpc.next_page_token
142
- token = nil if token == "".freeze
147
+ token = nil if token == ""
143
148
  instances.token = token
144
149
  instances.service = service
145
150
  instances.failed_locations = grpc.failed_locations.map(&:to_s)
@@ -18,6 +18,7 @@
18
18
  module Google
19
19
  module Cloud
20
20
  module Bigtable
21
+ ##
21
22
  # # LongrunningJob
22
23
  #
23
24
  # A resource representing the long-running, asynchronous processing operation.
@@ -35,7 +36,8 @@ module Google
35
36
  # The gRPC Service object.
36
37
  attr_accessor :service
37
38
 
38
- # Get result object of the operation.
39
+ ##
40
+ # Gets the result object of the operation.
39
41
  #
40
42
  # @return [Object, nil]
41
43
  # `nil` if the operation is not complete.
@@ -46,6 +48,7 @@ module Google
46
48
  @grpc.results
47
49
  end
48
50
 
51
+ ##
49
52
  # Checks if the processing of the instance operation is complete.
50
53
  #
51
54
  # @return [boolean] `true` when complete, `false` otherwise.
@@ -54,6 +57,7 @@ module Google
54
57
  @grpc.done?
55
58
  end
56
59
 
60
+ ##
57
61
  # Checks if the processing of the instance operation has errored.
58
62
  #
59
63
  # @return [boolean] `true` when errored, `false` otherwise.
@@ -74,6 +78,7 @@ module Google
74
78
  @grpc.error
75
79
  end
76
80
 
81
+ ##
77
82
  # Reloads the job with current data from the long-running,
78
83
  # asynchronous processing of an operation.
79
84
  #
@@ -84,6 +89,7 @@ module Google
84
89
  self
85
90
  end
86
91
 
92
+ ##
87
93
  # Reloads the job until the operation is complete. The delay between
88
94
  # reloads will incrementally increase.
89
95
  #
@@ -18,6 +18,7 @@
18
18
  module Google
19
19
  module Cloud
20
20
  module Bigtable
21
+ ##
21
22
  # # MutationEntry
22
23
  #
23
24
  # MutationEntry is a chainable structure that holds data for different
@@ -41,7 +42,7 @@ module Google
41
42
  # timestamp_to: timestamp_micros
42
43
  # ).delete_from_family("cf3").delete_from_row
43
44
  #
44
- # @example Using table
45
+ # @example Create using a table.
45
46
  # require "google/cloud/bigtable"
46
47
  #
47
48
  # bigtable = Google::Cloud::Bigtable.new
@@ -56,22 +57,26 @@ module Google
56
57
  class MutationEntry
57
58
  attr_accessor :row_key
58
59
 
60
+ # @private
59
61
  # mutations gRPC list
60
62
  # @return [Array<Google::Bigtable::V2::Mutation>]
61
63
  attr_accessor :mutations
62
64
 
65
+ ##
63
66
  # Creates a mutation entry instance.
64
67
  #
65
68
  # @param row_key [String]
69
+ #
66
70
  def initialize row_key = nil
67
71
  @row_key = row_key
68
72
  @mutations = []
69
73
  @retryable = true
70
74
  end
71
75
 
72
- # Add SetCell mutation to list of mutations.
76
+ ##
77
+ # Adds a SetCell to the list of mutations.
73
78
  #
74
- # A mutation that sets the value of the specified cell.
79
+ # A SetCell is a mutation that sets the value of the specified cell.
75
80
  #
76
81
  # @param family [String] Table column family name.
77
82
  # The name of the family into which new data should be written.
@@ -96,7 +101,7 @@ module Google
96
101
  # entry = Google::Cloud::Bigtable::MutationEntry.new("user-1")
97
102
  # entry.set_cell("cf1", "field01", "XYZ")
98
103
  #
99
- # @example With timestamp
104
+ # @example With timestamp.
100
105
  # entry = Google::Cloud::Bigtable::MutationEntry.new("user-1")
101
106
  # entry.set_cell(
102
107
  # "cf-1",
@@ -107,11 +112,11 @@ module Google
107
112
  #
108
113
  def set_cell family, qualifier, value, timestamp: nil
109
114
  # If value is integer, covert it to a 64-bit signed big-endian integer.
110
- value = [value].pack("q>") if value.is_a?(Integer)
115
+ value = [value].pack "q>" if value.is_a? Integer
111
116
  options = {
112
- family_name: family,
117
+ family_name: family,
113
118
  column_qualifier: qualifier,
114
- value: value
119
+ value: value
115
120
  }
116
121
 
117
122
  if timestamp
@@ -122,10 +127,12 @@ module Google
122
127
  self
123
128
  end
124
129
 
125
- # Add DeleteFromColumn entry to list of mutations.
130
+ ##
131
+ # Adds a DeleteFromColumn to the list of mutations.
126
132
  #
127
- # A mutation that deletes cells from the specified column, optionally
128
- # restricting the deletions to a given timestamp range.
133
+ # A DeleteFromColumn is a mutation that deletes cells from the
134
+ # specified column, optionally restricting the deletions to a given
135
+ # timestamp range.
129
136
  #
130
137
  # @param family [String] Table column family name.
131
138
  # The name of the column family from which cells should be deleted.
@@ -147,11 +154,11 @@ module Google
147
154
  # (millisecond granularity). For example: `1564257960168000`.
148
155
  # @return [MutationEntry] `self` object of entry for chaining.
149
156
  #
150
- # @example Without timestamp range
157
+ # @example Without timestamp range.
151
158
  # entry = Google::Cloud::Bigtable::MutationEntry.new("user-1")
152
159
  # entry.delete_cells("cf-1", "field-1")
153
160
  #
154
- # @example With timestamp range
161
+ # @example With timestamp range.
155
162
  # entry = Google::Cloud::Bigtable::MutationEntry.new("user-1")
156
163
  # timestamp_micros = (Time.now.to_f * 1000000).round(-3)
157
164
  # entry.delete_cells(
@@ -160,7 +167,7 @@ module Google
160
167
  # timestamp_from: timestamp_micros - 5000000,
161
168
  # timestamp_to: timestamp_micros
162
169
  # )
163
- # @example With timestamp range with lower boundary only
170
+ # @example With timestamp range with lower boundary only.
164
171
  # entry = Google::Cloud::Bigtable::MutationEntry.new("user-1")
165
172
  # timestamp_micros = (Time.now.to_f * 1000000).round(-3)
166
173
  # entry.delete_cells(
@@ -169,30 +176,22 @@ module Google
169
176
  # timestamp_from: timestamp_micros - 5000000
170
177
  # )
171
178
  #
172
- def delete_cells \
173
- family,
174
- qualifier,
175
- timestamp_from: nil,
176
- timestamp_to: nil
177
- grpc = Google::Bigtable::V2::Mutation::DeleteFromColumn.new(
178
- family_name: family,
179
- column_qualifier: qualifier
180
- )
179
+ def delete_cells family, qualifier, timestamp_from: nil, timestamp_to: nil
180
+ grpc = Google::Bigtable::V2::Mutation::DeleteFromColumn.new family_name: family, column_qualifier: qualifier
181
181
  if timestamp_from || timestamp_to
182
182
  time_range = Google::Bigtable::V2::TimestampRange.new
183
183
  time_range.start_timestamp_micros = timestamp_from if timestamp_from
184
184
  time_range.end_timestamp_micros = timestamp_to if timestamp_to
185
185
  grpc.time_range = time_range
186
186
  end
187
- @mutations << Google::Bigtable::V2::Mutation.new(
188
- delete_from_column: grpc
189
- )
187
+ @mutations << Google::Bigtable::V2::Mutation.new(delete_from_column: grpc)
190
188
  self
191
189
  end
192
190
 
193
- # Add DeleteFromFamily to list of mutations.
191
+ ##
192
+ # Adds a DeleteFromFamily to the list of mutations.
194
193
  #
195
- # A mutation that deletes all cells from the specified column family.
194
+ # A DeleteFromFamily is a mutation that deletes all cells from the specified column family.
196
195
  #
197
196
  # @param family [String] Table column family name.
198
197
  # The name of the column family from which cells should be deleted.
@@ -204,15 +203,14 @@ module Google
204
203
  # entry.delete_from_family("cf-1")
205
204
  #
206
205
  def delete_from_family family
207
- @mutations << Google::Bigtable::V2::Mutation.new(
208
- delete_from_family: { family_name: family }
209
- )
206
+ @mutations << Google::Bigtable::V2::Mutation.new(delete_from_family: { family_name: family })
210
207
  self
211
208
  end
212
209
 
213
- # Add DeleteFromRow entry to list of mutations
210
+ ##
211
+ # Adds a DeleteFromRow to the list of mutations.
214
212
  #
215
- # A Mutation which deletes all cells from the containing row.
213
+ # A DeleteFromRow is a mutation which deletes all cells from the containing row.
216
214
  #
217
215
  # @return [MutationEntry] `self` object of entry for chaining.
218
216
  #
@@ -225,7 +223,8 @@ module Google
225
223
  self
226
224
  end
227
225
 
228
- # Mutation entry is retryable or not based on set_cell value.
226
+ ##
227
+ # If the mutation entry is retryable or not based on set_cell value.
229
228
  #
230
229
  # @return [Boolean]
231
230
  #
@@ -233,10 +232,11 @@ module Google
233
232
  @retryable
234
233
  end
235
234
 
236
- # Number of mutations
235
+ ##
236
+ # The number of mutations.
237
237
  #
238
238
  # @return [Integer]
239
-
239
+ #
240
240
  def length
241
241
  @mutations.length
242
242
  end
@@ -248,10 +248,7 @@ module Google
248
248
  # @return [Google::Bigtable::V2::MutateRowsRequest::Entry]
249
249
  #
250
250
  def to_grpc
251
- Google::Bigtable::V2::MutateRowsRequest::Entry.new(
252
- row_key: @row_key,
253
- mutations: @mutations
254
- )
251
+ Google::Bigtable::V2::MutateRowsRequest::Entry.new row_key: @row_key, mutations: @mutations
255
252
  end
256
253
  end
257
254
  end