0

I want to copy only selective rows and columns from a specific Cassandra table. How do I that?

I am able to copy complete tables in .csv format with the help of:https://docs.datastax.com/en/cql/3.1/cql/cql_reference/copy_r.html

But, how do I copy selective data only?

I tried referencing: Selective copy cassandra million rows data to external file AND Cassandra selective copy . But none of them work.

Community
  • 1
  • 1
Abhay Bh
  • 43
  • 1
  • 7
  • cqlsh host port -u username -e "select column1, column2 from keyspace.tableName" | sed 's/[\t]/,/g' > 'path_to_file_where_you_want_to_copy_result' This command can be used to copy specific columns from a table(s) into a file. Note: If you have configured username and password to connect to cassandra, this command will prompt for password, give password to execute the command. – Shivanshu Goyal Apr 25 '19 at 05:00

2 Answers2

0

There is no built-in support for selective copy. You could either export the whole bunch of data and do filtering on the client side or use some Map-Reduce (or Spark) job otherwise to extract the data you need.

S. Stas
  • 800
  • 4
  • 8
0

You can specify which columns you would like to update. Say, if you 10 different columns but you want to copy only 3 of them then you specify like this

COPY products (name, id, color) from 'products.csv';

The only constraint over here is the CSV files should contain the only 3 columns. I'd suggest you to make a copy of csv file and refactor it. You can easily do it in python using csv library.

Bigby
  • 321
  • 5
  • 16