Cassandra query language (CQL) and Cassandra Java Client Example

Cassandra Table structure/Terminology

  • Before going to learn CQL commands, we just need to know terminology in cassandra.
RDBMS Cassandra Terminology
Database Keyspace
Table Column Family
Primary key Row Key
Column name Column name
Column value column value

CQL Commands

  • Creating a key-space

  • Use the keyspace (will use that key space)

Note: key spaces are equivalent to database/schema in RDBMS

  • Get list of key spaces

  • Create table

  • Get list of tables in a key-space

  • Insert data into table

  • Describe table

  • Create index

  • Update data in table

  • Delete data in table

  • Limitations in CQL

    • Delete query without where condition will not work.
    • Delete/Update query with Non-primary key in where clause will not works.
    • To use Select query with Non-primary key in where clause, we should index that column.
    • Instead of Update we can use insert with same primary key value, will replace the existing record with new values. (Upsert)
    • we cannot use ‘or’ clause in cql instead we have to use ‘in’ clause.

      Java client example

  • Take a Java maven project and Add below dependency