Reversing clustering order in the schema

While it's useful to be able to show the newest status updates first using ORDER BY, it would be even better if the rows were naturally ordered newest first. Although we can't change the clustering order of an existing table, we can make a new table that has the same structure as user_status_updates, but with id ordered newest first:

CREATE TABLE "reversed_user_status_updates" ("username" text, "id" timeuuid, "body" text, PRIMARY KEY ("username", "id")) WITH CLUSTERING ORDER BY ("id" DESC);

The CLUSTERING ORDER BY property tells Cassandra that we want to store columns in descending order by id, rather than the default ascending order. Adding a few quick rows to our table, we can see the reversed ...

Get Learning Apache Cassandra - Second 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.