Class: Google::Cloud::Bigtable::Table

Inherits:
Object
  • Object
show all
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.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.table("my-instance", "my-table")

if table.exists?
  p "Table exists."
else
  p "Table does not exist"
end

Defined Under Namespace

Classes: ClusterState, List, RestoreJob

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#app_profile_idString

Returns App profile ID for request routing.

Returns:

  • (String)

    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.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table("my-instance", "my-table")

predicate_filter = Google::Cloud::Bigtable::RowFilter.key("user-10")
on_match_mutations = Google::Cloud::Bigtable::MutationEntry.new
on_match_mutations.set_cell(
  "cf-1",
  "field-1",
  "XYZ",
  timestamp: (Time.now.to_f * 1000000).round(-3) # microseconds
).delete_cells("cf2", "field02")

otherwise_mutations = Google::Cloud::Bigtable::MutationEntry.new
otherwise_mutations.delete_from_family("cf3")

predicate_matched = table.check_and_mutate_row(
  "user01",
  predicate_filter,
  on_match: on_match_mutations,
  otherwise: otherwise_mutations
)

if predicate_matched
  puts "All predicates matched"
end

Parameters:

  • key (String)

    Row key. The row key of the row to which the conditional mutation should be applied.

  • predicate (SimpleFilter, ChainFilter, InterleaveFilter)

    Predicate filter. The filter to be applied to the contents of the specified row. Depending on whether or not any results are yielded, either +true_mutations+ or +false_mutations+ will be executed. If unset, checks that the row contains any values.

  • on_match (Google::Cloud::Bigtable::MutationEntry) (defaults to: nil)

    Mutation entry applied to predicate filter match. Changes to be atomically applied to the specified row if +predicate_filter+ yields at least one cell when applied to +row_key+. Entries are applied in order, meaning that earlier mutations can be masked by later ones. Must contain at least one entry if +false_mutations+ is empty and at most 100,000 entries.

  • otherwise (Google::Cloud::Bigtable::MutationEntry) (defaults to: nil)

    Mutation entry applied when predicate filter does not match. Changes to be atomically applied to the specified row if +predicate_filter+ does not yield any cells when applied to +row_key+. Entries are applied in order, meaning that earlier mutations can be masked by later ones. Must contain at least one entry if +true_mutations+ is empty and at most 100,000 entries.

Returns:

  • (Boolean)

    Predicate match or not status.

#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.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

instance = bigtable.instance("my-instance")
table = instance.table("my-table")

token = "l947XelENinaxJQP0nnrZJjHnAF7YrwW8HCJLotwrF"

if table.check_consistency(token)
  puts "Replication is consistent"
end

Parameters:

  • token (String)

    Consistency token

Returns:

  • (Boolean)

    true if replication is consistent



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_statesArray<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.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.table("my-instance", "my-table", perform_lookup: true)

table.column_families.each do |name, cf|
  puts name
  puts cf.gc_rule
end

# Get a column family by name
cf1 = table.column_families["cf1"]

Modify the table's column families

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.table("my-instance", "my-table", perform_lookup: true)

table.column_families do |cfm|
  cfm.add "cf4", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600)
  cfm.add "cf5", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5)

  rule_1 = Google::Cloud::Bigtable::GcRule.max_versions(3)
  rule_2 = Google::Cloud::Bigtable::GcRule.max_age(600)
  rule_union = Google::Cloud::Bigtable::GcRule.union(rule_1, rule_2)
  cfm.update "cf2", gc_rule: rule_union

  cfm.delete "cf3"
end

puts table.column_families["cf3"] #=> nil

Yields:

  • (column_families)

    A block for modifying the table's column families. Applies multiple 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.

Yield Parameters:

  • column_families (ColumnFamilyMap)

    A mutable object containing the column families for the table, mapped by column family name. Any changes made to this object will be stored in API.

Returns:

  • (ColumnFamilyMap)

    A frozen object containing the column families for the table, mapped by column family name.



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

#deleteBoolean

Permanently deletes the table from a instance.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.table("my-instance", "my-table")
table.delete

Returns:

  • (Boolean)

    Returns true if the table was deleted.



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.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

