Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do data migration of Cassandra from one keyspace to another keyspace?

I created an old keyspace in Cassandra cluster but found the definition of its "comparator" is wrong, so I have to recreate a new keyspace and do data migration. Is there any tool to do data migration? or I have to program with Thrift client read all data from old keyspace and write them to new keyspace? Any suggestions or code snippets is welcome!

like image 607
user1284795 Avatar asked Aug 22 '13 05:08

user1284795


2 Answers

This is a commun question, and I think it has been asked before here. You can use the COPY command in C*. You will find more details here http://www.datastax.com/dev/blog/ways-to-move-data-tofrom-datastax-enterprise-and-cassandra

like image 180
hjarraya Avatar answered Sep 19 '22 14:09

hjarraya


We can do it using COPY command in cql. Using COPY command we can save table data to .csv file and back to a table from .csv file. But, the better approach will be to write a program to read from table and write it to another table because importing from csv may fail if the table contains collection column types like list<text>, map<text, text>, set<text>.

Eg :- To copy table data from table to .csv file :-

COPY keyspace1.table1 (column1, column2) TO 'path/to/file/keyspace1_table1.csv';

To copy csv data from file to a table :-

COPY keyspace2.table1 (column1, column2) FROM 'path/to/file/keyspace1_table1.csv';

Refer Cassandra migration tool

like image 44
Visruth Avatar answered Sep 19 '22 14:09

Visruth