Class: Google::Cloud::Bigtable::Table
- Inherits:
-
Object
- Object
- Google::Cloud::Bigtable::Table
- Includes:
- MutationOperations, ReadOperations
- Defined in:
- lib/google/cloud/bigtable/table.rb,
lib/google/cloud/bigtable/table/list.rb,
lib/google/cloud/bigtable/table/cluster_state.rb,
lib/google/cloud/bigtable/table/column_family_map.rb
Overview
Table
A collection of user data indexed by row, column, and timestamp. Each table is served using the resources of its parent cluster.
Defined Under Namespace
Classes: ClusterState, ColumnFamilyMap, List
Instance Attribute Summary collapse
-
#app_profile_id ⇒ String
App profile id for request routing.
Instance Method Summary collapse
-
#check_and_mutate_row(key, predicate, on_match: nil, otherwise: nil) ⇒ Boolean
included
from MutationOperations
Mutates a row atomically based on the output of a predicate Reader filter.
-
#check_consistency(token) ⇒ Boolean
Checks replication consistency based on a consistency token, that is, if replication has caught up based on the conditions specified in the token and the check request.
-
#cluster_states ⇒ Array<Google::Cloud::Bigtable::Table::ClusterState>
Map from cluster ID to per-cluster table state.
-
#column_families ⇒ Array<Google::Bigtable::ColumnFamily>
The column families configured for this table, mapped by column family ID.
-
#column_family(name, gc_rule = nil) ⇒ Object
Create column family object to perform create,update or delete operation.
-
#delete ⇒ Boolean
Permanently deletes the table from a instance.
-
#delete_all_rows(timeout: nil) ⇒ Boolean
Delete all rows.
-
#delete_rows_by_prefix(prefix, timeout: nil) ⇒ Boolean
Delete rows using row key prefix.
-
#drop_row_range(row_key_prefix: nil, delete_all_data: nil, timeout: nil) ⇒ Boolean
Drop row range by row key prefix or delete all.
-
#exists? ⇒ Boolean
Check table existence.
-
#filter ⇒ Google::Cloud::Bigtable::RowRange
included
from ReadOperations
Get row filter.
-
#generate_consistency_token ⇒ String
Generates a consistency token for a Table, which can be used in CheckConsistency to check whether mutations to the table that finished before this call started have been replicated.
-
#granularity ⇒ Symbol
The granularity (e.g.
MILLIS
,MICROS
) at which timestamps are stored in this table. -
#granularity_millis? ⇒ Boolean
The table keeps data versioned at a granularity of 1ms.
-
#instance_id ⇒ String
The unique identifier for the instance.
-
#modify_column_families(modifications) ⇒ Google::Cloud::Bigtable::Table
Apply multitple column modifications Performs a series of column family modifications on the specified table.
-
#mutate_row(entry) ⇒ Boolean
included
from MutationOperations
Mutate row.
-
#mutate_rows(entries) ⇒ Array<Google::Bigtable::V2::MutateRowsResponse::Entry>
included
from MutationOperations
Mutates multiple rows in a batch.
-
#name ⇒ String
(also: #table_id)
The unique identifier for the table.
-
#new_column_range(family) ⇒ Google::Cloud::Bigtable::ColumnRange
included
from ReadOperations
Get new instance of ColumnRange.
-
#new_mutation_entry(row_key = nil) ⇒ Google::Cloud::Bigtable::MutationEntry
included
from MutationOperations
Create instance of mutation_entry.
-
#new_read_modify_write_rule(family, qualifier) ⇒ Google::Cloud::Bigtable::ReadModifyWriteRule
included
from MutationOperations
Create instance of ReadModifyWriteRule to append or increment value of the cell qualifier.
-
#new_row_range ⇒ Google::Cloud::Bigtable::RowRange
included
from ReadOperations
Get new instance of RowRange.
-
#new_value_range ⇒ Google::Cloud::Bigtable::ValueRange
included
from ReadOperations
Create new instance of ValueRange.
-
#path ⇒ String
The full path for the table resource.
-
#project_id ⇒ String
The unique identifier for the project.
-
#read_modify_write_row(key, rules) ⇒ Google::Cloud::Bigtable::Row
included
from MutationOperations
Modifies a row atomically on the server.
-
#read_row(key, filter: nil) ⇒ Google::Cloud::Bigtable::Row
included
from ReadOperations
Read single row by key.
-
#read_rows(keys: nil, ranges: nil, filter: nil, limit: nil, &block) ⇒ Array<Google::Cloud::Bigtable::Row> | :yields: row
included
from ReadOperations
Read rows.
-
#reload!(view: nil) ⇒ Google::Cloud::Bigtable::Table
Reload table information.
-
#sample_row_keys ⇒ :yields: sample_row_key
included
from ReadOperations
Read sample row keys.
-
#wait_for_replication(timeout: 600, check_interval: 5) ⇒ Boolean
Wait for replication to check replication consistency of table Checks replication consistency by generating consistency token and calling +check_consistency+ api call 5 times(default).
Instance Attribute Details
#app_profile_id ⇒ String
Returns App profile id for request routing.
68 69 70 |
# File 'lib/google/cloud/bigtable/table.rb', line 68 def app_profile_id @app_profile_id end |
Instance Method Details
#check_and_mutate_row(key, predicate, on_match: nil, otherwise: nil) ⇒ Boolean Originally defined in module MutationOperations
Mutates a row atomically based on the output of a predicate Reader filter.
NOTE: Condition predicate filter is not supported.
#check_consistency(token) ⇒ Boolean
Checks replication consistency based on a consistency token, that is, if replication has caught up based on the conditions specified in the token and the check request.
464 465 466 467 468 |
# File 'lib/google/cloud/bigtable/table.rb', line 464 def check_consistency token ensure_service! response = service.check_consistency(instance_id, name, token) response.consistent end |
#cluster_states ⇒ Array<Google::Cloud::Bigtable::Table::ClusterState>
Map from cluster ID to per-cluster table state.
If it could not be determined whether or not the table has data in a
particular cluster (for example, if its zone is unavailable), then
there will be an entry for the cluster with UNKNOWN replication_status
.
Views: FULL
135 136 137 138 139 140 |
# File 'lib/google/cloud/bigtable/table.rb', line 135 def cluster_states check_view_and_load(:REPLICATION_VIEW) @grpc.cluster_states.map do |name, state_grpc| ClusterState.from_grpc(state_grpc, name) end end |
#column_families ⇒ Array<Google::Bigtable::ColumnFamily>
The column families configured for this table, mapped by column family ID.
Available column families data only in table view types: SCHEMA_VIEW
, FULL
148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/google/cloud/bigtable/table.rb', line 148 def column_families check_view_and_load(:SCHEMA_VIEW) @grpc.column_families.map do |cf_name, cf_grpc| ColumnFamily.from_grpc( cf_grpc, service, name: cf_name, instance_id: instance_id, table_id: table_id ) end end |
#column_family(name, gc_rule = nil) ⇒ Object
Create column family object to perform create,update or delete operation.
281 282 283 284 285 286 287 288 289 290 291 292 |
# File 'lib/google/cloud/bigtable/table.rb', line 281 def column_family name, gc_rule = nil cf_grpc = Google::Bigtable::Admin::V2::ColumnFamily.new cf_grpc.gc_rule = gc_rule.to_grpc if gc_rule ColumnFamily.from_grpc( cf_grpc, service, name: name, instance_id: instance_id, table_id: table_id ) end |
#delete ⇒ Boolean
Permanently deletes the table from a instance.
193 194 195 196 197 |
# File 'lib/google/cloud/bigtable/table.rb', line 193 def delete ensure_service! service.delete_table(instance_id, name) true end |
#delete_all_rows(timeout: nil) ⇒ Boolean
Delete all rows
547 548 549 |
# File 'lib/google/cloud/bigtable/table.rb', line 547 def delete_all_rows timeout: nil drop_row_range(delete_all_data: true, timeout: timeout) end |
#delete_rows_by_prefix(prefix, timeout: nil) ⇒ Boolean
Delete rows using row key prefix.
568 569 570 |
# File 'lib/google/cloud/bigtable/table.rb', line 568 def delete_rows_by_prefix prefix, timeout: nil drop_row_range(row_key_prefix: prefix, timeout: timeout) end |
#drop_row_range(row_key_prefix: nil, delete_all_data: nil, timeout: nil) ⇒ Boolean
Drop row range by row key prefix or delete all.
591 592 593 594 595 596 597 598 599 600 601 602 603 604 |
# File 'lib/google/cloud/bigtable/table.rb', line 591 def drop_row_range \ row_key_prefix: nil, delete_all_data: nil, timeout: nil ensure_service! service.drop_row_range( instance_id, name, row_key_prefix: row_key_prefix, delete_all_data_from_table: delete_all_data, timeout: timeout ) true end |
#exists? ⇒ Boolean
Check table existence.
231 232 233 234 235 |
# File 'lib/google/cloud/bigtable/table.rb', line 231 def exists? !service.get_table(instance_id, name, view: :NAME_ONLY).nil? rescue Google::Cloud::NotFoundError false end |
#filter ⇒ Google::Cloud::Bigtable::RowRange Originally defined in module ReadOperations
Get row filter
#generate_consistency_token ⇒ String
Generates a consistency token for a Table, which can be used in CheckConsistency to check whether mutations to the table that finished before this call started have been replicated. The tokens will be available for 90 days.
438 439 440 441 442 |
# File 'lib/google/cloud/bigtable/table.rb', line 438 def generate_consistency_token ensure_service! response = service.generate_consistency_token(instance_id, name) response.consistency_token end |
#granularity ⇒ Symbol
The granularity (e.g. MILLIS
, MICROS
) at which timestamps are stored in
this table. Timestamps not matching the granularity will be rejected.
If unspecified at creation time, the value will be set to MILLIS
.
Views: SCHEMA_VIEW
, FULL
168 169 170 171 |
# File 'lib/google/cloud/bigtable/table.rb', line 168 def granularity check_view_and_load(:SCHEMA_VIEW) @grpc.granularity end |
#granularity_millis? ⇒ Boolean
The table keeps data versioned at a granularity of 1ms.
177 178 179 |
# File 'lib/google/cloud/bigtable/table.rb', line 177 def granularity_millis? granularity == :MILLIS end |
#instance_id ⇒ String
The unique identifier for the instance.
89 90 91 |
# File 'lib/google/cloud/bigtable/table.rb', line 89 def instance_id @grpc.name.split("/")[3] end |
#modify_column_families(modifications) ⇒ Google::Cloud::Bigtable::Table
Apply multitple column modifications Performs a series of column family modifications on the specified table. Either all or none of the modifications will occur before this method returns, but data requests received prior to that point may see a table where only some modifications have taken effect.
341 342 343 344 345 346 347 348 349 |
# File 'lib/google/cloud/bigtable/table.rb', line 341 def modify_column_families modifications ensure_service! self.class.modify_column_families( service, instance_id, table_id, modifications ) end |
#mutate_row(entry) ⇒ Boolean Originally defined in module MutationOperations
Mutate row.
Mutates a row atomically. Cells already present 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 ones. Must contain at least one mutation entry and at most 100000.
#mutate_rows(entries) ⇒ Array<Google::Bigtable::V2::MutateRowsResponse::Entry> Originally defined in module MutationOperations
Mutates multiple rows in a batch. Each individual row is mutated atomically as in MutateRow, but the entire batch is not executed atomically.
#name ⇒ String Also known as: table_id
The unique identifier for the table.
96 97 98 |
# File 'lib/google/cloud/bigtable/table.rb', line 96 def name @grpc.name.split("/")[5] end |
#new_column_range(family) ⇒ Google::Cloud::Bigtable::ColumnRange Originally defined in module ReadOperations
Get new instance of ColumnRange.
#new_mutation_entry(row_key = nil) ⇒ Google::Cloud::Bigtable::MutationEntry Originally defined in module MutationOperations
Create instance of mutation_entry
#new_read_modify_write_rule(family, qualifier) ⇒ Google::Cloud::Bigtable::ReadModifyWriteRule Originally defined in module MutationOperations
Create instance of ReadModifyWriteRule to append or increment value of the cell qualifier.
#new_row_range ⇒ Google::Cloud::Bigtable::RowRange Originally defined in module ReadOperations
Get new instance of RowRange.
#new_value_range ⇒ Google::Cloud::Bigtable::ValueRange Originally defined in module ReadOperations
Create new instance of ValueRange.
#path ⇒ String
The full path for the table resource. Values are of the form
projects/<project_id>/instances/<instance_id>/table/<table_id>
.
105 106 107 |
# File 'lib/google/cloud/bigtable/table.rb', line 105 def path @grpc.name end |
#project_id ⇒ String
The unique identifier for the project.
82 83 84 |
# File 'lib/google/cloud/bigtable/table.rb', line 82 def project_id @grpc.name.split("/")[1] end |
#read_modify_write_row(key, rules) ⇒ Google::Cloud::Bigtable::Row Originally defined in module MutationOperations
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.
#read_row(key, filter: nil) ⇒ Google::Cloud::Bigtable::Row Originally defined in module ReadOperations
Read single row by key
#read_rows(keys: nil, ranges: nil, filter: nil, limit: nil, &block) ⇒ Array<Google::Cloud::Bigtable::Row> | :yields: row Originally defined in module ReadOperations
Read rows
Streams back the contents of all requested rows in key order, optionally
applying the same Reader filter to each.
read_rows
, row_ranges
and filter
if not specified, reads from all rows.
See Google::Cloud::Bigtable::RowFilter for filter types.
#reload!(view: nil) ⇒ Google::Cloud::Bigtable::Table
Reload table information.
122 123 124 125 126 |
# File 'lib/google/cloud/bigtable/table.rb', line 122 def reload! view: nil @view = view || :SCHEMA_VIEW @grpc = service.get_table(instance_id, name, view: view) self end |
#sample_row_keys ⇒ :yields: sample_row_key Originally defined in module ReadOperations
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, which can be used to break up the data for distributed tasks like mapreduces.
#wait_for_replication(timeout: 600, check_interval: 5) ⇒ Boolean
Wait for replication to check replication consistency of table Checks replication consistency by generating consistency token and calling +check_consistency+ api call 5 times(default). If the response is consistent then return true. Otherwise try again. If consistency checking will run for more than 10 minutes and still not got the +true+ response then return +false+.
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
# File 'lib/google/cloud/bigtable/table.rb', line 499 def wait_for_replication timeout: 600, check_interval: 5 if check_interval > timeout raise( InvalidArgumentError, "'check_interval' can not be greather then timeout" ) end token = generate_consistency_token status = false start_at = Time.now loop do status = check_consistency(token) break if status || (Time.now - start_at) >= timeout sleep(check_interval) end status end |