class Cequel::Schema::Table

An object representation of a CQL3 table schema.

@see Keyspace#read_table

Attributes

clustering_columns[R]

@return [Array<ClusteringColumn>] clustering columns defined on the

table
columns[R]

@return [Array<Column>] all columns defined on the table

columns_by_name[R]
compact_storage[W]

@return [Boolean] `true` if this table is configured with compact

storage
data_columns[R]

@return [Array<DataColumn,CollectionColumn>] data columns and

collection columns defined on the table
name[R]

@return [Symbol] the name of the table

partition_key_columns[R]

@return [Array<PartitionKey>] partition key columns defined on the

table
properties[R]

@return [Hash] storage properties defined on the table

Public Class Methods

new(name, is_view=false) click to toggle source

@param name [Symbol] the name of the table @api private

# File lib/cequel/schema/table.rb, line 41
def initialize(name, is_view=false)
  @name = name.to_sym
  @is_view = is_view
  @partition_key_columns, @clustering_columns, @data_columns = [], [], []
  @columns, @columns_by_name = [], {}
  @properties = ActiveSupport::HashWithIndifferentAccess.new
end

Public Instance Methods

add_column(column_desc) click to toggle source

Add a column descriptor to this table descriptor.

column_desc - Descriptor of column to add. Can be PartitionKey,

ClusteringColumn, DataColumn, List, Set, or Map.
# File lib/cequel/schema/table.rb, line 59
def add_column(column_desc)
  column_flavor = case column_desc
                  when PartitionKey
                    @partition_key_columns
                  when ClusteringColumn
                    @clustering_columns
                  else
                    @data_columns
                  end

  column_flavor << column_desc
  columns << column_desc
  columns_by_name[column_desc.name] = column_desc
end
add_property(property_desc) click to toggle source

Add a property to this table descriptor

property_desc - A `TableProperty` describing one property of this table.

# File lib/cequel/schema/table.rb, line 78
def add_property(property_desc)
  properties[property_desc.name] = property_desc
end
clustering_column(name) click to toggle source

@param name [Symbol] name of clustering column to look up @return [ClusteringColumn] clustering column with given name

# File lib/cequel/schema/table.rb, line 171
def clustering_column(name)
  clustering_columns.find { |column| column.name == name }
end
clustering_column_count() click to toggle source

@return [Integer] number of clustering columns

# File lib/cequel/schema/table.rb, line 155
def clustering_column_count
  clustering_columns.length
end
clustering_column_names() click to toggle source

@return [Array<Symbol>] names of clustering columns

# File lib/cequel/schema/table.rb, line 148
def clustering_column_names
  clustering_columns.map { |key| key.name }
end
column(name) click to toggle source

@param name [Symbol] name of column to look up @return [Column] column defined on table with given name

# File lib/cequel/schema/table.rb, line 87
def column(name)
  columns_by_name[name.to_sym]
end
column_names() click to toggle source

@return [Array<Symbol>] the names of all columns

# File lib/cequel/schema/table.rb, line 99
def column_names
  columns_by_name.keys
end
compact_storage?() click to toggle source

@return [Boolean] `true` if this table uses compact storage

# File lib/cequel/schema/table.rb, line 196
def compact_storage?
  !!@compact_storage
end
data_column(name) click to toggle source

@param name [Symbol] name of data column to look up @return [DataColumn,CollectionColumn] data column or collection column

with given name
# File lib/cequel/schema/table.rb, line 180
def data_column(name)
  name = name.to_sym
  data_columns.find { |column| column.name == name }
end
has_column?(name) click to toggle source

Returns true iff this table has the specified column name.

# File lib/cequel/schema/table.rb, line 93
def has_column?(name)
  columns_by_name.has_key?(name.to_sym)
end
has_partition_key?() click to toggle source

Returns true iff this table descriptor currently has at least one partition key defined.

# File lib/cequel/schema/table.rb, line 141
def has_partition_key?
  partition_key_columns.any?
end
key_column_count() click to toggle source

@return [Integer] total number of key columns

# File lib/cequel/schema/table.rb, line 121
def key_column_count
  key_columns.length
end
key_column_names() click to toggle source

@return [Array<Symbol>] names of all key columns (partition +

clustering)
# File lib/cequel/schema/table.rb, line 114
def key_column_names
  key_columns.map { |key| key.name }
end
key_columns() click to toggle source

@return [Array<Column>] all key columns (partition + clustering)

# File lib/cequel/schema/table.rb, line 106
def key_columns
  partition_key_columns + clustering_columns
end
materialized_view?() click to toggle source

@return [Boolean] `true` when this table is a materialized view

# File lib/cequel/schema/table.rb, line 50
def materialized_view?
  @is_view
end
partition_key(name) click to toggle source

@param name [Symbol] name of partition key column to look up @return [PartitionKey] partition key column with given name

# File lib/cequel/schema/table.rb, line 163
def partition_key(name)
  partition_key_columns.find { |column| column.name == name }
end
partition_key_column_count() click to toggle source

@return [Integer] number of partition key columns

# File lib/cequel/schema/table.rb, line 135
def partition_key_column_count
  partition_key_columns.length
end
partition_key_column_names() click to toggle source

@return [Array<Symbol>] names of partition key columns

# File lib/cequel/schema/table.rb, line 128
def partition_key_column_names
  partition_key_columns.map { |key| key.name }
end
property(name) click to toggle source

@param name [Symbol] name of property to look up @return [TableProperty] property as defined on table

# File lib/cequel/schema/table.rb, line 189
def property(name)
  properties.fetch(name, null_table_property).value
end

Protected Instance Methods

null_table_property() click to toggle source
# File lib/cequel/schema/table.rb, line 210
def null_table_property
  @@null_table_property ||= Class.new do
    def value; nil; end
    def name; nil; end
  end.new
end
type(type) click to toggle source
# File lib/cequel/schema/table.rb, line 204
def type(type)
  type = type.kind if type.respond_to?(:kind)

  ::Cequel::Type[type]
end
value() click to toggle source
# File lib/cequel/schema/table.rb, line 212
def value; nil; end