instance = bigtable.instance("my-instance")
table = instance.table("my-table")
table.delete_all_rows

# With timeout
table.delete_all_rows(timeout: 120) # 120 seconds.

Parameters:

  • timeout (Integer) (defaults to: nil)

    Call timeout in seconds. Use in case of insufficient deadline for DropRowRange, then try again with a longer request deadline.

Returns:

  • (Boolean)


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.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.table("my-instance", "my-table")

table.delete_rows_by_prefix("user-100")

# With timeout
table.delete_rows_by_prefix("user-1", timeout: 120) # 120 seconds.

Parameters:

  • prefix (String)

    Row key prefix (for example, "user").

  • timeout (Integer) (defaults to: nil)

    Call timeout in seconds.

Returns:

  • (Boolean)


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.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.table("my-instance", "my-table")

# Delete rows using row key prefix.
table.drop_row_range(row_key_prefix: "user-100")

# Delete all data With timeout
table.drop_row_range(delete_all_data: true, timeout: 120) # 120 seconds.

Parameters:

  • row_key_prefix (String) (defaults to: nil)

    Row key prefix (for example, "user").

  • delete_all_data (Boolean) (defaults to: nil)

Returns:

  • (Boolean)


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.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.table("my-instance", "my-table")

if table.exists?
  p "Table exists."
else
  p "Table does not exist"
end

Using Cloud Bigtable instance

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

instance = bigtable.instance("my-instance")
table = instance.table("my-table")

if table.exists?
  p "Table exists."
else
  p "Table does not exist"
end

Returns:

  • (Boolean)


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

#filterGoogle::Cloud::Bigtable::RowRange Originally defined in module ReadOperations

Gets a row filter.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table("my-instance", "my-table")

filter = table.filter.key("user-*")

Returns:

#generate_consistency_tokenString

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.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

instance = bigtable.instance("my-instance")
table = instance.table("my-table")

table.generate_consistency_token # "l947XelENinaxJQP0nnrZJjHnAF7YrwW8HCJLotwrF"

Returns:

  • (String)

    The generated consistency token



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

#granularitySymbol

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.

Returns:

  • (Symbol)


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.

Returns:

  • (Boolean)


239
240
241
# File 'lib/google/cloud/bigtable/table.rb', line 239

def granularity_millis?
  granularity == :MILLIS
end

#instance_idString

The unique identifier for the instance to which the table belongs.

Returns:

  • (String)


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.

Examples:

Single mutation on row.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.table("my-instance", "my-table")

entry = table.new_mutation_entry("user-1")
entry.set_cell("cf1", "field1", "XYZ")
table.mutate_row(entry)

Multiple mutations on row.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.table("my-instance", "my-table")

entry = table.new_mutation_entry("user-1")
entry.set_cell(
  "cf-1",
  "field-1",
  "XYZ",
  timestamp: (Time.now.to_f * 1000000).round(-3) # microseconds
).delete_cells("cf2", "field02")

table.mutate_row(entry)

Parameters:

Returns:

  • (Boolean)

#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.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.table("my-instance", "my-table")

entries = []
entries << table.new_mutation_entry("row-1").set_cell("cf1", "field1", "XYZ")
entries << table.new_mutation_entry("row-2").set_cell("cf1", "field1", "ABC")
responses = table.mutate_rows(entries)

responses.each do |response|
  puts response.status.description
end

Parameters:

  • entries (Array<Google::Cloud::Bigtable::MutationEntry>)

    The row keys and corresponding mutations to be applied in bulk. Each entry is applied as an atomic mutation, but the entries may be applied in arbitrary order (even between entries for the same row). At least one entry must be specified, and in total the entries can contain a maximum of 100,000 mutations.

Returns:

#nameString Also known as: table_id

The unique identifier for the table.

Returns:

  • (String)


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.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table("my-instance", "my-table")

range = table.new_column_range("test-family")
range.from("abc")
range.to("xyz")

# OR
range = table.new_column_range("test-family").from("key-1").to("key-5")

With exclusive from range.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table("my-instance", "my-table")

range = table.new_column_range("test-family").from("key-1", inclusive: false).to("key-5")

Parameters:

  • family (String)

    Column family name.

Returns:

