Apache Cassandra Developer Associate study materials
Apache Cassandra Developer Associate study resources

Apache Cassandra Developer Associate: CQL (Cassandra Query Language)

Apache Cassandra Developer Associate · Work through your exam, one topic at a time.

All guide sections

CQL (Cassandra Query Language)

This domain tests fluent CQL: keyspace and table DDL, data types, primary-key syntax, INSERT/UPDATE/DELETE semantics, TTL, batches, lightweight transactions, and paging. Questions often hinge on whether a statement is valid and which consistency or performance trade-off it implies.

DDL and keyspaces

CREATE KEYSPACE sets replication, for example {'class':'NetworkTopologyStrategy','dc1':3}. USE selects a keyspace. Unquoted identifiers are case-insensitive and folded to lowercase; quoted identifiers preserve case and must be quoted consistently. CQL types include text, int, bigint, uuid, timeuuid, timestamp, boolean, decimal, collections (list, set, map), tuples, and user-defined types.

Writes, updates, deletes

INSERT and UPDATE are upserts; a row is created if absent. PRIMARY KEY ((pk), ck) defines partition and clustering columns. UPDATE can set static columns, counters (with counter-specific syntax), collections, and TTLs. USING TTL expires values; expired data becomes tombstones until compaction. DELETE removes a column, row, or partition and also creates tombstones. Batches group statements; a logged batch gives atomicity across partitions at extra cost, while an unlogged batch is only a grouping and can be dangerous across partitions.

Worked example

CREATE TABLE readings (sensor_id text, day date, ts timestamp, value double, PRIMARY KEY ((sensor_id, day), ts)) WITH CLUSTERING ORDER BY (ts DESC); SELECT value FROM readings WHERE sensor_id='s1' AND day='2025-01-01' AND ts >= '2025-01-01 12:00:00' LIMIT 10; This is valid because all partition-key columns are equality-bound and the clustering column has a range predicate. Adding a filter on value would require ALLOW FILTERING and scan partitions, which is not a scalable design.

Lightweight transactions

IF NOT EXISTS and IF condition use Paxos. They are significantly more expensive than normal writes and should be reserved for uniqueness or compare-and-set cases. Use SERIAL or LOCAL_SERIAL consistency for the transaction, and keep the conditional scope small.

Traps

Do not expect ORDER BY on non-clustering columns. Do not use ALLOW FILTERING as a primary access path. Do not assume batches improve throughput. Do not set TTL on a counter. Remember that tombstone-heavy deletes hurt reads until compaction.