Querying data

While Apache Cassandra is known for its restrictive query model (design your tables to suit your queries), the previous content has shown that CQL can still be quite powerful. Consider the following table:

CREATE TABLE query_test ( pk1 TEXT, pk2 TEXT, ck3 TEXT, ck4 TEXT, c5 TEXT, PRIMARY KEY ((pk1,pk2), ck3, ck4))WITH CLUSTERING ORDER BY (ck3 DESC, ck4 ASC);INSERT INTO query_test (pk1,pk2,ck3,ck4,c5) VALUES ('a','b','c1','d1','e1');INSERT INTO query_test (pk1,pk2,ck3,ck4,c5) VALUES ('a','b','c2','d2','e2');INSERT INTO query_test (pk1,pk2,ck3,ck4,c5) VALUES ('a','b','c2','d3','e3');INSERT INTO query_test (pk1,pk2,ck3,ck4,c5) VALUES ('a','b','c2','d4','e4');INSERT INTO query_test (pk1,pk2,ck3,ck4,c5) VALUES ('a','b','c3','d5','e5'); ...

Get Mastering Apache Cassandra 3.x - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.