Class: Cassandra::MaterializedView
- Inherits:
-
ColumnContainer
- Object
- ColumnContainer
- Cassandra::MaterializedView
- Defined in:
- lib/cassandra/materialized_view.rb
Overview
Represents a cassandra materialized view
Instance Attribute Summary
Attributes inherited from ColumnContainer
#clustering_columns, #id, #keyspace, #name, #options, #partition_key, #primary_key
Instance Method Summary collapse
-
#base_table ⇒ Table
The table that this materialized view applies to.
-
#to_cql ⇒ String
A cql representation of this materialized view.
Methods inherited from ColumnContainer
#column, #each_column, #has_column?
Instance Method Details
#base_table ⇒ Table
42 43 44 |
# File 'lib/cassandra/materialized_view.rb', line 42 def base_table @keyspace.table(@base_table_name) end |
#to_cql ⇒ String
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/cassandra/materialized_view.rb', line 47 def to_cql keyspace_name = Util.escape_name(@keyspace.name) cql = "CREATE MATERIALIZED VIEW #{keyspace_name}.#{Util.escape_name(@name)} AS\nSELECT " cql << if @include_all_columns '*' else @columns.map do |column| Util.escape_name(column.name) end.join(', ') end cql << "\nFROM #{keyspace_name}.#{Util.escape_name(@base_table_name)}" cql << "\nWHERE #{@where_clause}" if @where_clause cql << "\nPRIMARY KEY ((" cql << @partition_key.map do |column| Util.escape_name(column.name) end.join(', ') cql << ')' unless @clustering_columns.empty? cql << ', ' cql << @clustering_columns.map do |column| Util.escape_name(column.name) end.join(', ') end cql << ")\nWITH #{@options.to_cql.split("\n").join("\n ")};" end |