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) -> ColumnFamilyRetrieves the ColumnFamily object corresponding to the name. If not
found, returns nil.
#add
def add(name, gc_rule: nil)Adds a new column family to the table.
def add(name, gc_rule: nil)- 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.
- (ArgumentError) — if the column family name already exists.
- (FrozenError) — if the column family map is frozen.
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)Adds a new column family to the table.
def add(name, gc_rule: nil)- 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.
- (ArgumentError) — if the column family name already exists.
- (FrozenError) — if the column family map is frozen.
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)Deletes the named column family from the table.
- name (String) — Column family name.
- (ArgumentError) — if the column family name does not exist.
- (FrozenError) — if the column family map is frozen.
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)Deletes the named column family from the table.
- name (String) — Column family name.
- (ArgumentError) — if the column family name does not exist.
- (FrozenError) — if the column family map is frozen.
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, nilCalls 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.
- (name, column_family) — The name and column family pair.
- name (String) — the column family name.
- column_family (ColumnFamily) — the column family object.
-
(Enumerator, nil) — An enumerator is returned if no block is given, otherwise
nil.
#empty?
def empty?() -> BooleanReturns true if the map contains no name and column family pairs.
- (Boolean)
#initialize
def initialize() { |_self| ... } -> ColumnFamilyMapCreates a new ColumnFamilyMap object.
- (_self)
- _self (Google::Cloud::Bigtable::ColumnFamilyMap) — the object that the method was called on
- (ColumnFamilyMap) — a new instance of ColumnFamilyMap
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) -> BooleanReturns true if the given name is present in the map.
- (Boolean)
#keys
def keys() -> Array<String>Returns a new array populated with the names from the map.
- (Array<String>)
#length
def length() -> IntegerReturns the number of name and column family pairs in the map.
- (Integer)
#name?
def name?(name) -> BooleanReturns true if the given name is present in the map.
- (Boolean)
#names
def names() -> Array<String>Returns a new array populated with the names from the map.
- (Array<String>)
#size
def size() -> IntegerReturns the number of name and column family pairs in the map.
- (Integer)
#update
def update(name, gc_rule: nil)Updates an existing column family in the table.
- 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.
- (ArgumentError) — if the column family name does not exist.
- (FrozenError) — if the column family map is frozen.
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