13

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.

2 Answers 2

18

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/

2
  • Hey, thanks for your answer! I assume this is still valid in recent versions of Cassandra? And is there an easy way to bulk-load?
    – tftd
    Apr 23, 2021 at 13:58
  • 2
    You're welcome! I'm a little surprised that this is still useful 8 years later. I've edited it with links to some tools that may help.
    – jbellis
    May 3, 2021 at 14:49
0

You may also change your CQL SELECT query to ORDER BY ASC without altering the table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.