11

Trying to find a way to easily transfer all the rows from a Cassandra ColumnFamily/Table to another.

The COPY command, as I understand, is a good option. However, as it dumps all the data to .csv on disk and then loads it back, I can't help but wonder if there is a better way to do it in-engine.

A specific example of what I mean would be the INSERT * FROM my_table INTO my_other_table available in many SQL databases. Of course, I realize that Cassandra is NoSQL and therefore does not to work the same way - but it seems like something which might be available.

What is a good way to accomplish this?

Thanks very much!

10
cqlsh -k mykeyspace -e 'COPY fromTable(columnNames) TO STDOUT' | head -n -1 | 
cqlsh -k mykeyspace -e 'COPY toTable(columnNames) FROM STDIN'
  • 1
    Thanks, this looks interesting. However, I'd be concerned about character escaping and other issues, especially when dealing with certain types of data. Is that a concern at all? – Juan Carlos Coto Aug 19 '14 at 19:04
  • 1
    Good idea, but as @JuanCarlosCoto said, it doesn't work with certain data types. I tried it on a table with a blob column and it crashed on a newline character. – Alexandre DuBreuil May 29 '15 at 10:09
  • On cassandra 2.1.2 I had to modify the command to be head -n -2 because the ouput of COPY includes two lines at the end that need to be trimmed. It was still working, but it got mad about the empty line at the end. – ctlacko Oct 1 '15 at 16:10
  • Note - Only use COPY FROM to import datasets that have less than 2 million rows. To import large datasets, use the Cassandra bulk loader. – GaneshP Oct 9 '18 at 19:38
2

Did you take a look at sstableloader http://www.datastax.com/documentation/cassandra/2.0/cassandra/tools/toolsBulkloader_t.html ?

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.