Class: Google::Cloud::Bigtable::ColumnFamily

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/bigtable/column_family.rb

Overview

ColumnFamily

A set of columns within a table which share a common configuration.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

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

# Create
gc_rule = Google::Cloud::Bigtable::GcRule.max_versions(5)
column_family = table.column_families.create("cf1", gc_rule: gc_rule)

# Update
column_family = table.column_families.find_by_name("cf2")
column_family.gc_rule = Google::Cloud::Bigtable::GcRule.max_age(600)
column_family.update

# Delete
column_family = table.column_families.find_by_name("cf3")
column_family.delete

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject (readonly)

Column family name



60
61
62
# File 'lib/google/cloud/bigtable/column_family.rb', line 60

def name
  @name
end

Class Method Details

.create_modification(name, gc_rule) ⇒ Google::Bigtable::Admin::V2::ModifyColumnFamiliesRequest::Modification

Create gPRC instance to create column family modification

Examples:

require "google/cloud/bigtable"

Google::Cloud::Bigtable::ColumnFamily.create_modification(
  "cf1", Google::Cloud::Bigtable::GcRule.max_age(600))
)

Parameters:

Returns:



164
165
166
# File 'lib/google/cloud/bigtable/column_family.rb', line 164

def self.create_modification name, gc_rule
  column_modification_grpc(:create, name, gc_rule)
end

.drop_modification(name) ⇒ Google::Bigtable::Admin::V2::ModifyColumnFamiliesRequest::Modification

Create drop column family modification gRPC instance

Examples:

require "google/cloud/bigtable"

Google::Cloud::Bigtable::ColumnFamily.drop_modification("cf1")

Parameters:

  • name (String)

    Column family name

Returns:



195
196
197
# File 'lib/google/cloud/bigtable/column_family.rb', line 195

def self.drop_modification name
  column_modification_grpc(:drop, name)
end

.update_modification(name, gc_rule) ⇒ Google::Bigtable::Admin::V2::ModifyColumnFamiliesRequest::Modification

Create update column family modification gPRC instance

Examples:

require "google/cloud/bigtable"

Google::Cloud::Bigtable::ColumnFamily.update_modification(
  "cf1", Google::Cloud::Bigtable::GcRule.max_age(600))
)

Parameters:

Returns:



181
182
183
# File 'lib/google/cloud/bigtable/column_family.rb', line 181

def self.update_modification name, gc_rule
  column_modification_grpc(:update, name, gc_rule)
end

Instance Method Details

#createGoogle::Cloud::Bigtable::ColumnFamily

Create column family.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

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

gc_rule = Google::Cloud::Bigtable::GcRule.max_versions(3)
cf = table.column_family("cf", gc_rule)
cf.create

Returns:



107
108
109
# File 'lib/google/cloud/bigtable/column_family.rb', line 107

def create
  modify_column_family(self.class.create_modification(name, gc_rule))
end

#deleteGoogle::Cloud::Bigtable::Table

Permanently delete column family from table.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

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

column_family = table.column_families.find {|cf| cf.name == "cf" }
column_family.delete

Returns:



147
148
149
# File 'lib/google/cloud/bigtable/column_family.rb', line 147

def delete
  modify_column_family(self.class.drop_modification(name)).nil?
end

#gc_ruleGoogle::Cloud::Bigtable::GcRule

Get GC rule



87
88
89
# File 'lib/google/cloud/bigtable/column_family.rb', line 87

def gc_rule
  GcRule.from_grpc(@grpc.gc_rule) if @grpc.gc_rule
end

#gc_rule=(rule) ⇒ Object

Set GC rule

Parameters:



79
80
81
# File 'lib/google/cloud/bigtable/column_family.rb', line 79

def gc_rule= rule
  @grpc.gc_rule = rule.to_grpc
end

#saveGoogle::Cloud::Bigtable::ColumnFamily Also known as: update

Update column family.

Examples:

require "google/cloud/bigtable"

bigtable = Google::Cloud::Bigtable.new

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

column_family = table.column_families.find {|cf| cf.name == "cf" }
column_family.gc_rule = Google::Cloud::Bigtable::GcRule.max_age(600)
column_family.save

Returns:



127
128
129
# File 'lib/google/cloud/bigtable/column_family.rb', line 127

def save
  modify_column_family(self.class.update_modification(name, gc_rule))
end