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
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
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.
-
#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 a new instance of ColumnRange.
-
#new_mutation_entry(row_key = nil) ⇒ Google::Cloud::Bigtable::MutationEntry
included
from MutationOperations
Create an instance of mutation_entry.
-
#new_read_modify_write_rule(family, qualifier) ⇒ Google::Cloud::Bigtable::ReadModifyWriteRule
included
from MutationOperations
Create an instance of ReadModifyWriteRule to append or increment the value of the cell qualifier.
-
#new_row_range ⇒ Google::Cloud::Bigtable::RowRange
included
from ReadOperations
Get 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.
-
#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
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
Reload table information.
-
#sample_row_keys ⇒ :yields: sample_row_key
included
from ReadOperations
Reads sample row keys.
-
#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.
61 62 63 |
# File 'lib/google/cloud/bigtable/table.rb', line 61 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.
376 377 378 379 380 |
# File 'lib/google/cloud/bigtable/table.rb', line 376 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
139 140 141 142 143 144 |
# File 'lib/google/cloud/bigtable/table.rb', line 139 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.
207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/google/cloud/bigtable/table.rb', line 207 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.
255 256 257 258 259 |
# File 'lib/google/cloud/bigtable/table.rb', line 255 def delete ensure_service! service.delete_table instance_id, name true end |
#delete_all_rows(timeout: nil) ⇒ Boolean
Deletes all rows.
456 457 458 |
# File 'lib/google/cloud/bigtable/table.rb', line 456 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.
478 479 480 |
# File 'lib/google/cloud/bigtable/table.rb', line 478 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.
502 503 504 505 506 507 508 509 510 511 512 |
# File 'lib/google/cloud/bigtable/table.rb', line 502 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.
293 294 295 296 297 |
# File 'lib/google/cloud/bigtable/table.rb', line 293 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.
349 350 351 352 353 |
# File 'lib/google/cloud/bigtable/table.rb', line 349 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
228 229 230 231 |
# File 'lib/google/cloud/bigtable/table.rb', line 228 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.
238 239 240 |
# File 'lib/google/cloud/bigtable/table.rb', line 238 def granularity_millis? granularity == :MILLIS end |
#instance_id ⇒ String
The unique identifier for the instance.
86 87 88 |
# File 'lib/google/cloud/bigtable/table.rb', line 86 def instance_id @grpc.name.split("/")[3] end |
#mutate_row(entry) ⇒ Boolean Originally defined in module MutationOperations
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.
#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.
95 96 97 |
# File 'lib/google/cloud/bigtable/table.rb', line 95 def name @grpc.name.split("/")[5] end |
#new_column_range(family) ⇒ Google::Cloud::Bigtable::ColumnRange Originally defined in module ReadOperations
Get a new instance of ColumnRange.
#new_mutation_entry(row_key = nil) ⇒ Google::Cloud::Bigtable::MutationEntry Originally defined in module MutationOperations
Create an instance of mutation_entry
#new_read_modify_write_rule(family, qualifier) ⇒ Google::Cloud::Bigtable::ReadModifyWriteRule Originally defined in module MutationOperations
Create an instance of ReadModifyWriteRule to append or increment the value of the cell qualifier.
#new_row_range ⇒ Google::Cloud::Bigtable::RowRange Originally defined in module ReadOperations
Get 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>
.
106 107 108 |
# File 'lib/google/cloud/bigtable/table.rb', line 106 def path @grpc.name end |
#project_id ⇒ String
The unique identifier for the project.
77 78 79 |
# File 'lib/google/cloud/bigtable/table.rb', line 77 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
Reload table information.
124 125 126 127 128 |
# File 'lib/google/cloud/bigtable/table.rb', line 124 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.
#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
.
412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'lib/google/cloud/bigtable/table.rb', line 412 def wait_for_replication timeout: 600, check_interval: 5 raise InvalidArgumentError, "'check_interval' can not be greather then 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 |