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/restore_job.rb,
lib/google/cloud/bigtable/table/cluster_state.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, List, RestoreJob
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.
-
#cluster_states ⇒ Array<Google::Cloud::Bigtable::Table::ClusterState>
Map from cluster ID to per-cluster table state.
-
#column_families {|column_families| ... } ⇒ ColumnFamilyMap
Returns a frozen object containing the column families configured for the table, mapped by column family name.
-
#delete ⇒ Boolean
Permanently deletes the table from a instance.
-
#delete_all_rows(timeout: nil) ⇒ Boolean
Deletes all rows.
-
#delete_rows_by_prefix(prefix, timeout: nil) ⇒ Boolean
Deletes rows using row key prefix.
-
#drop_row_range(row_key_prefix: nil, delete_all_data: nil, timeout: nil) ⇒ Boolean
Drops row range by row key prefix or deletes all.
-
#exists? ⇒ Boolean
Checks to see if the table exists.
-
#filter ⇒ Google::Cloud::Bigtable::RowRange
included
from ReadOperations
Gets a row filter.
-
#generate_consistency_token ⇒ String
Generates a consistency token for a table.
-
#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 1 ms.
-
#instance_id ⇒ String
The unique identifier for the instance to which the table belongs.
-
#mutate_row(entry) ⇒ Boolean
included
from MutationOperations
Mutates a row atomically.
-
#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
Gets a new instance of ColumnRange.
-
#new_mutation_entry(row_key = nil) ⇒ Google::Cloud::Bigtable::MutationEntry
included
from MutationOperations
Creates a mutation entry instance.
-
#new_read_modify_write_rule(family, qualifier) ⇒ Google::Cloud::Bigtable::ReadModifyWriteRule
included
from MutationOperations
Create a read/modify/write rule to append or increment the value of the cell qualifier.
-
#new_row_range ⇒ Google::Cloud::Bigtable::RowRange
included
from ReadOperations
Gets a new instance of RowRange.
-
#new_value_range ⇒ Google::Cloud::Bigtable::ValueRange
included
from ReadOperations
Creates a new instance of ValueRange.
-
#path ⇒ String
The full path for the table resource.
-
#policy {|policy| ... } ⇒ Policy
Gets the Cloud IAM access control policy for the table.
-
#project_id ⇒ String
The unique identifier for the project to which the table belongs.
-
#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
Reads a single row by row key.
-
#read_rows(keys: nil, ranges: nil, filter: nil, limit: nil, &block) ⇒ Array<Google::Cloud::Bigtable::Row> | :yields: row
included
from ReadOperations
Reads rows.
-
#reload!(view: nil) ⇒ Google::Cloud::Bigtable::Table
Reloads table data.
-
#sample_row_keys ⇒ :yields: sample_row_key
included
from ReadOperations
Reads sample row keys.
-
#test_iam_permissions(*permissions) ⇒ Array<String>
Tests the specified permissions against the Cloud IAM access control policy.
-
#update_policy(new_policy) ⇒ Policy
(also: #policy=)
Updates the Cloud IAM access control policy for the table.
-
#wait_for_replication(timeout: 600, check_interval: 5) ⇒ Boolean
Wait for replication to check replication consistency.
Instance Attribute Details
#app_profile_id ⇒ String
Returns App profile ID for request routing.
62 63 64 |
# File 'lib/google/cloud/bigtable/table.rb', line 62 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. Replication is considered consistent if replication has caught up based on the conditions specified in the token and the check request.
488 489 490 491 492 |
# File 'lib/google/cloud/bigtable/table.rb', line 488 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
.
140 141 142 143 144 145 |
# File 'lib/google/cloud/bigtable/table.rb', line 140 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 {|column_families| ... } ⇒ ColumnFamilyMap
Returns a frozen object containing the column families configured for
the table, mapped by column family name. Reloads the table if
necessary to retrieve the column families data, since it is only
available in a table with view type SCHEMA_VIEW
or FULL
.
Also accepts a block for making modifications to the table's column families. After the modifications are completed, the table will be updated with the changes, and the updated column families will be returned.
208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/google/cloud/bigtable/table.rb', line 208 def column_families check_view_and_load :SCHEMA_VIEW if block_given? column_families = ColumnFamilyMap.from_grpc @grpc.column_families yield column_families modifications = column_families.modifications @grpc.column_families @grpc = service.modify_column_families instance_id, table_id, modifications if modifications.any? end ColumnFamilyMap.from_grpc(@grpc.column_families).freeze end |
#delete ⇒ Boolean
Permanently deletes the table from a instance.
367 368 369 370 371 |
# File 'lib/google/cloud/bigtable/table.rb', line 367 def delete ensure_service! service.delete_table instance_id, name true end |
#delete_all_rows(timeout: nil) ⇒ Boolean
Deletes all rows.
559 560 561 |
# File 'lib/google/cloud/bigtable/table.rb', line 559 def delete_all_rows timeout: nil drop_row_range delete_all_data: true, timeout: timeout end |
#delete_rows_by_prefix(prefix, timeout: nil) ⇒ Boolean
Deletes rows using row key prefix.
581 582 583 |
# File 'lib/google/cloud/bigtable/table.rb', line 581 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
Drops row range by row key prefix or deletes all.
605 606 607 608 609 610 611 612 613 614 615 |
# File 'lib/google/cloud/bigtable/table.rb', line 605 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
Checks to see if the table exists.
405 406 407 408 409 |
# File 'lib/google/cloud/bigtable/table.rb', line 405 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
Gets a row filter.
#generate_consistency_token ⇒ String
Generates a consistency token for a table. The token 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.
461 462 463 464 465 |
# File 'lib/google/cloud/bigtable/table.rb', line 461 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
.
229 230 231 232 |
# File 'lib/google/cloud/bigtable/table.rb', line 229 def granularity check_view_and_load :SCHEMA_VIEW @grpc.granularity end |
#granularity_millis? ⇒ Boolean
The table keeps data versioned at a granularity of 1 ms.
239 240 241 |
# File 'lib/google/cloud/bigtable/table.rb', line 239 def granularity_millis? granularity == :MILLIS end |
#instance_id ⇒ String
The unique identifier for the instance to which the table belongs.
87 88 89 |
# File 'lib/google/cloud/bigtable/table.rb', line 87 def instance_id @grpc.name.split("/")[3] end |
#mutate_row(entry) ⇒ Boolean Originally defined in module MutationOperations
Mutates a row atomically. Cells in the row are left unchanged unless explicitly changed by the mutations. 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 and at most 100,000.
#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 ##mutate_row, 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
Gets a new instance of ColumnRange.
#new_mutation_entry(row_key = nil) ⇒ Google::Cloud::Bigtable::MutationEntry Originally defined in module MutationOperations
Creates a mutation entry instance.
#new_read_modify_write_rule(family, qualifier) ⇒ Google::Cloud::Bigtable::ReadModifyWriteRule Originally defined in module MutationOperations
Create a read/modify/write rule to append or increment the value of the cell qualifier.
#new_row_range ⇒ Google::Cloud::Bigtable::RowRange Originally defined in module ReadOperations
Gets a new instance of RowRange.
#new_value_range ⇒ Google::Cloud::Bigtable::ValueRange Originally defined in module ReadOperations
Creates a 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>
.
107 108 109 |
# File 'lib/google/cloud/bigtable/table.rb', line 107 def path @grpc.name end |
#policy {|policy| ... } ⇒ Policy
Gets the Cloud IAM access control policy for the table.
277 278 279 280 281 282 283 284 |
# File 'lib/google/cloud/bigtable/table.rb', line 277 def policy ensure_service! grpc = service.get_table_policy instance_id, name policy = Policy.from_grpc grpc return policy unless block_given? yield policy update_policy policy end |
#project_id ⇒ String
The unique identifier for the project to which the table belongs.
78 79 80 |
# File 'lib/google/cloud/bigtable/table.rb', line 78 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
Reads a single row by row key.
#read_rows(keys: nil, ranges: nil, filter: nil, limit: nil, &block) ⇒ Array<Google::Cloud::Bigtable::Row> | :yields: row Originally defined in module ReadOperations
Reads 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
Reloads table data.
125 126 127 128 129 |
# File 'lib/google/cloud/bigtable/table.rb', line 125 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
Reads 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.
#test_iam_permissions(*permissions) ⇒ Array<String>
Tests the specified permissions against the Cloud IAM access control policy.
348 349 350 351 352 |
# File 'lib/google/cloud/bigtable/table.rb', line 348 def * ensure_service! grpc = service. instance_id, name, .flatten grpc..to_a end |
#update_policy(new_policy) ⇒ Policy Also known as: policy=
Updates the Cloud IAM access control
policy for the table. The policy should be read from #policy.
See Policy for an explanation of the policy
etag
property and how to modify policies.
You can also update the policy by passing a block to #policy, which will call this method internally after the block completes.
313 314 315 316 317 |
# File 'lib/google/cloud/bigtable/table.rb', line 313 def update_policy new_policy ensure_service! grpc = service.set_table_policy instance_id, name, new_policy.to_grpc Policy.from_grpc grpc end |
#wait_for_replication(timeout: 600, check_interval: 5) ⇒ Boolean
Wait for replication to check replication consistency.
Checks replication consistency by generating a consistency token and
making the check_consistency
API call 5 times (by default).
If the response is consistent, returns true
. Otherwise tries again
repeatedly until the timeout. If the check does not succeed by the
timeout, returns false
.
524 525 526 527 528 529 530 531 532 533 534 535 536 537 |
# File 'lib/google/cloud/bigtable/table.rb', line 524 def wait_for_replication timeout: 600, check_interval: 5 raise InvalidArgumentError, "'check_interval' cannot be greater than timeout" if check_interval > timeout 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 |