Module: Google::Cloud::Bigtable::MutationOperations
- Included in:
- Table
- Defined in:
- lib/google/cloud/bigtable/mutation_operations.rb
Overview
MutationOperations
Collection of mutations APIs.
- Mutate single row
- Mutate multiple rows
- Read modify and write row atomically on the server
- Check and mutate row
Defined Under Namespace
Classes: Response
Instance Method Summary collapse
-
#check_and_mutate_row(key, predicate, on_match: nil, otherwise: nil) ⇒ Boolean
Mutates a row atomically based on the output of a predicate reader filter.
-
#mutate_row(entry) ⇒ Boolean
Mutate row.
-
#mutate_rows(entries) ⇒ Array<Google::Bigtable::V2::MutateRowsResponse::Entry>
Mutates multiple rows in a batch.
-
#new_mutation_entry(row_key = nil) ⇒ Google::Cloud::Bigtable::MutationEntry
Create an instance of mutation_entry.
-
#new_read_modify_write_rule(family, qualifier) ⇒ Google::Cloud::Bigtable::ReadModifyWriteRule
Create an instance of ReadModifyWriteRule to append or increment the value of the cell qualifier.
-
#read_modify_write_row(key, rules) ⇒ Google::Cloud::Bigtable::Row
Modifies a row atomically on the server.
-
#sample_row_keys ⇒ :yields: sample_row_key
Read sample row keys.
Instance Method Details
#check_and_mutate_row(key, predicate, on_match: nil, otherwise: nil) ⇒ Boolean
Mutates a row atomically based on the output of a predicate reader filter.
NOTE: Condition predicate filter is not supported.
243 244 245 246 247 248 249 250 251 252 253 254 255 |
# File 'lib/google/cloud/bigtable/mutation_operations.rb', line 243 def check_and_mutate_row key, predicate, on_match: nil, otherwise: nil true_mutations = on_match.mutations if on_match false_mutations = otherwise.mutations if otherwise response = client.check_and_mutate_row( path, key, predicate_filter: predicate.to_grpc, true_mutations: true_mutations, false_mutations: false_mutations, app_profile_id: @app_profile_id ) response.predicate_matched end |
#mutate_row(entry) ⇒ Boolean
Mutate row.
Mutates a row atomically. Cells in the row are left unchanged unless explicitly changed by +mutation+. Changes to be atomically applied to the specified row. Entries are applied in order, meaning that earlier mutations can be masked by later mutations. Must contain at least one mutation entry and at most 100,000.
78 79 80 81 |
# File 'lib/google/cloud/bigtable/mutation_operations.rb', line 78 def mutate_row entry client.mutate_row path, entry.row_key, entry.mutations, app_profile_id: @app_profile_id true end |
#mutate_rows(entries) ⇒ Array<Google::Bigtable::V2::MutateRowsResponse::Entry>
Mutates multiple rows in a batch. Each individual row is mutated atomically as in MutateRow, but the entire batch is not executed atomically.
112 113 114 115 |
# File 'lib/google/cloud/bigtable/mutation_operations.rb', line 112 def mutate_rows entries statuses = RowsMutator.new(self, entries).apply_mutations statuses.map { |s| Response.from_grpc s } end |
#new_mutation_entry(row_key = nil) ⇒ Google::Cloud::Bigtable::MutationEntry
Create an instance of mutation_entry
310 311 312 |
# File 'lib/google/cloud/bigtable/mutation_operations.rb', line 310 def new_mutation_entry row_key = nil Google::Cloud::Bigtable::MutationEntry.new row_key end |
#new_read_modify_write_rule(family, qualifier) ⇒ Google::Cloud::Bigtable::ReadModifyWriteRule
Create an instance of ReadModifyWriteRule to append or increment the value of the cell qualifier.
340 341 342 |
# File 'lib/google/cloud/bigtable/mutation_operations.rb', line 340 def new_read_modify_write_rule family, qualifier Google::Cloud::Bigtable::ReadModifyWriteRule.new family, qualifier end |
#read_modify_write_row(key, rules) ⇒ Google::Cloud::Bigtable::Row
Modifies a row atomically on the server. The method reads the latest existing timestamp and value from the specified columns and writes a new entry based on pre-defined read/modify/write rules. The new value for the timestamp is the greater of the existing timestamp or the current server time. The method returns the new contents of all modified cells.
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/google/cloud/bigtable/mutation_operations.rb', line 160 def read_modify_write_row key, rules res_row = client.read_modify_write_row( path, key, Array(rules).map(&:to_grpc), app_profile_id: @app_profile_id ).row row = Row.new res_row.key res_row.families.each do |family| family.columns.each do |column| column.cells.each do |cell| row_cell = Row::Cell.new( family.name, column.qualifier, cell., cell.value, cell.labels ) row.cells[family.name] << row_cell end end end row end |
#sample_row_keys ⇒ :yields: sample_row_key
Read sample row keys.
Returns a sample of row keys in the table. The returned row keys will delimit contiguous sections of the table of approximately equal size. The sections can be used to break up the data for distributed tasks like MapReduces.
280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/google/cloud/bigtable/mutation_operations.rb', line 280 def sample_row_keys return enum_for :sample_row_keys unless block_given? response = client.sample_row_keys( path, app_profile_id: @app_profile_id ) response.each do |grpc| yield SampleRowKey.from_grpc grpc end end |