#new_mutation_entry(row_key = nil) ⇒ Google::Cloud::Bigtable::MutationEntry Originally defined in module MutationOperations

Creates a mutation entry instance.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table("my-instance", "my-table")

entry = table.new_mutation_entry("row-key-1")

# Without row key
entry = table.new_mutation_entry

Parameters:

  • row_key (String) (defaults to: nil)

    Row key. Optional. The row key of the row to which the mutation should be applied.

Returns:

#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.

Examples:

Create rule to append to qualifier value.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table("my-instance", "my-table")
rule = table.new_read_modify_write_rule("cf", "qualifier-1")
rule.append("append-xyz")

Create rule to increment qualifier value.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table("my-instance", "my-table")
rule = table.new_read_modify_write_rule("cf", "qualifier-1")
rule.increment(100)

Parameters:

  • family (String)

    The name of the column family to which the read/modify/write rule should be applied.

  • qualifier (String)

    The qualifier of the column to which the read/modify/write rule should be applied.

Returns:

#new_row_rangeGoogle::Cloud::Bigtable::RowRange Originally defined in module ReadOperations

Gets a new instance of RowRange.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table("my-instance", "my-table")

range = table.new_row_range
range.from("abc")
range.to("xyz")

# OR
range = table.new_row_range.from("key-1").to("key-5")

With exclusive from range.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table("my-instance", "my-table")

range = table.new_row_range.from("key-1", inclusive: false).to("key-5")

Returns:

#new_value_rangeGoogle::Cloud::Bigtable::ValueRange Originally defined in module ReadOperations

Creates a new instance of ValueRange.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table("my-instance", "my-table")

range = table.new_value_range
range.from("abc")
range.to("xyz")

# OR
range = table.new_value_range.from("abc").to("xyz")

With exclusive from range.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table("my-instance", "my-table")

range = table.new_value_range.from("abc", inclusive: false).to("xyz")

Returns:

#pathString

The full path for the table resource. Values are of the form projects/<project_id>/instances/<instance_id>/table/<table_id>.

Returns:

  • (String)


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.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.table("my-instance", "my-table", perform_lookup: true)
policy = table.policy

Update the policy by passing a block.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.table("my-instance", "my-table", perform_lookup: true)

table.policy do |p|
  p.add("roles/owner", "user:[email protected]")
end # 2 API calls

Yields:

  • (policy)

    A block for updating the policy. The latest policy will be read from the Bigtable service and passed to the block. After the block completes, the modified policy will be written to the service.

Yield Parameters:

  • policy (Policy)

    the current Cloud IAM Policy for this table.

Returns:

  • (Policy)

    The current Cloud IAM Policy for the table.

See Also:



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_idString

The unique identifier for the project to which the table belongs.

Returns:

  • (String)


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.

Examples:

Apply multiple modification rules.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table("my-instance", "my-table")

rule_1 = table.new_read_modify_write_rule("cf", "field01")
rule_1.append("append-xyz")

rule_2 = table.new_read_modify_write_rule("cf", "field01")
rule_2.increment(1)

row = table.read_modify_write_row("user01", [rule_1, rule_2])

puts row.cells

Apply single modification rules.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table("my-instance", "my-table")

rule = table.new_read_modify_write_rule("cf", "field01").append("append-xyz")

row = table.read_modify_write_row("user01", rule)

puts row.cells

Parameters:

Returns:

#read_row(key, filter: nil) ⇒ Google::Cloud::Bigtable::Row Originally defined in module ReadOperations

Reads a single row by row key.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table("my-instance", "my-table")

row = table.read_row("user-1")

Read row with filter.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table("my-instance", "my-table")

filter = Google::Cloud::Bigtable::RowFilter.cells_per_row(3)

row = table.read_row("user-1", filter: filter)

Parameters:

  • key (String)

    Row key. Required.

  • filter (Google::Cloud::Bigtable::RowFilter) (defaults to: nil)

    The filter to apply to the contents of the specified row. Optional.

Returns:

#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.

Examples:

Read with limit.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table("my-instance", "my-table")

table.read_rows(limit: 10).each do |row|
  puts row
end

Read using row keys.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table("my-instance", "my-table")

