RDBMS vs Cassandra

  1. No Joins #81
  2. No Referential Integrity
    1. ie Foreign key & Cascading deletes are not available
  3. Denormalized
    1. Can be achieved through,
      1. Classic Denormalization
      2. Materialized Views (Starting from Cassandra v3.0)
  4. Query first Design
  5. Data Storage Consideration
    1. In Cassandra, a table might be partitioned across multiple nodes
    2. A Query that only search for a data in a single partition(Single Node) will be more faster that searching in multiple partition(Multiple nodes) #83
  6. Sorting Order
    1. Is fixed in Cassandra (we cannot change the order of data using queries as we can do in RDBMS...Ex ; select * from ... ORDER BY)
    2. Is determined based on Clustering Columns #84

How to create Secondary Index?

cqlsh:ks> -- Note : Secondary index are not recommended for, #76 #94
cqlsh:ks> -- - Columns with High Cardinality
cqlsh:ks> -- - Columns with Low Cardinality
cqlsh:ks> -- - Columns that are frequently updated or deleted
cqlsh:ks> -- ** Better to have a denormalized table rather than secondary
cqlsh:ks> --    index #77
cqlsh:ks> -- # a120 > a93
cqlsh:ks>
cqlsh:ks> -- Create Table
cqlsh:ks> drop table student;
cqlsh:ks> drop type mark;
cqlsh:ks>
cqlsh:ks> create type mark (
      ...    math text,
      ...    science text
      ... );
cqlsh:ks>
cqlsh:ks> create table student(
      ...    name text,
      ...    class text,
      ...    month_v_attendance map<text, text>,
      ...    week_v_attendance map<text, text>,
      ...    subjects frozen<mark>,
      ...    primary key(name)
      ... );
cqlsh:ks>
cqlsh:ks> -- Insert Data
cqlsh:ks> insert into
      ...    student( name, class, subjects, month_v_attendance,
      ...             week_v_attendance)
      ... values('bob', '3rd', {math: '70', science: '80'},
      ...       {'jan': '90%'}, {'3rdweek' : '90%'});
cqlsh:ks>
cqlsh:ks> select * from student;

 name | class | month_v_attendance | subjects                    | week_v_attendance
------+-------+--------------------+-----------------------------+--------------------
  bob |   3rd |     {'jan': '90%'} | {math: '70', science: '80'} | {'3rdweek': '90%'}

(1 rows)
cqlsh:ks>
cqlsh:ks> select * from student where class='3rd';
InvalidRequest: Error from server: code=2200 [Invalid query] message="Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING"
cqlsh:ks>
cqlsh:ks> -- Create Secondary Index
cqlsh:ks> create index classindex on student (class);
cqlsh:ks> select * from student where class='3rd';

 name | class | month_v_attendance | subjects                    | week_v_attendance
------+-------+--------------------+-----------------------------+--------------------
  bob |   3rd |     {'jan': '90%'} | {math: '70', science: '80'} | {'3rdweek': '90%'}

(1 rows)
-- SASI : SSTable Attached Secondary Index : Read more...#78

How to create user defined data type (UDT)....

cqlsh:ks> // UDT can be created as part of keyspace
cqlsh:ks> create type mark (
      ...    math text,
      ...    science text
      ... );
cqlsh:ks>
cqlsh:ks> // UDT can be utilized by using the 'frozen' keyword #74
cqlsh:ks> // Note : The concept of 'frozen' is given for forward
cqlsh:ks> //        compatibility
cqlsh:ks> create table student(
      ...    name text,
      ...    class text,
      ...    subjects frozen<mark>,
      ...    primary key(name));
cqlsh:ks>
cqlsh:ks> insert into student(name, class, subjects) values('bob', '3rd',
      ...    {math: '70', science: '80'});
cqlsh:ks> select * from student;

 name | class | subjects
------+-------+-----------------------------
  bob |   3rd | {math: '70', science: '80'}

(1 rows)

Collection Data types : set, list, map...

  1. set #71
  2. list
  3. map

Some more data types : boolean, blob, inet, counter


  1. boolean #69
  2. blob
  3. inet
    1. To store IPV4 & IPV6 addresses
  4. counter
    1. Is a 64 bit Signed Integer

Data types for Universally Unique Identifier (UUID)

  1. uuid #68
  2. timeuuid

Data and Time data types...

  1. timestamp #68
  2. data
  3. time

Text Data Types...


  1. text, varchar
    1. UTF-8 Character String. Recommended #67
  2. ascii
    1. ASCII Character String
Hints : $LANG, HELP TEXT_OUTPUT