Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alter composite primary key in cassandra CQL 3.0

I'm in a situation where I need to change the the composite primary key as follows:

Old Primary Key: (id, source, attribute_name, updated_at);

New Primary Key I want: (source, id, attribute_name, updated_at);

I issued the following (mysql like) command:

ALTER TABLE general_trend_table  DROP PRIMARY KEY,  ADD PRIMARY KEY(source, id, attribute_name, updated_at); 

I got the following error:

Bad Request: line 1:38 no viable alternative at input 'PRIMARY'

any idea how to get around this problem? more specifically I want to know is there any way to change the primary key in cassandra?

like image 976
aroyc Avatar asked Mar 03 '14 06:03

aroyc


People also ask

Can we alter primary key in Cassandra?

You can only rename clustering columns, which are part of the primary key. You cannot rename the partition key because the partition key determines the data storage location on a node.

Does Cassandra allows defining composite primary keys?

False correct cassandra allows to define composite.

What is composite key in Cassandra?

For a table with a composite partition key, Cassandra uses multiple columns as the partition key. These columns form logical sets inside a partition to facilitate retrieval. In contrast to a simple partition key, a composite partition key uses two or more columns to identify where data will reside.


1 Answers

There is no way to change a primary key, as it defines how your data is physically stored.

You can create a new table with the new primary key, copy data from the old one, and then drop the old table.

like image 131
Mikhail Stepura Avatar answered Oct 19 '22 03:10

Mikhail Stepura