Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cassandra-CQl : Change Clustering order for Created Column Family

Tags:

cassandra

cql

I know that I can define clustering order when I create a table by cql as code below:

create table test(
id int,
time timestamp,
value text,
primary key(id,time)) with clustering order by (time desc)

but I want change the clustering for table test after its creation with alter:

alter table  test
with clustering order by (item asc)

but I got error by that. Thanks for any help.

like image 252
S.Mohamed Mahdi Ahmadian zadeh Avatar asked Jul 31 '13 14:07

S.Mohamed Mahdi Ahmadian zadeh


People also ask

Can we alter clustering key in Cassandra?

Based on how Cassandra stores the data, updating clustering columns (Primary key) is not possible.

What is the relationship between a column family and CQL table?

To answer the original question you posed: a column family and a table are the same thing. The name "column family" was used in the older Thrift API. The name "table" is used in the newer CQL API.

Which of the following is used to alter the schema of the table in CQL?

ALTER TABLE command is used to alter the table after creating it. You can use the ALTER command to perform two types of operations: Add a column.

How do I sort data in Cassandra?

Cassandra supports sorting using the clustering columns. When you create a table, you can define clustering columns which will be used to sort the data inside each partition in either ascending or descending orders. Then you can easily use the ORDER BY clause with the ASC or DESC options.


1 Answers

Changing the clustering order would require rewriting all your data on disk in a different order. The standard way to do this is to leverage Spark with the Cassandra Spark Connector: https://github.com/datastax/spark-cassandra-connector

Alternatively, if you're early in your dev process or it's a relatively small amount of data, you can use the bulk loader to throw it into a new table: https://docs.datastax.com/en/dsbulk/doc/

like image 88
jbellis Avatar answered Oct 12 '22 00:10

jbellis