Class: Cequel::Schema::TableReader

Inherits:
Object
  • Object
show all
Defined in:
lib/cequel/schema/table_reader.rb

Overview

A TableReader will query Cassandra’s internal representation of a table’s schema, and build a Table instance exposing an object representation of that schema

Since:

  • 1.0.0

Constant Summary collapse

COMPOSITE_TYPE_PATTERN =

Since:

  • 1.0.0

/^org\.apache\.cassandra\.db\.marshal\.CompositeType\((.+)\)$/
REVERSED_TYPE_PATTERN =

Since:

  • 1.0.0

/^org\.apache\.cassandra\.db\.marshal\.ReversedType\((.+)\)$/
COLLECTION_TYPE_PATTERN =

Since:

  • 1.0.0

/^org\.apache\.cassandra\.db\.marshal\.(List|Set|Map)Type\((.+)\)$/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(keyspace, table_name) ⇒ TableReader

Returns a new instance of TableReader.

Parameters:

  • keyspace (Metal::Keyspace)

    keyspace to read the table from

  • table_name (Symbol)

    name of the table to read

Since:

  • 1.0.0



47
48
49
50
# File 'lib/cequel/schema/table_reader.rb', line 47

def initialize(keyspace, table_name)
  @keyspace, @table_name = keyspace, table_name
  @table = Table.new(table_name.to_sym)
end

Class Method Details

.get(keyspace, table_name) ⇒ TableReader

Return a Cequel::Schema::TableReader instance

Parameters:

  • keyspace (Metal::Keyspace)

    keyspace to read the table from

  • table_name (Symbol)

    name of the table to read

Returns:

Since:

  • 1.0.0



38
39
40
# File 'lib/cequel/schema/table_reader.rb', line 38

def self.get(keyspace, table_name)
  new(keyspace, table_name)
end

.read(keyspace, table_name) ⇒ Table

Read the schema defined in the database for a given table and return a Cequel::Schema::Table instance

Parameters:

  • keyspace (Metal::Keyspace)

    keyspace to read the table from

  • table_name (Symbol)

    name of the table to read

Returns:

  • (Table)

    object representation of table in the database, or ‘nil` if no table by given name exists

Since:

  • 1.0.0



28
29
30
# File 'lib/cequel/schema/table_reader.rb', line 28

def self.read(keyspace, table_name)
  new(keyspace, table_name).read
end

Instance Method Details

#materialized_view?boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Check if it is materialized view

Returns:

  • (boolean)

    true if it is materialized view

Since:

  • 1.0.0



79
80
81
82
# File 'lib/cequel/schema/table_reader.rb', line 79

def materialized_view?
  cluster.keyspace(keyspace.name)
    .has_materialized_view?(table_name.to_s)
end

#readTable

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Read table schema from the database

Returns:

  • (Table)

    object representation of table in the database, or ‘nil` if no table by given name exists

Since:

  • 1.0.0



61
62
63
64
65
66
67
68
69
70
# File 'lib/cequel/schema/table_reader.rb', line 61

def read
  if table_data.present?
    read_partition_keys
    read_clustering_columns
    read_data_columns
    read_properties
    read_table_settings
    table
  end
end