1

Context :

I need to change the order of my primarey key

PRIMARY KEY (a, b) --> PRIMARY KEY (b,a)

But in cassandra I can't just alter PRIMARY KEY like this : alter composite primary key in cassandra CQL 3.0

So, I just want to move data from the old table to a new table I've created. Since the number of rows is huge I need to use Spark.

Data "in" :

I get the data like this from the old table:

JavaRDD<CassandraRow> initialRDD;

Question :

Id it possible to directly save it back to the new table since the row itself didn't change?

What I managed to do :

I could do this but it seems absurd to map from CassandraRow to CassandraRow

javaFunctions(initialRDD).writerBuilder("targetKeyspace", "targetTable", mapToRow(CassandraRow.class)).saveToCassandra();

thus it's prompting me an error :

Some primary key columns are missing in RDD or have not been selected: ...
Community
  • 1
  • 1
Fundhor
  • 3,369
  • 1
  • 25
  • 47

1 Answers1

1

I don't use spark very much, but I think you would need to create a second table with the new key order, then load the first table into an RDD using the spark connector:

val rdd = sc.cassandraTable("keyspace", "table1")

Then save it to the second table with the new key order:

rdd.saveToCassandra("keyspace", "table2", SomeColumns("b", "a"))

Jim Meyer
  • 9,275
  • 1
  • 24
  • 49