Composite partition key example

Solving data model problems attributed to unbound row growth can sometimes be done by adding another partition key. Let's assume that we want to query security entrance logs for employees. If we were to use a clustering key on a new column named time to one of the preceding examples, we would be continually adding cells to each partition. So we'll build this PRIMARY KEY to partition our data by entrance and day, as well as cluster it on checkpoint_time and username:

CREATE TABLE security_log ( entrance TEXT, day BIGINT, checkpoint_time TIMESTAMP, username TEXT, email TEXT, department TEXT, title TEXT, PRIMARY KEY ((entrance,day),checkpoint_time,username))WITH CLUSTERING ORDER BY (checkpoint_time DESC, username ...

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.