Vignesh Mohan
Vignesh Mohan

Reputation: 11

Cassandra: creating a Partition Key

I have a table student (id,marks,score) in cassandra. i created the table with id as primary key. I need to sort table by score and i haven't created a partition key for score. How to create a partition key without recreating table?

Upvotes: 0

Views: 186

Answers (2)

Zanson
Zanson

Reputation: 4031

The Materialized Views feature of Cassandra 3.0 allows you to have a new view with a different column as the partition key. The view can be added without re-creating the table.

There is a good discussion of when and when not to use them here.

Upvotes: 0

Abhishek Garg
Abhishek Garg

Reputation: 2288

Cassandra does not allow you to alter the primary key as a primary key defines how data will be physically stored on the disk. If you really want to change it, as you already mentioned the only way is to create a new table with different primary key and migrate all the data to the new table.

In your new table, you will probably still want ID as your partition key (assuming you know the ID at query time), and score as a clustering column. This will allow you to search for a specific ID and then sort it by the scores associated with that partition.

Upvotes: 2

Related Questions