Now that we know what partition and clustering keys are, we can put them to use. Assume that I have to design a table to track user logins to an application. I could solve that with a table like this:
CREATE TABLE packt.logins_by_user ( user_id text, login_datetime timestamp, origin_ip text, PRIMARY KEY ((user_id), login_datetime) ) WITH CLUSTERING ORDER BY (login_datetime DESC);
Next, I'll write some data to test with:
INSERT INTO logins_by_user (user_id, login_datetime, origin_ip) VALUES ('aploetz','2017-06-01 12:36:01','192.168.0.101'); INSERT INTO logins_by_user (user_id, login_datetime, origin_ip) VALUES ...