Cassandra View

I. Introduction

Cassandra NOSQL database as a P2P structure, using HBase different decentralized architecture, very widely used in foreign countries, even in popularity over Hbase. Today This article describes some of the Cassandra design point to note in terms of view.

II. Established view

Cassandra views created following statement:

create_materialized_view_statement ::=  CREATE MATERIALIZED VIEW [ IF NOT EXISTS ] view_name AS
                                            select_statement
                                            PRIMARY KEY '(' primary_key ')'
                                            WITH table_options

example:

CREATE TABLE emp (
    emp_id int PRIMARY KEY,
    emp_city text,
    emp_name text,
    emp_phone varint,
    emp_sal varint
)

create MATERIALIZED VIEW emp_view as 
select * from emp where emp_id is not null 
and emp_name is not null 
primary key(emp_id,emp_name) 
with comment='this is an iew';

View emp_view established based on the emp table. During the views created mainly includes three parts: select statement, primary key definitions, view configuration options. In this three-part main it should be noted that the first two parts.

select statement:

1. The view from the source table column must not use any function when using a column select statement, * may be used as a shortcut to select all columns.

2. When the column in the source table has a static definition, can not be used when creating the view *, shall be listed using the static declaration can not be included in the materialized view.

3. It does not have a sorting clause, not a limiting, nor has ALLOW FILTERING.

Primary key definition:

1. Each view must have a primary key, and it must contain all of the primary key columns of the base table, which ensures that each row corresponds exactly to the view of the row of the base table.

2. The primary key can not contain a primary key column in the source table primary key

3. view as the primary key, must be defined not null

View Configuration Options:

When a view is created, plus some configuration details, see

http://cassandra.apache.org/doc/latest/cql/ddl.html#create-table-options

III. Delete View

drop_materialized_view_statement ::=  DROP MATERIALIZED VIEW [ IF EXISTS ] view_name;

 

Guess you like

Origin www.cnblogs.com/tangs1/p/11969723.html