google-cloud-bigtable 1.3.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.
- checksums.yaml +7 -0
- data/.yardopts +19 -0
- data/AUTHENTICATION.md +177 -0
- data/CHANGELOG.md +223 -0
- data/CODE_OF_CONDUCT.md +40 -0
- data/CONTRIBUTING.md +188 -0
- data/EMULATOR.md +30 -0
- data/LICENSE +201 -0
- data/LOGGING.md +32 -0
- data/OVERVIEW.md +400 -0
- data/TROUBLESHOOTING.md +31 -0
- data/lib/google-cloud-bigtable.rb +171 -0
- data/lib/google/bigtable/admin/v2/bigtable_instance_admin_pb.rb +145 -0
- data/lib/google/bigtable/admin/v2/bigtable_instance_admin_services_pb.rb +90 -0
- data/lib/google/bigtable/admin/v2/bigtable_table_admin_pb.rb +208 -0
- data/lib/google/bigtable/admin/v2/bigtable_table_admin_services_pb.rb +154 -0
- data/lib/google/bigtable/admin/v2/common_pb.rb +30 -0
- data/lib/google/bigtable/admin/v2/instance_pb.rb +74 -0
- data/lib/google/bigtable/admin/v2/table_pb.rb +127 -0
- data/lib/google/bigtable/v2/bigtable_pb.rb +113 -0
- data/lib/google/bigtable/v2/bigtable_services_pb.rb +68 -0
- data/lib/google/bigtable/v2/data_pb.rb +156 -0
- data/lib/google/cloud/bigtable.rb +184 -0
- data/lib/google/cloud/bigtable/admin.rb +202 -0
- data/lib/google/cloud/bigtable/admin/credentials.rb +27 -0
- data/lib/google/cloud/bigtable/admin/v2.rb +223 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client.rb +1451 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_instance_admin_client_config.json +139 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client.rb +1734 -0
- data/lib/google/cloud/bigtable/admin/v2/bigtable_table_admin_client_config.json +163 -0
- data/lib/google/cloud/bigtable/admin/v2/credentials.rb +51 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_instance_admin.rb +297 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/bigtable_table_admin.rb +587 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/instance.rb +193 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/bigtable/admin/v2/table.rb +303 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/iam_policy.rb +64 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/options.rb +33 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/iam/v1/policy.rb +151 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/longrunning/operations.rb +51 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/any.rb +131 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/duration.rb +91 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/empty.rb +29 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/field_mask.rb +222 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/protobuf/timestamp.rb +113 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/rpc/status.rb +39 -0
- data/lib/google/cloud/bigtable/admin/v2/doc/google/type/expr.rb +45 -0
- data/lib/google/cloud/bigtable/app_profile.rb +439 -0
- data/lib/google/cloud/bigtable/app_profile/job.rb +99 -0
- data/lib/google/cloud/bigtable/app_profile/list.rb +165 -0
- data/lib/google/cloud/bigtable/backup.rb +324 -0
- data/lib/google/cloud/bigtable/backup/job.rb +87 -0
- data/lib/google/cloud/bigtable/backup/list.rb +167 -0
- data/lib/google/cloud/bigtable/chunk_processor.rb +241 -0
- data/lib/google/cloud/bigtable/cluster.rb +390 -0
- data/lib/google/cloud/bigtable/cluster/job.rb +88 -0
- data/lib/google/cloud/bigtable/cluster/list.rb +171 -0
- data/lib/google/cloud/bigtable/column_family.rb +73 -0
- data/lib/google/cloud/bigtable/column_family_map.rb +426 -0
- data/lib/google/cloud/bigtable/column_range.rb +194 -0
- data/lib/google/cloud/bigtable/convert.rb +83 -0
- data/lib/google/cloud/bigtable/credentials.rb +25 -0
- data/lib/google/cloud/bigtable/errors.rb +38 -0
- data/lib/google/cloud/bigtable/gc_rule.rb +334 -0
- data/lib/google/cloud/bigtable/instance.rb +935 -0
- data/lib/google/cloud/bigtable/instance/cluster_map.rb +74 -0
- data/lib/google/cloud/bigtable/instance/job.rb +98 -0
- data/lib/google/cloud/bigtable/instance/list.rb +164 -0
- data/lib/google/cloud/bigtable/longrunning_job.rb +122 -0
- data/lib/google/cloud/bigtable/mutation_entry.rb +256 -0
- data/lib/google/cloud/bigtable/mutation_operations.rb +357 -0
- data/lib/google/cloud/bigtable/policy.rb +167 -0
- data/lib/google/cloud/bigtable/project.rb +471 -0
- data/lib/google/cloud/bigtable/read_modify_write_rule.rb +134 -0
- data/lib/google/cloud/bigtable/read_operations.rb +328 -0
- data/lib/google/cloud/bigtable/routing_policy.rb +172 -0
- data/lib/google/cloud/bigtable/row.rb +136 -0
- data/lib/google/cloud/bigtable/row_filter.rb +639 -0
- data/lib/google/cloud/bigtable/row_filter/chain_filter.rb +590 -0
- data/lib/google/cloud/bigtable/row_filter/condition_filter.rb +114 -0
- data/lib/google/cloud/bigtable/row_filter/interleave_filter.rb +621 -0
- data/lib/google/cloud/bigtable/row_filter/simple_filter.rb +287 -0
- data/lib/google/cloud/bigtable/row_range.rb +179 -0
- data/lib/google/cloud/bigtable/rows_mutator.rb +113 -0
- data/lib/google/cloud/bigtable/rows_reader.rb +200 -0
- data/lib/google/cloud/bigtable/sample_row_key.rb +85 -0
- data/lib/google/cloud/bigtable/service.rb +913 -0
- data/lib/google/cloud/bigtable/status.rb +76 -0
- data/lib/google/cloud/bigtable/table.rb +686 -0
- data/lib/google/cloud/bigtable/table/cluster_state.rb +125 -0
- data/lib/google/cloud/bigtable/table/list.rb +154 -0
- data/lib/google/cloud/bigtable/table/restore_job.rb +117 -0
- data/lib/google/cloud/bigtable/v2.rb +146 -0
- data/lib/google/cloud/bigtable/v2/bigtable_client.rb +591 -0
- data/lib/google/cloud/bigtable/v2/bigtable_client_config.json +83 -0
- data/lib/google/cloud/bigtable/v2/credentials.rb +46 -0
- data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/bigtable.rb +290 -0
- data/lib/google/cloud/bigtable/v2/doc/google/bigtable/v2/data.rb +493 -0
- data/lib/google/cloud/bigtable/v2/doc/google/protobuf/any.rb +131 -0
- data/lib/google/cloud/bigtable/v2/doc/google/protobuf/wrappers.rb +34 -0
- data/lib/google/cloud/bigtable/v2/doc/google/rpc/status.rb +39 -0
- data/lib/google/cloud/bigtable/value_range.rb +181 -0
- data/lib/google/cloud/bigtable/version.rb +22 -0
- metadata +337 -0
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright 2018 Google LLC
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
module Google
|
|
19
|
+
module Cloud
|
|
20
|
+
module Bigtable
|
|
21
|
+
##
|
|
22
|
+
# # MutationEntry
|
|
23
|
+
#
|
|
24
|
+
# MutationEntry is a chainable structure that holds data for different
|
|
25
|
+
# type of mutations.
|
|
26
|
+
# MutationEntry is used in following data operations:
|
|
27
|
+
#
|
|
28
|
+
# * Mutate row. See {Google::Cloud::Bigtable::Table#mutate_row}
|
|
29
|
+
# * Mutate rows. See {Google::Cloud::Bigtable::Table#mutate_rows}
|
|
30
|
+
# * Check and mutate row using a predicate.
|
|
31
|
+
# See {Google::Cloud::Bigtable::Table#check_and_mutate_row}
|
|
32
|
+
#
|
|
33
|
+
# @example
|
|
34
|
+
# entry = Google::Cloud::Bigtable::MutationEntry.new("user-1")
|
|
35
|
+
# timestamp_micros = (Time.now.to_f * 1000000).round(-3)
|
|
36
|
+
# entry.set_cell(
|
|
37
|
+
# "cf1", "fiel01", "XYZ", timestamp: timestamp_micros
|
|
38
|
+
# ).delete_cells(
|
|
39
|
+
# "cf2",
|
|
40
|
+
# "field02",
|
|
41
|
+
# timestamp_from: timestamp_micros - 5000000,
|
|
42
|
+
# timestamp_to: timestamp_micros
|
|
43
|
+
# ).delete_from_family("cf3").delete_from_row
|
|
44
|
+
#
|
|
45
|
+
# @example Create using a table.
|
|
46
|
+
# require "google/cloud/bigtable"
|
|
47
|
+
#
|
|
48
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
49
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
50
|
+
#
|
|
51
|
+
# entry = table.new_mutation_entry("user-1")
|
|
52
|
+
# timestamp_micros = (Time.now.to_f * 1000000).round(-3)
|
|
53
|
+
# entry.set_cell(
|
|
54
|
+
# "cf1", "fiel01", "XYZ", timestamp: timestamp_micros
|
|
55
|
+
# )
|
|
56
|
+
#
|
|
57
|
+
class MutationEntry
|
|
58
|
+
attr_accessor :row_key
|
|
59
|
+
|
|
60
|
+
# @private
|
|
61
|
+
# mutations gRPC list
|
|
62
|
+
# @return [Array<Google::Bigtable::V2::Mutation>]
|
|
63
|
+
attr_accessor :mutations
|
|
64
|
+
|
|
65
|
+
##
|
|
66
|
+
# Creates a mutation entry instance.
|
|
67
|
+
#
|
|
68
|
+
# @param row_key [String]
|
|
69
|
+
#
|
|
70
|
+
def initialize row_key = nil
|
|
71
|
+
@row_key = row_key
|
|
72
|
+
@mutations = []
|
|
73
|
+
@retryable = true
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
##
|
|
77
|
+
# Adds a SetCell to the list of mutations.
|
|
78
|
+
#
|
|
79
|
+
# A SetCell is a mutation that sets the value of the specified cell.
|
|
80
|
+
#
|
|
81
|
+
# @param family [String] Table column family name.
|
|
82
|
+
# The name of the family into which new data should be written.
|
|
83
|
+
# Must match `[-_.a-zA-Z0-9]+`
|
|
84
|
+
# @param qualifier [String] Column qualifier name.
|
|
85
|
+
# The qualifier of the column into which new data should be written.
|
|
86
|
+
# 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 timestamp [Integer] Timestamp value in microseconds.
|
|
90
|
+
# The timestamp of the cell into which new data should be written.
|
|
91
|
+
# Use -1 for current Bigtable server time.
|
|
92
|
+
# Otherwise, the client should set this value itself, noting that the
|
|
93
|
+
# default value is a timestamp of zero if the field is left unspecified.
|
|
94
|
+
# Values are in microseconds but must match the granularity of the
|
|
95
|
+
# table. Therefore, if {Table#granularity} is `MILLIS` (the default),
|
|
96
|
+
# the given value must be a multiple of 1000 (millisecond
|
|
97
|
+
# granularity). For example: `1564257960168000`.
|
|
98
|
+
# @return [MutationEntry] `self` object of entry for chaining.
|
|
99
|
+
#
|
|
100
|
+
# @example
|
|
101
|
+
# entry = Google::Cloud::Bigtable::MutationEntry.new("user-1")
|
|
102
|
+
# entry.set_cell("cf1", "field01", "XYZ")
|
|
103
|
+
#
|
|
104
|
+
# @example With timestamp.
|
|
105
|
+
# entry = Google::Cloud::Bigtable::MutationEntry.new("user-1")
|
|
106
|
+
# entry.set_cell(
|
|
107
|
+
# "cf-1",
|
|
108
|
+
# "field-1",
|
|
109
|
+
# "XYZ",
|
|
110
|
+
# timestamp: (Time.now.to_f * 1000000).round(-3) # microseconds
|
|
111
|
+
# )
|
|
112
|
+
#
|
|
113
|
+
def set_cell family, qualifier, value, timestamp: nil
|
|
114
|
+
# If value is integer, covert it to a 64-bit signed big-endian integer.
|
|
115
|
+
value = [value].pack "q>" if value.is_a? Integer
|
|
116
|
+
options = {
|
|
117
|
+
family_name: family,
|
|
118
|
+
column_qualifier: qualifier,
|
|
119
|
+
value: value
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if timestamp
|
|
123
|
+
options[:timestamp_micros] = timestamp
|
|
124
|
+
@retryable = timestamp != -1
|
|
125
|
+
end
|
|
126
|
+
@mutations << Google::Bigtable::V2::Mutation.new(set_cell: options)
|
|
127
|
+
self
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
##
|
|
131
|
+
# Adds a DeleteFromColumn to the list of mutations.
|
|
132
|
+
#
|
|
133
|
+
# A DeleteFromColumn is a mutation that deletes cells from the
|
|
134
|
+
# specified column, optionally restricting the deletions to a given
|
|
135
|
+
# timestamp range.
|
|
136
|
+
#
|
|
137
|
+
# @param family [String] Table column family name.
|
|
138
|
+
# The name of the column family from which cells should be deleted.
|
|
139
|
+
# Must match `[-_.a-zA-Z0-9]+`
|
|
140
|
+
# @param qualifier [String] Column qualifier name.
|
|
141
|
+
# The qualifier of the column from which cells should be deleted.
|
|
142
|
+
# Can be any byte string, including an empty string.
|
|
143
|
+
# @param timestamp_from [Integer] Timestamp lower boundary in
|
|
144
|
+
# microseconds. Optional. Begins the range of timestamps from which
|
|
145
|
+
# cells should be deleted. Values are in microseconds but must match
|
|
146
|
+
# the granularity of the table. Therefore, if {Table#granularity} is
|
|
147
|
+
# `MILLIS` (the default), the given value must be a multiple of 1000
|
|
148
|
+
# (millisecond granularity). For example: `1564257960168000`.
|
|
149
|
+
# @param timestamp_to [Integer] Timestamp upper boundary in
|
|
150
|
+
# microseconds. Optional. Ends the range of timestamps from which
|
|
151
|
+
# cells should be deleted. Values are in microseconds but must match
|
|
152
|
+
# the granularity of the table. Therefore, if {Table#granularity} is
|
|
153
|
+
# `MILLIS` (the default), the given value must be a multiple of 1000
|
|
154
|
+
# (millisecond granularity). For example: `1564257960168000`.
|
|
155
|
+
# @return [MutationEntry] `self` object of entry for chaining.
|
|
156
|
+
#
|
|
157
|
+
# @example Without timestamp range.
|
|
158
|
+
# entry = Google::Cloud::Bigtable::MutationEntry.new("user-1")
|
|
159
|
+
# entry.delete_cells("cf-1", "field-1")
|
|
160
|
+
#
|
|
161
|
+
# @example With timestamp range.
|
|
162
|
+
# entry = Google::Cloud::Bigtable::MutationEntry.new("user-1")
|
|
163
|
+
# timestamp_micros = (Time.now.to_f * 1000000).round(-3)
|
|
164
|
+
# entry.delete_cells(
|
|
165
|
+
# "cf1",
|
|
166
|
+
# "field-1",
|
|
167
|
+
# timestamp_from: timestamp_micros - 5000000,
|
|
168
|
+
# timestamp_to: timestamp_micros
|
|
169
|
+
# )
|
|
170
|
+
# @example With timestamp range with lower boundary only.
|
|
171
|
+
# entry = Google::Cloud::Bigtable::MutationEntry.new("user-1")
|
|
172
|
+
# timestamp_micros = (Time.now.to_f * 1000000).round(-3)
|
|
173
|
+
# entry.delete_cells(
|
|
174
|
+
# "cf1",
|
|
175
|
+
# "field-1",
|
|
176
|
+
# timestamp_from: timestamp_micros - 5000000
|
|
177
|
+
# )
|
|
178
|
+
#
|
|
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
|
+
if timestamp_from || timestamp_to
|
|
182
|
+
time_range = Google::Bigtable::V2::TimestampRange.new
|
|
183
|
+
time_range.start_timestamp_micros = timestamp_from if timestamp_from
|
|
184
|
+
time_range.end_timestamp_micros = timestamp_to if timestamp_to
|
|
185
|
+
grpc.time_range = time_range
|
|
186
|
+
end
|
|
187
|
+
@mutations << Google::Bigtable::V2::Mutation.new(delete_from_column: grpc)
|
|
188
|
+
self
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
##
|
|
192
|
+
# Adds a DeleteFromFamily to the list of mutations.
|
|
193
|
+
#
|
|
194
|
+
# A DeleteFromFamily is a mutation that deletes all cells from the specified column family.
|
|
195
|
+
#
|
|
196
|
+
# @param family [String] Table column family name.
|
|
197
|
+
# The name of the column family from which cells should be deleted.
|
|
198
|
+
# Must match `[-_.a-zA-Z0-9]+`
|
|
199
|
+
# @return [MutationEntry] `self` object of entry for chaining.
|
|
200
|
+
#
|
|
201
|
+
# @example
|
|
202
|
+
# entry = Google::Cloud::Bigtable::MutationEntry.new("user-1")
|
|
203
|
+
# entry.delete_from_family("cf-1")
|
|
204
|
+
#
|
|
205
|
+
def delete_from_family family
|
|
206
|
+
@mutations << Google::Bigtable::V2::Mutation.new(delete_from_family: { family_name: family })
|
|
207
|
+
self
|
|
208
|
+
end
|
|
209
|
+
|
|
210
|
+
##
|
|
211
|
+
# Adds a DeleteFromRow to the list of mutations.
|
|
212
|
+
#
|
|
213
|
+
# A DeleteFromRow is a mutation which deletes all cells from the containing row.
|
|
214
|
+
#
|
|
215
|
+
# @return [MutationEntry] `self` object of entry for chaining.
|
|
216
|
+
#
|
|
217
|
+
# @example
|
|
218
|
+
# entry = Google::Cloud::Bigtable::MutationEntry.new("user-1")
|
|
219
|
+
# entry.delete_from_row
|
|
220
|
+
#
|
|
221
|
+
def delete_from_row
|
|
222
|
+
@mutations << Google::Bigtable::V2::Mutation.new(delete_from_row: {})
|
|
223
|
+
self
|
|
224
|
+
end
|
|
225
|
+
|
|
226
|
+
##
|
|
227
|
+
# If the mutation entry is retryable or not based on set_cell value.
|
|
228
|
+
#
|
|
229
|
+
# @return [Boolean]
|
|
230
|
+
#
|
|
231
|
+
def retryable?
|
|
232
|
+
@retryable
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
##
|
|
236
|
+
# The number of mutations.
|
|
237
|
+
#
|
|
238
|
+
# @return [Integer]
|
|
239
|
+
#
|
|
240
|
+
def length
|
|
241
|
+
@mutations.length
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
# @private
|
|
245
|
+
#
|
|
246
|
+
# Convert mutation entry to gRPC protobuf object.
|
|
247
|
+
#
|
|
248
|
+
# @return [Google::Bigtable::V2::MutateRowsRequest::Entry]
|
|
249
|
+
#
|
|
250
|
+
def to_grpc
|
|
251
|
+
Google::Bigtable::V2::MutateRowsRequest::Entry.new row_key: @row_key, mutations: @mutations
|
|
252
|
+
end
|
|
253
|
+
end
|
|
254
|
+
end
|
|
255
|
+
end
|
|
256
|
+
end
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Copyright 2018 Google LLC
|
|
4
|
+
#
|
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
# you may not use this file except in compliance with the License.
|
|
7
|
+
# You may obtain a copy of the License at
|
|
8
|
+
#
|
|
9
|
+
# https:#www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
#
|
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
# See the License for the specific language governing permissions and
|
|
15
|
+
# limitations under the License.
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
require "google/cloud/bigtable/mutation_entry"
|
|
19
|
+
require "google/cloud/bigtable/row"
|
|
20
|
+
require "google/cloud/bigtable/rows_mutator"
|
|
21
|
+
require "google/cloud/bigtable/read_modify_write_rule"
|
|
22
|
+
require "google/cloud/bigtable/status"
|
|
23
|
+
|
|
24
|
+
module Google
|
|
25
|
+
module Cloud
|
|
26
|
+
module Bigtable
|
|
27
|
+
##
|
|
28
|
+
# # MutationOperations
|
|
29
|
+
#
|
|
30
|
+
# Collection of mutations APIs.
|
|
31
|
+
#
|
|
32
|
+
# * Mutate single row
|
|
33
|
+
# * Mutate multiple rows
|
|
34
|
+
# * Read modify and write row atomically on the server
|
|
35
|
+
# * Check and mutate row
|
|
36
|
+
#
|
|
37
|
+
module MutationOperations
|
|
38
|
+
##
|
|
39
|
+
# Mutates a row atomically. Cells in the row are left
|
|
40
|
+
# unchanged unless explicitly changed by the mutations.
|
|
41
|
+
# Changes to be atomically applied to the specified row. Entries are applied
|
|
42
|
+
# in order, meaning that earlier mutations can be masked by later mutations.
|
|
43
|
+
# Must contain at least one mutation and at most 100,000.
|
|
44
|
+
#
|
|
45
|
+
# @param entry [Google::Cloud::Bigtable::MutationEntry]
|
|
46
|
+
# Mutation entry with row key and list of mutations.
|
|
47
|
+
# @return [Boolean]
|
|
48
|
+
# @example Single mutation on row.
|
|
49
|
+
# require "google/cloud/bigtable"
|
|
50
|
+
#
|
|
51
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
52
|
+
#
|
|
53
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
54
|
+
#
|
|
55
|
+
# entry = table.new_mutation_entry("user-1")
|
|
56
|
+
# entry.set_cell("cf1", "field1", "XYZ")
|
|
57
|
+
# table.mutate_row(entry)
|
|
58
|
+
#
|
|
59
|
+
# @example Multiple mutations on row.
|
|
60
|
+
# require "google/cloud/bigtable"
|
|
61
|
+
#
|
|
62
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
63
|
+
#
|
|
64
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
65
|
+
#
|
|
66
|
+
# entry = table.new_mutation_entry("user-1")
|
|
67
|
+
# entry.set_cell(
|
|
68
|
+
# "cf-1",
|
|
69
|
+
# "field-1",
|
|
70
|
+
# "XYZ",
|
|
71
|
+
# timestamp: (Time.now.to_f * 1000000).round(-3) # microseconds
|
|
72
|
+
# ).delete_cells("cf2", "field02")
|
|
73
|
+
#
|
|
74
|
+
# table.mutate_row(entry)
|
|
75
|
+
#
|
|
76
|
+
def mutate_row entry
|
|
77
|
+
service.mutate_row path, entry.row_key, entry.mutations, app_profile_id: @app_profile_id
|
|
78
|
+
true
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
##
|
|
82
|
+
# Mutates multiple rows in a batch. Each individual row is mutated
|
|
83
|
+
# atomically as in #{mutate_row}, but the entire batch is not executed
|
|
84
|
+
# atomically.
|
|
85
|
+
#
|
|
86
|
+
# @param entries [Array<Google::Cloud::Bigtable::MutationEntry>]
|
|
87
|
+
# The row keys and corresponding mutations to be applied in bulk.
|
|
88
|
+
# Each entry is applied as an atomic mutation, but the entries may be
|
|
89
|
+
# applied in arbitrary order (even between entries for the same row).
|
|
90
|
+
# At least one entry must be specified, and in total the entries can
|
|
91
|
+
# contain a maximum of 100,000 mutations.
|
|
92
|
+
# @return [Array<Google::Bigtable::V2::MutateRowsResponse::Entry>]
|
|
93
|
+
#
|
|
94
|
+
# @example
|
|
95
|
+
# require "google/cloud/bigtable"
|
|
96
|
+
#
|
|
97
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
98
|
+
#
|
|
99
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
100
|
+
#
|
|
101
|
+
# entries = []
|
|
102
|
+
# entries << table.new_mutation_entry("row-1").set_cell("cf1", "field1", "XYZ")
|
|
103
|
+
# entries << table.new_mutation_entry("row-2").set_cell("cf1", "field1", "ABC")
|
|
104
|
+
# responses = table.mutate_rows(entries)
|
|
105
|
+
#
|
|
106
|
+
# responses.each do |response|
|
|
107
|
+
# puts response.status.description
|
|
108
|
+
# end
|
|
109
|
+
#
|
|
110
|
+
def mutate_rows entries
|
|
111
|
+
statuses = RowsMutator.new(self, entries).apply_mutations
|
|
112
|
+
statuses.map { |s| Response.from_grpc s }
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
##
|
|
116
|
+
# Modifies a row atomically on the server. The method reads the latest
|
|
117
|
+
# existing timestamp and value from the specified columns and writes a new
|
|
118
|
+
# entry based on pre-defined read/modify/write rules. The new value for the
|
|
119
|
+
# timestamp is the greater of the existing timestamp or the current server
|
|
120
|
+
# time. The method returns the new contents of all modified cells.
|
|
121
|
+
#
|
|
122
|
+
# @param key [String]
|
|
123
|
+
# The row key of the row to which the read/modify/write rules should be applied.
|
|
124
|
+
# @param rules [Google::Cloud::Bigtable::ReadModifyWriteRule,
|
|
125
|
+
# Array<Google::Cloud::Bigtable::ReadModifyWriteRule>]
|
|
126
|
+
# Rules specifying how the specified row's contents are to be transformed
|
|
127
|
+
# into writes. Entries are applied in order, meaning that earlier rules will
|
|
128
|
+
# affect the results of later ones.
|
|
129
|
+
# @return [Google::Cloud::Bigtable::Row]
|
|
130
|
+
# @example Apply multiple modification rules.
|
|
131
|
+
# require "google/cloud/bigtable"
|
|
132
|
+
#
|
|
133
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
134
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
135
|
+
#
|
|
136
|
+
# rule_1 = table.new_read_modify_write_rule("cf", "field01")
|
|
137
|
+
# rule_1.append("append-xyz")
|
|
138
|
+
#
|
|
139
|
+
# rule_2 = table.new_read_modify_write_rule("cf", "field01")
|
|
140
|
+
# rule_2.increment(1)
|
|
141
|
+
#
|
|
142
|
+
# row = table.read_modify_write_row("user01", [rule_1, rule_2])
|
|
143
|
+
#
|
|
144
|
+
# puts row.cells
|
|
145
|
+
#
|
|
146
|
+
# @example Apply single modification rules.
|
|
147
|
+
# require "google/cloud/bigtable"
|
|
148
|
+
#
|
|
149
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
150
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
151
|
+
#
|
|
152
|
+
# rule = table.new_read_modify_write_rule("cf", "field01").append("append-xyz")
|
|
153
|
+
#
|
|
154
|
+
# row = table.read_modify_write_row("user01", rule)
|
|
155
|
+
#
|
|
156
|
+
# puts row.cells
|
|
157
|
+
#
|
|
158
|
+
def read_modify_write_row key, rules
|
|
159
|
+
res_row = service.read_modify_write_row(
|
|
160
|
+
path,
|
|
161
|
+
key,
|
|
162
|
+
Array(rules).map(&:to_grpc),
|
|
163
|
+
app_profile_id: @app_profile_id
|
|
164
|
+
).row
|
|
165
|
+
row = Row.new res_row.key
|
|
166
|
+
|
|
167
|
+
res_row.families.each do |family|
|
|
168
|
+
family.columns.each do |column|
|
|
169
|
+
column.cells.each do |cell|
|
|
170
|
+
row_cell = Row::Cell.new(
|
|
171
|
+
family.name,
|
|
172
|
+
column.qualifier,
|
|
173
|
+
cell.timestamp_micros,
|
|
174
|
+
cell.value,
|
|
175
|
+
cell.labels
|
|
176
|
+
)
|
|
177
|
+
row.cells[family.name] << row_cell
|
|
178
|
+
end
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
row
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
##
|
|
185
|
+
# Mutates a row atomically based on the output of a predicate reader filter.
|
|
186
|
+
#
|
|
187
|
+
# NOTE: Condition predicate filter is not supported.
|
|
188
|
+
#
|
|
189
|
+
# @param key [String] Row key.
|
|
190
|
+
# The row key of the row to which the conditional mutation should be applied.
|
|
191
|
+
# @param predicate [SimpleFilter, ChainFilter, InterleaveFilter] Predicate filter.
|
|
192
|
+
# The filter to be applied to the contents of the specified row. Depending
|
|
193
|
+
# on whether or not any results are yielded, either +true_mutations+ or
|
|
194
|
+
# +false_mutations+ will be executed. If unset, checks that the row contains
|
|
195
|
+
# any values.
|
|
196
|
+
# @param on_match [Google::Cloud::Bigtable::MutationEntry] Mutation entry
|
|
197
|
+
# applied to predicate filter match.
|
|
198
|
+
# Changes to be atomically applied to the specified row if +predicate_filter+
|
|
199
|
+
# yields at least one cell when applied to +row_key+. Entries are applied in
|
|
200
|
+
# order, meaning that earlier mutations can be masked by later ones.
|
|
201
|
+
# Must contain at least one entry if +false_mutations+ is empty and at most
|
|
202
|
+
# 100,000 entries.
|
|
203
|
+
# @param otherwise [Google::Cloud::Bigtable::MutationEntry] Mutation entry applied
|
|
204
|
+
# when predicate filter does not match.
|
|
205
|
+
# Changes to be atomically applied to the specified row if +predicate_filter+
|
|
206
|
+
# does not yield any cells when applied to +row_key+. Entries are applied in
|
|
207
|
+
# order, meaning that earlier mutations can be masked by later ones.
|
|
208
|
+
# Must contain at least one entry if +true_mutations+ is empty and at most
|
|
209
|
+
# 100,000 entries.
|
|
210
|
+
# @return [Boolean]
|
|
211
|
+
# Predicate match or not status.
|
|
212
|
+
#
|
|
213
|
+
# @example
|
|
214
|
+
# require "google/cloud/bigtable"
|
|
215
|
+
#
|
|
216
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
217
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
218
|
+
#
|
|
219
|
+
# predicate_filter = Google::Cloud::Bigtable::RowFilter.key("user-10")
|
|
220
|
+
# on_match_mutations = Google::Cloud::Bigtable::MutationEntry.new
|
|
221
|
+
# on_match_mutations.set_cell(
|
|
222
|
+
# "cf-1",
|
|
223
|
+
# "field-1",
|
|
224
|
+
# "XYZ",
|
|
225
|
+
# timestamp: (Time.now.to_f * 1000000).round(-3) # microseconds
|
|
226
|
+
# ).delete_cells("cf2", "field02")
|
|
227
|
+
#
|
|
228
|
+
# otherwise_mutations = Google::Cloud::Bigtable::MutationEntry.new
|
|
229
|
+
# otherwise_mutations.delete_from_family("cf3")
|
|
230
|
+
#
|
|
231
|
+
# predicate_matched = table.check_and_mutate_row(
|
|
232
|
+
# "user01",
|
|
233
|
+
# predicate_filter,
|
|
234
|
+
# on_match: on_match_mutations,
|
|
235
|
+
# otherwise: otherwise_mutations
|
|
236
|
+
# )
|
|
237
|
+
#
|
|
238
|
+
# if predicate_matched
|
|
239
|
+
# puts "All predicates matched"
|
|
240
|
+
# end
|
|
241
|
+
#
|
|
242
|
+
def check_and_mutate_row key, predicate, on_match: nil, otherwise: nil
|
|
243
|
+
true_mutations = on_match.mutations if on_match
|
|
244
|
+
false_mutations = otherwise.mutations if otherwise
|
|
245
|
+
response = service.check_and_mutate_row(
|
|
246
|
+
path,
|
|
247
|
+
key,
|
|
248
|
+
predicate_filter: predicate.to_grpc,
|
|
249
|
+
true_mutations: true_mutations,
|
|
250
|
+
false_mutations: false_mutations,
|
|
251
|
+
app_profile_id: @app_profile_id
|
|
252
|
+
)
|
|
253
|
+
response.predicate_matched
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
##
|
|
257
|
+
# Creates a mutation entry instance.
|
|
258
|
+
#
|
|
259
|
+
# @param row_key [String] Row key. Optional.
|
|
260
|
+
# The row key of the row to which the mutation should be applied.
|
|
261
|
+
# @return [Google::Cloud::Bigtable::MutationEntry]
|
|
262
|
+
#
|
|
263
|
+
# @example
|
|
264
|
+
# require "google/cloud/bigtable"
|
|
265
|
+
#
|
|
266
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
267
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
268
|
+
#
|
|
269
|
+
# entry = table.new_mutation_entry("row-key-1")
|
|
270
|
+
#
|
|
271
|
+
# # Without row key
|
|
272
|
+
# entry = table.new_mutation_entry
|
|
273
|
+
#
|
|
274
|
+
def new_mutation_entry row_key = nil
|
|
275
|
+
Google::Cloud::Bigtable::MutationEntry.new row_key
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
##
|
|
279
|
+
# Create a read/modify/write rule to append or increment the value
|
|
280
|
+
# of the cell qualifier.
|
|
281
|
+
#
|
|
282
|
+
# @param family [String]
|
|
283
|
+
# The name of the column family to which the read/modify/write rule should be applied.
|
|
284
|
+
# @param qualifier [String]
|
|
285
|
+
# The qualifier of the column to which the read/modify/write rule should be applied.
|
|
286
|
+
# @return [Google::Cloud::Bigtable::ReadModifyWriteRule]
|
|
287
|
+
#
|
|
288
|
+
# @example Create rule to append to qualifier value.
|
|
289
|
+
# require "google/cloud/bigtable"
|
|
290
|
+
#
|
|
291
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
292
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
293
|
+
# rule = table.new_read_modify_write_rule("cf", "qualifier-1")
|
|
294
|
+
# rule.append("append-xyz")
|
|
295
|
+
#
|
|
296
|
+
# @example Create rule to increment qualifier value.
|
|
297
|
+
# require "google/cloud/bigtable"
|
|
298
|
+
#
|
|
299
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
300
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
301
|
+
# rule = table.new_read_modify_write_rule("cf", "qualifier-1")
|
|
302
|
+
# rule.increment(100)
|
|
303
|
+
#
|
|
304
|
+
def new_read_modify_write_rule family, qualifier
|
|
305
|
+
Google::Cloud::Bigtable::ReadModifyWriteRule.new family, qualifier
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
##
|
|
309
|
+
# # MutationEntry::Response
|
|
310
|
+
#
|
|
311
|
+
# Represents a response message from BigtableService.MutateRows.
|
|
312
|
+
#
|
|
313
|
+
# @attr [Integer] index The index into the original request's `entries`
|
|
314
|
+
# list of the Entry for which a result is being reported.
|
|
315
|
+
# @attr [Google::Cloud::Bigtable::Status] The result of the request
|
|
316
|
+
# Entry identified by `index`. Depending on how requests are batched
|
|
317
|
+
# during execution, it is possible for one Entry to fail due to an
|
|
318
|
+
# error with another Entry. In the event that this occurs, the same
|
|
319
|
+
# error will be reported for both entries.
|
|
320
|
+
#
|
|
321
|
+
# @example
|
|
322
|
+
# require "google/cloud/bigtable"
|
|
323
|
+
#
|
|
324
|
+
# bigtable = Google::Cloud::Bigtable.new
|
|
325
|
+
#
|
|
326
|
+
# table = bigtable.table("my-instance", "my-table")
|
|
327
|
+
#
|
|
328
|
+
# entries = []
|
|
329
|
+
# entries << table.new_mutation_entry("row-1").set_cell("cf1", "field1", "XYZ")
|
|
330
|
+
# entries << table.new_mutation_entry("row-2").set_cell("cf1", "field1", "ABC")
|
|
331
|
+
# responses = table.mutate_rows(entries)
|
|
332
|
+
#
|
|
333
|
+
# responses.each do |response|
|
|
334
|
+
# puts response.status.description
|
|
335
|
+
# end
|
|
336
|
+
#
|
|
337
|
+
class Response
|
|
338
|
+
attr_reader :index, :status
|
|
339
|
+
|
|
340
|
+
##
|
|
341
|
+
# @private Creates a MutationEntry::Response object.
|
|
342
|
+
def initialize index, status
|
|
343
|
+
@index = index
|
|
344
|
+
@status = status
|
|
345
|
+
end
|
|
346
|
+
|
|
347
|
+
##
|
|
348
|
+
# @private New MutationEntry::Response from a
|
|
349
|
+
# Google::Bigtable::V2::MutateRowsResponse::Entry object.
|
|
350
|
+
def self.from_grpc grpc
|
|
351
|
+
new grpc.index, Status.from_grpc(grpc.status)
|
|
352
|
+
end
|
|
353
|
+
end
|
|
354
|
+
end
|
|
355
|
+
end
|
|
356
|
+
end
|
|
357
|
+
end
|