Cloud Bigtable API - Class Google::Cloud::Bigtable::ColumnFamilyMap (v2.10.2)

Reference documentation and code samples for the Cloud Bigtable API class Google::Cloud::Bigtable::ColumnFamilyMap.

Represents a table's column families.

See Project#create_table, Instance#create_table and Table#column_families.

Inherits

  • Object

Includes

  • Enumerable

Examples

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

column_families = Google::Cloud::Bigtable::ColumnFamilyMap.new

column_families.add "cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600)
column_families.add "cf2", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5)

Create a table with a block yielding a ColumnFamilyMap.

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

table = bigtable.create_table "my-instance", "my-table" do |cfm|
  cfm.add "cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5)
  cfm.add "cf2", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600)

  gc_rule = Google::Cloud::Bigtable::GcRule.union(
    Google::Cloud::Bigtable::GcRule.max_age(1800),
    Google::Cloud::Bigtable::GcRule.max_versions(3)
  )
  cfm.add "cf3", gc_rule: gc_rule
end

puts table.column_families

Update column families with a block yielding a ColumnFamilyMap.

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

Methods

#[]

def [](name) -> ColumnFamily

Retrieves the ColumnFamily object corresponding to the name. If not found, returns nil.

Returns

#add

def add(name, gc_rule: nil)
Aliases

Adds a new column family to the table.

Overloads
def add(name, gc_rule: nil)
Adds a new column family to the table.
Parameters
  • name (String) — Column family name.
  • gc_rule (Google::Cloud::Bigtable::GcRule) (defaults to: nil) — The garbage collection rule to be used for the column family. Optional. The service default value will be used when not specified.
Raises
  • (ArgumentError) — if the column family name already exists.
  • (FrozenError) — if the column family map is frozen.
Example
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

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

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

#create

def add(name, gc_rule: nil)
Alias Of: #add

Adds a new column family to the table.

Overloads
def add(name, gc_rule: nil)
Adds a new column family to the table.
Parameters
  • name (String) — Column family name.
  • gc_rule (Google::Cloud::Bigtable::GcRule) (defaults to: nil) — The garbage collection rule to be used for the column family. Optional. The service default value will be used when not specified.
Raises
  • (ArgumentError) — if the column family name already exists.
  • (FrozenError) — if the column family map is frozen.
Example
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

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

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

#delete

def delete(name)
Aliases

Deletes the named column family from the table.

Parameter
  • name (String) — Column family name.
Raises
  • (ArgumentError) — if the column family name does not exist.
  • (FrozenError) — if the column family map is frozen.
Example
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

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

table.column_families do |column_families|
  column_families.delete "cf3"
end

#drop

def drop(name)
Alias Of: #delete

Deletes the named column family from the table.

Parameter
  • name (String) — Column family name.
Raises
  • (ArgumentError) — if the column family name does not exist.
  • (FrozenError) — if the column family map is frozen.
Example
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

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

table.column_families do |column_families|
  column_families.delete "cf3"
end

#each

def each() { |name, column_family| ... } -> Enumerator, nil

Calls the block once for each column family in the map, passing the name and column family pair as parameters.

If no block is given, an enumerator is returned instead.

Yields
  • (name, column_family) — The name and column family pair.
Yield Parameters
  • name (String) — the column family name.
  • column_family (ColumnFamily) — the column family object.
Returns
  • (Enumerator, nil) — An enumerator is returned if no block is given, otherwise nil.

#empty?

def empty?() -> Boolean

Returns true if the map contains no name and column family pairs.

Returns
  • (Boolean)

#initialize

def initialize() { |_self| ... } -> ColumnFamilyMap

Creates a new ColumnFamilyMap object.

Yields
  • (_self)
Yield Parameter
Returns
Examples
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

column_families = Google::Cloud::Bigtable::ColumnFamilyMap.new

column_families.add "cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600)
column_families.add "cf2", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5)

Create new column families using block syntax:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

column_families = Google::Cloud::Bigtable::ColumnFamilyMap.new do |cfm|
  cfm.add "cf1", gc_rule: Google::Cloud::Bigtable::GcRule.max_age(600)
  cfm.add "cf2", gc_rule: Google::Cloud::Bigtable::GcRule.max_versions(5)
end

#key?

def key?(name) -> Boolean
Alias Of: #name?

Returns true if the given name is present in the map.

Returns
  • (Boolean)

#keys

def keys() -> Array<String>
Alias Of: #names

Returns a new array populated with the names from the map.

Returns
  • (Array<String>)

#length

def length() -> Integer
Aliases

Returns the number of name and column family pairs in the map.

Returns
  • (Integer)

#name?

def name?(name) -> Boolean
Aliases

Returns true if the given name is present in the map.

Returns
  • (Boolean)

#names

def names() -> Array<String>
Aliases

Returns a new array populated with the names from the map.

Returns
  • (Array<String>)

#size

def size() -> Integer
Alias Of: #length

Returns the number of name and column family pairs in the map.

Returns
  • (Integer)

#update

def update(name, gc_rule: nil)

Updates an existing column family in the table.

Parameters
  • name (String) — Column family name.
  • gc_rule (Google::Cloud::Bigtable::GcRule) (defaults to: nil) — The new garbage collection rule to be used for the column family. Optional. The service default value will be used when not specified.
Raises
  • (ArgumentError) — if the column family name does not exist.
  • (FrozenError) — if the column family map is frozen.
Example
require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

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

table.column_families do |column_families|
  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

  column_families.update "cf2", gc_rule: rule_union
end