- Learning Apache Cassandra(Second Edition)
- Sandeep Yarabarla
- 111字
- 2021-07-03 00:19:35
Composite partition key with multiple clustering columns
It is also possible to declare a table that has both a composite partition key as well as multiple clustering columns. Suppose we wish to model a status update replies table to be clustered by the reply date first and then the reply time; we would have a table like this:
CREATE TABLE "status_update_replies" (
"status_update_username" text,
"status_update_id" timeuuid,
"status_date" date,
"status_time" time,
"id" timeuuid,
"author_username" text,
"body" text,
PRIMARY KEY (
("status_update_username", "status_update_id"),
"status_date", "status_time", "id"
)
);
In the preceding table, the partition key is a combination of status_update_username and status_update_id.
The replies are clustered by status_date, status_time and id.