Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alter cassandra column family primary key using cassandra-cli or CQL

I am using Cassandra 1.2.5. After creating a column family in Cassandra using cassandra-cli, is it possible to modify the primary key on the column family using either cassandra-cli or CQL?

Specifically, I currently have the following table (from CQL):

CREATE TABLE "table1" (
  key blob,
  column1 blob,
  value blob,
  PRIMARY KEY (key, column1)
);

I would like the table to be as follows, without having to drop and recreate the table:

CREATE TABLE "table1" (
  key blob,
  column1 blob,
  value blob,
  PRIMARY KEY (key)
);

Is this possible through either cassandra-cli or CQL?

like image 977
Justin Sweeney Avatar asked Aug 24 '13 18:08

Justin Sweeney


People also ask

How do I change my primary key in Cassandra table?

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.

Can we update the primary key column in Cassandra?

You cannot update any column in the primary key because that would change the primary key for the record.

How do you use alter command in Cassandra?

Using ALTER command, you can add a column to a table. While adding columns, you have to take care that the column name is not conflicting with the existing column names and that the table is not defined with compact storage option. Given below is the syntax to add a column to a table.

Which command modifies the column properties of a table in Cassandra?

Modifies the columns and properties of a table. Changes the datatype of a columns, add new columns, drop existing columns, renames columns, and change table properties. The command returns no results.


1 Answers

The primary keys directly determine how and where cassandra stores the data contained in a table (column family). The primary key consists of partition key and clustering key (optional).

The partition key determines which node stores the data. It is responsible for data distribution across the nodes. The additional columns determine per-partition clustering (see compound key documentation).

So changing the primary key will always require all data to be migrated. I do not think that either cqlsh or cassandra-cli have a command for this (as of 2015)..

like image 175
John Avatar answered Oct 19 '22 03:10

John