CASSANDRA MCQ 3 — Questions and Answers
Question 1: In a Cassandra primary key defined as PRIMARY KEY ((account_id), event_time), what is the role of event_time?
- Partition key
- Clustering column (Correct answer)
- Secondary index column
- Static column
Correct answer: Clustering column
event_time is a clustering column that determines the sort order of rows within the partition identified by account_id.
Question 2: Which CQL statement creates a table-level snapshot for backup purposes?
- BACKUP TABLE keyspace.table
- CREATE SNAPSHOT OF keyspace.table
- nodetool snapshot -t snap_name keyspace (Correct answer)
- FLUSH TABLE keyspace.table
Correct answer: nodetool snapshot -t snap_name keyspace
`nodetool snapshot` creates hard-link snapshots of SSTables, providing a point-in-time backup without interrupting writes.
Question 3: What happens when you execute a CQL BATCH statement in Cassandra?
- All statements execute atomically across all partitions with ACID guarantees
- Statements targeting the same partition key are applied atomically; cross-partition atomicity is not guaranteed (Correct answer)
- The batch is queued and executed asynchronously by background threads
- Cassandra converts the batch to a lightweight transaction automatically
Correct answer: Statements targeting the same partition key are applied atomically; cross-partition atomicity is not guaranteed
An unlogged batch achieves atomicity only at the partition level; a logged batch provides server-side atomicity but only for mutations to the same partition.
Question 4: Which CQL collection type preserves insertion order and allows duplicate values?
- set
- map
- list (Correct answer)
- tuple
Correct answer: list
A list is an ordered collection of values that permits duplicates, unlike a set which is unordered and deduplicates, or a map which stores key-value pairs.
Question 5: What is the purpose of the ALLOW FILTERING clause in a CQL SELECT statement?
- Enables server-side post-processing of results not supported by the primary key or index (Correct answer)
- Bypasses Cassandra's consistency level check
- Forces a full table scan on all coordinator nodes
- Allows filtering on static columns
Correct answer: Enables server-side post-processing of results not supported by the primary key or index
ALLOW FILTERING instructs Cassandra to perform an in-memory filter on data that cannot be satisfied by the partition key or a secondary index, which can be expensive.
Question 6: Which Cassandra feature lets you query on non-primary-key columns without creating a secondary index?
- Materialized view (Correct answer)
- Counter table
- User-defined type (UDT)
- Lightweight transaction
Correct answer: Materialized view
A materialized view creates a separate denormalized table that is automatically kept in sync with the base table, allowing queries on different primary key columns.
Question 7: In Cassandra CQL, what does the TTL function return when called on a column value?
- The timestamp when the cell was written
- The number of seconds remaining before the cell expires (Correct answer)
- The compaction time for the associated SSTable
- The token value for the row's partition key
Correct answer: The number of seconds remaining before the cell expires
TTL(column_name) in a SELECT returns the remaining time-to-live in seconds for that cell, or null if no TTL was set.
In a Cassandra primary key defined as PRIMARY KEY ((account_id), event_time), what is the role of event_time?