Querying Cassandra with CQL
CQL, Cassandra's language: what the primary key allows, row order, ALLOW FILTERING, writes that overwrite and time to live.
- 23 cards
- 4 topics
- Free
The outline, topic by topic
Each topic is weighted the way the exam weighs it.
- Concepts
- Questions
- Sort and link
- Scenarios
A few cards from the deck
CQL: what is it?
Show the answer
Cassandra's query language, whose syntax looks like SQL but which has no join and no subquery.
A query reads a single table: that is why you create one table per query to serve.
Table
mesureswithPRIMARY KEY ((capteur), instant). Sensor c7 has rows at 2025-02-10, 2025-03-01 and 2025-03-05. What is the first row returned bySELECT * FROM mesures WHERE capteur = 'c7' AND instant >= '2025-03-01' LIMIT 2?- The 2025-03-01 row
- The 2025-03-05 row
- The 2025-02-10 row
- None, the query is refused
Show the answer
The 2025-03-01 row
Without
ORDER BY, a partition's rows come out in clustering column order, ascending unless the table was created withCLUSTERING ORDER BY. The range removes 10 February, andLIMIT 2keeps the two left.In
PRIMARY KEY ((capteur, jour), instant), the partition key is made of … and the clustering column is ….Show the answer
In
PRIMARY KEY ((capteur, jour), instant), the partition key is made of capteur and jour and the clustering column is instant.The inner parentheses delimit the partition key; what follows is clustering.
Partition key: what is it?
Show the answer
The first part of the primary key: its value designates the group of rows, and so the machines, where the data is stored.
An efficient
SELECTalways gives the whole partition key, otherwise Cassandra would have to query every node.Reads of one sensor time out and its partition weighs 2 GB, with
PRIMARY KEY ((capteur), instant). Which fix is right?- Add
ALLOW FILTERINGto all the reads - Put
instantalone in the partition key - Put the day in the key:
((capteur, jour), instant) - Add
valeuras a clustering column
Show the answer
Put the day in the key:
((capteur, jour), instant)The partition key has no time bound: a sensor's partition grows without end. Adding the day cuts it into bounded pieces, one per sensor and per day.
- Add