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>
Returns an array of ClusterState objects that map 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::Cloud::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 with the provided
view
, or withSCHEMA_VIEW
if none is provided. -
#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.
70 71 72 |
# File 'lib/google/cloud/bigtable/table.rb', line 70 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.
526 527 528 529 530 |
# File 'lib/google/cloud/bigtable/table.rb', line 526 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>
Returns an array of ClusterState objects that map 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
the cluster state's replication_state
will be UNKNOWN
.
Reloads the table with the FULL
view type to retrieve the cluster states
data, unless the table was previously loaded with view type ENCRYPTION_VIEW
,
REPLICATION_VIEW
or FULL
.
171 172 173 174 175 176 |
# File 'lib/google/cloud/bigtable/table.rb', line 171 def cluster_states check_view_and_load :FULL, skip_if: [:ENCRYPTION_VIEW, :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
. Previously loaded data is retained.
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.
243 244 245 246 247 248 249 250 251 252 253 254 |
# File 'lib/google/cloud/bigtable/table.rb', line 243 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.
405 406 407 408 409 |
# File 'lib/google/cloud/bigtable/table.rb', line 405 def delete ensure_service! service.delete_table instance_id, name true end |
#delete_all_rows(timeout: nil) ⇒ Boolean
Deletes all rows.
597 598 599 |
# File 'lib/google/cloud/bigtable/table.rb', line 597 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.
619 620 621 |
# File 'lib/google/cloud/bigtable/table.rb', line 619 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.
644 645 646 647 648 649 650 651 652 653 654 |
# File 'lib/google/cloud/bigtable/table.rb', line 644 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.
443 444 445 446 447 |
# File 'lib/google/cloud/bigtable/table.rb', line 443 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.
499 500 501 502 503 |
# File 'lib/google/cloud/bigtable/table.rb', line 499 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
.
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
. Previously loaded data is retained.
267 268 269 270 |
# File 'lib/google/cloud/bigtable/table.rb', line 267 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.
277 278 279 |
# File 'lib/google/cloud/bigtable/table.rb', line 277 def granularity_millis? granularity == :MILLIS end |
#instance_id ⇒ String
The unique identifier for the instance to which the table belongs.
98 99 100 |
# File 'lib/google/cloud/bigtable/table.rb', line 98 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::Cloud::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.
107 108 109 |
# File 'lib/google/cloud/bigtable/table.rb', line 107 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>
.
118 119 120 |
# File 'lib/google/cloud/bigtable/table.rb', line 118 def path @grpc.name end |
#policy {|policy| ... } ⇒ Policy
Gets the Cloud IAM access control policy for the table.
315 316 317 318 319 320 321 322 |
# File 'lib/google/cloud/bigtable/table.rb', line 315 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.
89 90 91 |
# File 'lib/google/cloud/bigtable/table.rb', line 89 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 with the provided view
, or with SCHEMA_VIEW
if none is provided. Previously loaded data is not retained.
137 138 139 140 141 142 |
# File 'lib/google/cloud/bigtable/table.rb', line 137 def reload! view: nil view ||= :SCHEMA_VIEW @grpc = service.get_table instance_id, name, view: view @loaded_views = Set[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.
386 387 388 389 390 |
# File 'lib/google/cloud/bigtable/table.rb', line 386 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.
351 352 353 354 355 |
# File 'lib/google/cloud/bigtable/table.rb', line 351 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
.
562 563 564 565 566 567 568 569 570 571 572 573 574 575 |
# File 'lib/google/cloud/bigtable/table.rb', line 562 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 |