Understanding queries

In order to make sense of the various types of queries, we will start with a common data model to be used across the following examples. For this data model, we will return to the authors table, with name as the partition key, followed by year and title as clustering columns. We'll also sort the year in descending order. This table can be created as follows:

CREATE TABLE authors ( 
   name text, 
   year int, 
   title text, 
   isbn text, 
   publisher text, 
   PRIMARY KEY (name, year, title) 
) WITH CLUSTERING ORDER BY (year DESC); 

Also, for the purposes of these examples, we will assume a replication factor of 3 and consistency level of QUORUM.

Query by key

We'll start with a basic query by key:

SELECT * FROM authors WHERE name = 'Tom Clancy';  ...

Get Cassandra 3.x High Availability - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.