- Learning Apache Cassandra
- Mat Brown
- 188字
- 2021-07-23 20:34:50
Beyond two columns
We've now seen a table with two columns in its primary key: a partition key, and a clustering column. As it turns out, neither of these roles is limited to a single column. A table can define one or more partition key columns, and zero or more clustering columns.
For instance, in our status application, we might want to allow users to reply to other users' status updates. In this case, each status update would have a stream of replies; replies would be partitioned by the full primary key of the original status update, and each reply would get its own timestamped UUID:
CREATE TABLE "status_update_replies" ( "status_update_username" text, "status_update_id" timeuuid, "id" timeuuid, "author_username" text, "body" text, PRIMARY KEY ( ("status_update_username", "status_update_id"), "id" ) );
Note the extra set of parentheses around the status_update_username
and status_update_id
columns in the PRIMARY KEY
declaration. This tells Cassandra that we want those two columns together to form the partition key. Without the extra parentheses, Cassandra assumes by default that only the first column in the primary key is a partition key, and the remaining columns are clustering columns.
- Boost程序庫(kù)完全開(kāi)發(fā)指南:深入C++”準(zhǔn)”標(biāo)準(zhǔn)庫(kù)(第5版)
- Building a RESTful Web Service with Spring
- NLTK基礎(chǔ)教程:用NLTK和Python庫(kù)構(gòu)建機(jī)器學(xué)習(xí)應(yīng)用
- Oracle從入門(mén)到精通(第5版)
- Mastering Android Development with Kotlin
- 機(jī)器學(xué)習(xí)與R語(yǔ)言實(shí)戰(zhàn)
- 編程菜鳥(niǎo)學(xué)Python數(shù)據(jù)分析
- .NET 4.5 Parallel Extensions Cookbook
- 大數(shù)據(jù)時(shí)代的企業(yè)升級(jí)之道(全3冊(cè))
- Apache Solr PHP Integration
- C++17 By Example
- 你好!Java
- 絕密原型檔案:看看專業(yè)產(chǎn)品經(jīng)理的原型是什么樣
- WCF編程(第2版)
- 信息學(xué)競(jìng)賽寶典:基礎(chǔ)算法