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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +36 -0
- data/CONTRIBUTING.md +1 -1
- data/lib/google-cloud-bigtable.rb +19 -21
- data/lib/google/cloud/bigtable.rb +11 -17
- data/lib/google/cloud/bigtable/app_profile.rb +148 -82
- data/lib/google/cloud/bigtable/app_profile/job.rb +5 -8
- data/lib/google/cloud/bigtable/app_profile/list.rb +11 -5
- data/lib/google/cloud/bigtable/chunk_processor.rb +23 -35
- data/lib/google/cloud/bigtable/cluster.rb +38 -11
- data/lib/google/cloud/bigtable/cluster/job.rb +3 -7
- data/lib/google/cloud/bigtable/cluster/list.rb +20 -18
- data/lib/google/cloud/bigtable/column_family.rb +22 -229
- data/lib/google/cloud/bigtable/column_family_map.rb +426 -0
- data/lib/google/cloud/bigtable/column_range.rb +9 -1
- data/lib/google/cloud/bigtable/convert.rb +12 -4
- data/lib/google/cloud/bigtable/errors.rb +4 -1
- data/lib/google/cloud/bigtable/gc_rule.rb +184 -65
- data/lib/google/cloud/bigtable/instance.rb +136 -126
- data/lib/google/cloud/bigtable/instance/cluster_map.rb +9 -7
- data/lib/google/cloud/bigtable/instance/job.rb +4 -3
- data/lib/google/cloud/bigtable/instance/list.rb +14 -9
- data/lib/google/cloud/bigtable/longrunning_job.rb +6 -0
- data/lib/google/cloud/bigtable/mutation_entry.rb +19 -23
- data/lib/google/cloud/bigtable/mutation_operations.rb +82 -29
- data/lib/google/cloud/bigtable/policy.rb +9 -5
- data/lib/google/cloud/bigtable/project.rb +62 -140
- data/lib/google/cloud/bigtable/read_modify_write_rule.rb +9 -4
- data/lib/google/cloud/bigtable/read_operations.rb +28 -41
- data/lib/google/cloud/bigtable/routing_policy.rb +171 -0
- data/lib/google/cloud/bigtable/row.rb +18 -7
- data/lib/google/cloud/bigtable/row_filter.rb +49 -20
- data/lib/google/cloud/bigtable/row_filter/chain_filter.rb +71 -43
- data/lib/google/cloud/bigtable/row_filter/condition_filter.rb +4 -1
- data/lib/google/cloud/bigtable/row_filter/interleave_filter.rb +74 -43
- data/lib/google/cloud/bigtable/row_filter/simple_filter.rb +22 -7
- data/lib/google/cloud/bigtable/row_range.rb +5 -0
- data/lib/google/cloud/bigtable/rows_mutator.rb +14 -17
- data/lib/google/cloud/bigtable/rows_reader.rb +18 -14
- data/lib/google/cloud/bigtable/sample_row_key.rb +5 -2
- data/lib/google/cloud/bigtable/service.rb +161 -242
- data/lib/google/cloud/bigtable/status.rb +76 -0
- data/lib/google/cloud/bigtable/table.rb +141 -236
- data/lib/google/cloud/bigtable/table/cluster_state.rb +7 -1
- data/lib/google/cloud/bigtable/table/list.rb +14 -7
- data/lib/google/cloud/bigtable/value_range.rb +5 -0
- data/lib/google/cloud/bigtable/version.rb +1 -1
- metadata +27 -25
- data/lib/google/cloud/bigtable/table/column_family_map.rb +0 -70
@@ -19,16 +19,17 @@ module Google
|
|
19
19
|
module Cloud
|
20
20
|
module Bigtable
|
21
21
|
class Instance
|
22
|
+
##
|
22
23
|
# Instance::ClusterMap is a hash with cluster name and gRPC object.
|
23
24
|
# It is used to create an instance.
|
24
25
|
# @example Create
|
25
26
|
#
|
26
27
|
# clusters = Google::Cloud::Bigtable::Instance::ClusterMap.new
|
27
28
|
#
|
28
|
-
# clusters.add("cluster-1",
|
29
|
+
# clusters.add("cluster-1", "us-east1-b", nodes: 3, storage_type: :SSD)
|
29
30
|
#
|
30
31
|
# # Or
|
31
|
-
#
|
32
|
+
# clusters.add("cluster-2", "us-east1-b")
|
32
33
|
#
|
33
34
|
class ClusterMap < DelegateClass(::Hash)
|
34
35
|
# @private
|
@@ -36,9 +37,10 @@ module Google
|
|
36
37
|
# Creates a new Instance::ClusterMap with an hash of Cluster name and
|
37
38
|
# cluster grpc instances.
|
38
39
|
def initialize value = {}
|
39
|
-
super
|
40
|
+
super value
|
40
41
|
end
|
41
42
|
|
43
|
+
##
|
42
44
|
# Adds a cluster to a map
|
43
45
|
#
|
44
46
|
# @param name [String] Cluster name
|
@@ -53,15 +55,15 @@ module Google
|
|
53
55
|
# *`:HDD`(Magnetic drive (HDD) storage should be used)
|
54
56
|
#
|
55
57
|
# If not set then default will set to `:STORAGE_TYPE_UNSPECIFIED`
|
56
|
-
|
58
|
+
#
|
57
59
|
def add name, location, nodes: nil, storage_type: nil
|
58
60
|
attrs = {
|
59
|
-
serve_nodes:
|
60
|
-
location:
|
61
|
+
serve_nodes: nodes,
|
62
|
+
location: location,
|
61
63
|
default_storage_type: storage_type
|
62
64
|
}.delete_if { |_, v| v.nil? }
|
63
65
|
|
64
|
-
self[name] = Google::Bigtable::Admin::V2::Cluster.new
|
66
|
+
self[name] = Google::Bigtable::Admin::V2::Cluster.new attrs
|
65
67
|
end
|
66
68
|
end
|
67
69
|
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
|
@@ -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,7 +72,7 @@ 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|
|
@@ -88,7 +89,7 @@ module Google
|
|
88
89
|
# instance = job.instance
|
89
90
|
#
|
90
91
|
def instance
|
91
|
-
Instance.from_grpc
|
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,10 +29,12 @@ 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
|
|
37
|
+
##
|
35
38
|
# Locations from which Instance information could not be retrieved,
|
36
39
|
# due to an outage or some other transient condition.
|
37
40
|
# Instances whose Clusters are all in one of the failed locations
|
@@ -43,9 +46,10 @@ module Google
|
|
43
46
|
# Creates a new Instance::List with an array of
|
44
47
|
# Instance instances.
|
45
48
|
def initialize arr = []
|
46
|
-
super
|
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
|
84
|
-
next_list = self.class.from_grpc
|
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
|
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
|
144
|
+
Instance.from_grpc instance, service
|
140
145
|
end)
|
141
146
|
token = grpc.next_page_token
|
142
|
-
token = nil if token == ""
|
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,6 +36,7 @@ module Google
|
|
35
36
|
# The gRPC Service object.
|
36
37
|
attr_accessor :service
|
37
38
|
|
39
|
+
##
|
38
40
|
# Get result object of the operation.
|
39
41
|
#
|
40
42
|
# @return [Object, nil]
|
@@ -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
|
@@ -56,19 +57,23 @@ 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
|
|
76
|
+
##
|
72
77
|
# Add SetCell mutation to list of mutations.
|
73
78
|
#
|
74
79
|
# A mutation that sets the value of the specified cell.
|
@@ -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
|
115
|
+
value = [value].pack "q>" if value.is_a? Integer
|
111
116
|
options = {
|
112
|
-
family_name:
|
117
|
+
family_name: family,
|
113
118
|
column_qualifier: qualifier,
|
114
|
-
value:
|
119
|
+
value: value
|
115
120
|
}
|
116
121
|
|
117
122
|
if timestamp
|
@@ -122,6 +127,7 @@ module Google
|
|
122
127
|
self
|
123
128
|
end
|
124
129
|
|
130
|
+
##
|
125
131
|
# Add DeleteFromColumn entry to list of mutations.
|
126
132
|
#
|
127
133
|
# A mutation that deletes cells from the specified column, optionally
|
@@ -169,27 +175,19 @@ module Google
|
|
169
175
|
# timestamp_from: timestamp_micros - 5000000
|
170
176
|
# )
|
171
177
|
#
|
172
|
-
def delete_cells
|
173
|
-
|
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
|
-
)
|
178
|
+
def delete_cells family, qualifier, timestamp_from: nil, timestamp_to: nil
|
179
|
+
grpc = Google::Bigtable::V2::Mutation::DeleteFromColumn.new family_name: family, column_qualifier: qualifier
|
181
180
|
if timestamp_from || timestamp_to
|
182
181
|
time_range = Google::Bigtable::V2::TimestampRange.new
|
183
182
|
time_range.start_timestamp_micros = timestamp_from if timestamp_from
|
184
183
|
time_range.end_timestamp_micros = timestamp_to if timestamp_to
|
185
184
|
grpc.time_range = time_range
|
186
185
|
end
|
187
|
-
@mutations << Google::Bigtable::V2::Mutation.new(
|
188
|
-
delete_from_column: grpc
|
189
|
-
)
|
186
|
+
@mutations << Google::Bigtable::V2::Mutation.new(delete_from_column: grpc)
|
190
187
|
self
|
191
188
|
end
|
192
189
|
|
190
|
+
##
|
193
191
|
# Add DeleteFromFamily to list of mutations.
|
194
192
|
#
|
195
193
|
# A mutation that deletes all cells from the specified column family.
|
@@ -204,12 +202,11 @@ module Google
|
|
204
202
|
# entry.delete_from_family("cf-1")
|
205
203
|
#
|
206
204
|
def delete_from_family family
|
207
|
-
@mutations << Google::Bigtable::V2::Mutation.new(
|
208
|
-
delete_from_family: { family_name: family }
|
209
|
-
)
|
205
|
+
@mutations << Google::Bigtable::V2::Mutation.new(delete_from_family: { family_name: family })
|
210
206
|
self
|
211
207
|
end
|
212
208
|
|
209
|
+
##
|
213
210
|
# Add DeleteFromRow entry to list of mutations
|
214
211
|
#
|
215
212
|
# A Mutation which deletes all cells from the containing row.
|
@@ -225,6 +222,7 @@ module Google
|
|
225
222
|
self
|
226
223
|
end
|
227
224
|
|
225
|
+
##
|
228
226
|
# Mutation entry is retryable or not based on set_cell value.
|
229
227
|
#
|
230
228
|
# @return [Boolean]
|
@@ -233,10 +231,11 @@ module Google
|
|
233
231
|
@retryable
|
234
232
|
end
|
235
233
|
|
234
|
+
##
|
236
235
|
# Number of mutations
|
237
236
|
#
|
238
237
|
# @return [Integer]
|
239
|
-
|
238
|
+
#
|
240
239
|
def length
|
241
240
|
@mutations.length
|
242
241
|
end
|
@@ -248,10 +247,7 @@ module Google
|
|
248
247
|
# @return [Google::Bigtable::V2::MutateRowsRequest::Entry]
|
249
248
|
#
|
250
249
|
def to_grpc
|
251
|
-
Google::Bigtable::V2::MutateRowsRequest::Entry.new
|
252
|
-
row_key: @row_key,
|
253
|
-
mutations: @mutations
|
254
|
-
)
|
250
|
+
Google::Bigtable::V2::MutateRowsRequest::Entry.new row_key: @row_key, mutations: @mutations
|
255
251
|
end
|
256
252
|
end
|
257
253
|
end
|
@@ -19,10 +19,12 @@ require "google/cloud/bigtable/mutation_entry"
|
|
19
19
|
require "google/cloud/bigtable/row"
|
20
20
|
require "google/cloud/bigtable/rows_mutator"
|
21
21
|
require "google/cloud/bigtable/read_modify_write_rule"
|
22
|
+
require "google/cloud/bigtable/status"
|
22
23
|
|
23
24
|
module Google
|
24
25
|
module Cloud
|
25
26
|
module Bigtable
|
27
|
+
##
|
26
28
|
# # MutationOperations
|
27
29
|
#
|
28
30
|
# Collection of mutations APIs.
|
@@ -33,6 +35,7 @@ module Google
|
|
33
35
|
# * Check and mutate row
|
34
36
|
#
|
35
37
|
module MutationOperations
|
38
|
+
##
|
36
39
|
# Mutate row.
|
37
40
|
#
|
38
41
|
# Mutates a row atomically. Cells in the row are left
|
@@ -45,18 +48,18 @@ module Google
|
|
45
48
|
# Mutation entry with row key and list of mutations.
|
46
49
|
# @return [Boolean]
|
47
50
|
# @example Single mutation on row.
|
48
|
-
# require "google/cloud"
|
51
|
+
# require "google/cloud/bigtable"
|
49
52
|
#
|
50
53
|
# bigtable = Google::Cloud::Bigtable.new
|
51
54
|
#
|
52
55
|
# table = bigtable.table("my-instance", "my-table")
|
53
56
|
#
|
54
|
-
# entry = table.new_mutation_entry
|
57
|
+
# entry = table.new_mutation_entry("user-1")
|
55
58
|
# entry.set_cell("cf1", "field1", "XYZ")
|
56
59
|
# table.mutate_row(entry)
|
57
60
|
#
|
58
61
|
# @example Multiple mutations on row.
|
59
|
-
# require "google/cloud"
|
62
|
+
# require "google/cloud/bigtable"
|
60
63
|
#
|
61
64
|
# bigtable = Google::Cloud::Bigtable.new
|
62
65
|
#
|
@@ -73,15 +76,11 @@ module Google
|
|
73
76
|
# table.mutate_row(entry)
|
74
77
|
#
|
75
78
|
def mutate_row entry
|
76
|
-
client.mutate_row
|
77
|
-
path,
|
78
|
-
entry.row_key,
|
79
|
-
entry.mutations,
|
80
|
-
app_profile_id: @app_profile_id
|
81
|
-
)
|
79
|
+
client.mutate_row path, entry.row_key, entry.mutations, app_profile_id: @app_profile_id
|
82
80
|
true
|
83
81
|
end
|
84
82
|
|
83
|
+
##
|
85
84
|
# Mutates multiple rows in a batch. Each individual row is mutated
|
86
85
|
# atomically as in MutateRow, but the entire batch is not executed
|
87
86
|
# atomically.
|
@@ -95,7 +94,7 @@ module Google
|
|
95
94
|
# @return [Array<Google::Bigtable::V2::MutateRowsResponse::Entry>]
|
96
95
|
#
|
97
96
|
# @example
|
98
|
-
# require "google/cloud"
|
97
|
+
# require "google/cloud/bigtable"
|
99
98
|
#
|
100
99
|
# bigtable = Google::Cloud::Bigtable.new
|
101
100
|
#
|
@@ -104,12 +103,18 @@ module Google
|
|
104
103
|
# entries = []
|
105
104
|
# entries << table.new_mutation_entry("row-1").set_cell("cf1", "field1", "XYZ")
|
106
105
|
# entries << table.new_mutation_entry("row-2").set_cell("cf1", "field1", "ABC")
|
107
|
-
# table.
|
106
|
+
# responses = table.mutate_rows(entries)
|
107
|
+
#
|
108
|
+
# responses.each do |response|
|
109
|
+
# puts response.status.description
|
110
|
+
# end
|
108
111
|
#
|
109
112
|
def mutate_rows entries
|
110
|
-
RowsMutator.new(self, entries).apply_mutations
|
113
|
+
statuses = RowsMutator.new(self, entries).apply_mutations
|
114
|
+
statuses.map { |s| Response.from_grpc s }
|
111
115
|
end
|
112
116
|
|
117
|
+
##
|
113
118
|
# Modifies a row atomically on the server. The method reads the latest
|
114
119
|
# existing timestamp and value from the specified columns and writes a new
|
115
120
|
# entry based on pre-defined read/modify/write rules. The new value for the
|
@@ -118,7 +123,8 @@ module Google
|
|
118
123
|
#
|
119
124
|
# @param key [String]
|
120
125
|
# The row key of the row to which the read/modify/write rules should be applied.
|
121
|
-
# @param rules [Google::Cloud::Bigtable::ReadModifyWriteRule,
|
126
|
+
# @param rules [Google::Cloud::Bigtable::ReadModifyWriteRule,
|
127
|
+
# Array<Google::Cloud::Bigtable::ReadModifyWriteRule>]
|
122
128
|
# Rules specifying how the specified row's contents are to be transformed
|
123
129
|
# into writes. Entries are applied in order, meaning that earlier rules will
|
124
130
|
# affect the results of later ones.
|
@@ -158,7 +164,7 @@ module Google
|
|
158
164
|
Array(rules).map(&:to_grpc),
|
159
165
|
app_profile_id: @app_profile_id
|
160
166
|
).row
|
161
|
-
row = Row.new
|
167
|
+
row = Row.new res_row.key
|
162
168
|
|
163
169
|
res_row.families.each do |family|
|
164
170
|
family.columns.each do |column|
|
@@ -177,6 +183,7 @@ module Google
|
|
177
183
|
row
|
178
184
|
end
|
179
185
|
|
186
|
+
##
|
180
187
|
# Mutates a row atomically based on the output of a predicate reader filter.
|
181
188
|
#
|
182
189
|
# NOTE: Condition predicate filter is not supported.
|
@@ -222,35 +229,32 @@ module Google
|
|
222
229
|
# otherwise_mutations = Google::Cloud::Bigtable::MutationEntry.new
|
223
230
|
# otherwise_mutations.delete_from_family("cf3")
|
224
231
|
#
|
225
|
-
#
|
232
|
+
# predicate_matched = table.check_and_mutate_row(
|
226
233
|
# "user01",
|
227
234
|
# predicate_filter,
|
228
235
|
# on_match: on_match_mutations,
|
229
236
|
# otherwise: otherwise_mutations
|
230
237
|
# )
|
231
238
|
#
|
232
|
-
# if
|
239
|
+
# if predicate_matched
|
233
240
|
# puts "All predicates matched"
|
234
241
|
# end
|
235
242
|
#
|
236
|
-
def check_and_mutate_row
|
237
|
-
key,
|
238
|
-
predicate,
|
239
|
-
on_match: nil,
|
240
|
-
otherwise: nil
|
243
|
+
def check_and_mutate_row key, predicate, on_match: nil, otherwise: nil
|
241
244
|
true_mutations = on_match.mutations if on_match
|
242
245
|
false_mutations = otherwise.mutations if otherwise
|
243
246
|
response = client.check_and_mutate_row(
|
244
247
|
path,
|
245
248
|
key,
|
246
249
|
predicate_filter: predicate.to_grpc,
|
247
|
-
true_mutations:
|
248
|
-
false_mutations:
|
249
|
-
app_profile_id:
|
250
|
+
true_mutations: true_mutations,
|
251
|
+
false_mutations: false_mutations,
|
252
|
+
app_profile_id: @app_profile_id
|
250
253
|
)
|
251
254
|
response.predicate_matched
|
252
255
|
end
|
253
256
|
|
257
|
+
##
|
254
258
|
# Read sample row keys.
|
255
259
|
#
|
256
260
|
# Returns a sample of row keys in the table. The returned row keys will
|
@@ -263,7 +267,7 @@ module Google
|
|
263
267
|
# Yield block for each processed SampleRowKey.
|
264
268
|
#
|
265
269
|
# @example
|
266
|
-
# require "google/cloud"
|
270
|
+
# require "google/cloud/bigtable"
|
267
271
|
#
|
268
272
|
# bigtable = Google::Cloud::Bigtable.new
|
269
273
|
# table = bigtable.table("my-instance", "my-table")
|
@@ -274,17 +278,18 @@ module Google
|
|
274
278
|
# end
|
275
279
|
#
|
276
280
|
def sample_row_keys
|
277
|
-
return enum_for
|
281
|
+
return enum_for :sample_row_keys unless block_given?
|
278
282
|
|
279
283
|
response = client.sample_row_keys(
|
280
284
|
path,
|
281
285
|
app_profile_id: @app_profile_id
|
282
286
|
)
|
283
287
|
response.each do |grpc|
|
284
|
-
yield SampleRowKey.from_grpc
|
288
|
+
yield SampleRowKey.from_grpc grpc
|
285
289
|
end
|
286
290
|
end
|
287
291
|
|
292
|
+
##
|
288
293
|
# Create an instance of mutation_entry
|
289
294
|
#
|
290
295
|
# @param row_key [String] Row key. Optional
|
@@ -303,9 +308,10 @@ module Google
|
|
303
308
|
# entry = table.new_mutation_entry
|
304
309
|
#
|
305
310
|
def new_mutation_entry row_key = nil
|
306
|
-
Google::Cloud::Bigtable::MutationEntry.new
|
311
|
+
Google::Cloud::Bigtable::MutationEntry.new row_key
|
307
312
|
end
|
308
313
|
|
314
|
+
##
|
309
315
|
# Create an instance of ReadModifyWriteRule to append or increment the value
|
310
316
|
# of the cell qualifier.
|
311
317
|
#
|
@@ -332,7 +338,54 @@ module Google
|
|
332
338
|
# rule.increment(100)
|
333
339
|
#
|
334
340
|
def new_read_modify_write_rule family, qualifier
|
335
|
-
Google::Cloud::Bigtable::ReadModifyWriteRule.new
|
341
|
+
Google::Cloud::Bigtable::ReadModifyWriteRule.new family, qualifier
|
342
|
+
end
|
343
|
+
|
344
|
+
##
|
345
|
+
# # MutationEntry::Response
|
346
|
+
#
|
347
|
+
# Represents a response message from BigtableService.MutateRows.
|
348
|
+
#
|
349
|
+
# @attr [Integer] index The index into the original request's `entries`
|
350
|
+
# list of the Entry for which a result is being reported.
|
351
|
+
# @attr [Google::Cloud::Bigtable::Status] The result of the request
|
352
|
+
# Entry identified by `index`. Depending on how requests are batched
|
353
|
+
# during execution, it is possible for one Entry to fail due to an
|
354
|
+
# error with another Entry. In the event that this occurs, the same
|
355
|
+
# error will be reported for both entries.
|
356
|
+
#
|
357
|
+
# @example
|
358
|
+
# require "google/cloud/bigtable"
|
359
|
+
#
|
360
|
+
# bigtable = Google::Cloud::Bigtable.new
|
361
|
+
#
|
362
|
+
# table = bigtable.table("my-instance", "my-table")
|
363
|
+
#
|
364
|
+
# entries = []
|
365
|
+
# entries << table.new_mutation_entry("row-1").set_cell("cf1", "field1", "XYZ")
|
366
|
+
# entries << table.new_mutation_entry("row-2").set_cell("cf1", "field1", "ABC")
|
367
|
+
# responses = table.mutate_rows(entries)
|
368
|
+
#
|
369
|
+
# responses.each do |response|
|
370
|
+
# puts response.status.description
|
371
|
+
# end
|
372
|
+
#
|
373
|
+
class Response
|
374
|
+
attr_reader :index, :status
|
375
|
+
|
376
|
+
##
|
377
|
+
# @private Creates a MutationEntry::Response object.
|
378
|
+
def initialize index, status
|
379
|
+
@index = index
|
380
|
+
@status = status
|
381
|
+
end
|
382
|
+
|
383
|
+
##
|
384
|
+
# @private New MutationEntry::Response from a
|
385
|
+
# Google::Bigtable::V2::MutateRowsResponse::Entry object.
|
386
|
+
def self.from_grpc grpc
|
387
|
+
new grpc.index, Status.from_grpc(grpc.status)
|
388
|
+
end
|
336
389
|
end
|
337
390
|
end
|
338
391
|
end
|