cassandra copy data from one columnfamily to another columnfamily
Asked Answered
B

3

10

I am newbie to cassandra . I need to copy data from one columnFamily to another columnFamily in same keyspace in cassandra .Say for ex we have a A1 columnFamily in keyspace K1 , so now i need to create columnFamily A2 in the same keyspace K1 .Here i need to copy data from columnFamily A1 to A2 .A1 and A2 have the same schema .I read online docs where in we can use sstable loader to copy data from one cassandra cluster to another . But here i need to copy data from one columnFamily to another columnFamily within same keyspace .

Any ideas on above . Or is it achievable i am not sure of it .

Bolt answered 9/7, 2013 at 7:16 Comment(0)
S
10

Depending on the cassandra version you can use the copy cql command. To use that you need a cql client like the one that is distributted with cassandra.

First you have to copy the columnfamily A1 to a CSV file using:

COPY K1.A1 (column1, column2,...) TO 'temp.csv';

And after that copy the file to the new column family

COPY K1.A2 (column1, column2,...) FROM 'temp.csv';

Obviously you have to change the name of the columns to your names.

More information:

http://www.datastax.com/documentation/cassandra/1.2/index.html#cassandra/cql_reference/copy_r.html

Scandura answered 9/7, 2013 at 11:25 Comment(2)
Please if the solutions works for you, check the answer as correct so other person that have the same doubt can check that this is the method to go for.Scandura
i am trying to do the same but it is giving me error something like Invalid STRING constant, Previously-inserted values still present.. So is it necessary to truncate the data after doing COPY K1.A1 (column1, column2,...) TO 'temp.csv'; step..Ishmael
E
2

Please be aware of a limit of max. 2 million rows when using the COPY command. See https://docs.datastax.com/en/cql/3.3/cql/cql_reference/cqlshCopy.html

Note: Only use COPY FROM to import datasets that have less than 2 million rows. To import large datasets, use the Cassandra bulk loader

Early answered 25/1, 2017 at 22:35 Comment(0)
T
0

cqlsh -k mykeyspace -e 'COPY fromTable(columnNames) TO STDOUT' | head -n -1 | cqlsh -k mykeyspace -e 'COPY toTable(columnNames) FROM STDIN'

Telford answered 16/8, 2014 at 12:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.