table.read_rows(keys: ["user-1", "user-2"]).each do |row|
  puts row
end

Read using row ranges.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table("my-instance", "my-table")

range = table.new_row_range.between("user-1", "user-100")

table.read_rows(ranges: range).each do |row|
  puts row
end

Read using filter.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table("my-instance", "my-table")

filter = table.filter.key("user-*")
# OR
# filter = Google::Cloud::Bigtable::RowFilter.key("user-*")

table.read_rows(filter: filter).each do |row|
  puts row
end

Read using filter with limit.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table("my-instance", "my-table")

filter = table.filter.key("user-*")
# OR
# filter = Google::Cloud::Bigtable::RowFilter.key("user-*")

table.read_rows(filter: filter, limit: 10).each do |row|
  puts row
end

Parameters:

  • keys (Array<String>) (defaults to: nil)

    List of row keys to be read. Optional.

  • ranges (Google::Cloud::Bigtable::RowRange | Array<Google::Cloud::Bigtable::RowRange>) (defaults to: nil)

    Row ranges array or single range. Optional.

  • filter (SimpleFilter, ChainFilter, InterleaveFilter, ConditionFilter) (defaults to: nil)

    The filter to apply to the contents of the specified row(s). If unset, reads the entries of each row. Optional.

  • limit (Integer) (defaults to: nil)

    Limit number of read rows count. Optional. The read will terminate after committing to N rows' worth of results. The default (zero) is to return all results.

Returns:

#reload!(view: nil) ⇒ Google::Cloud::Bigtable::Table

Reloads table data.

Parameters:

  • view (Symbol) (defaults to: nil)

    Table view type. Default view type is :SCHEMA_VIEW. Valid view types are:

    • :NAME_ONLY - Only populates name.
    • :SCHEMA_VIEW - Only populates name and fields related to the table's schema.
    • :REPLICATION_VIEW - Only populates name and fields related to the table's replication state.
    • :FULL - Populates all fields.

Returns:



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.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new
table = bigtable.table("my-instance", "my-table")

table.sample_row_keys.each do |sample_row_key|
  p sample_row_key.key # user00116
  p sample_row_key.offset # 805306368
end

Yield Returns:

Returns:

  • (:yields: sample_row_key)

    Yield block for each processed SampleRowKey.

#test_iam_permissions(*permissions) ⇒ Array<String>

Tests the specified permissions against the Cloud IAM access control policy.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.table("my-instance", "my-table", perform_lookup: true)

permissions = table.test_iam_permissions(
  "bigtable.tables.delete",
  "bigtable.tables.get"
)
permissions.include? "bigtable.tables.delete" #=> false
permissions.include? "bigtable.tables.get" #=> true

Parameters:

  • permissions (String, Array<String>)

    permissions The set of permissions to check access for. Permissions with wildcards (such as * or bigtable.*) are not allowed. See Access Control.

Returns:

  • (Array<String>)

    The permissions that are configured for the policy.

See Also:



348
349
350
351
352
# File 'lib/google/cloud/bigtable/table.rb', line 348

def test_iam_permissions *permissions
  ensure_service!
  grpc = service.test_table_permissions instance_id, name, permissions.flatten
  grpc.permissions.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.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.table("my-instance", "my-table", perform_lookup: true)

policy = table.policy
policy.add("roles/owner", "user:[email protected]")
updated_policy = table.update_policy(policy)

puts updated_policy.roles

Parameters:

  • new_policy (Policy)

    a new or modified Cloud IAM Policy for this table

Returns:

  • (Policy)

    The policy returned by the API update operation.



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.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.table("my-instance", "my-table", perform_lookup: true)

if table.wait_for_replication
  puts "Replication done"
end

# With custom timeout and interval
if table.wait_for_replication(timeout: 300, check_interval: 10)
  puts "Replication done"
end

Parameters:

  • timeout (Integer) (defaults to: 600)

    Timeout in seconds. Defaults value is 600 seconds.

  • check_interval (Integer) (defaults to: 5)

    Consistency check interval in seconds. Default is 5 seconds.

Returns:

  • (Boolean)

    true if replication is consistent

Raises:

  • (InvalidArgumentError)


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