0

I need to create a csv file in cassandra, that will only give the csv file of specific rows, and specific column.

CREATE TABLE abcd (
    a bigint,
    b bigint,
    c bigint,
    d int,
    e int,
    PRIMARY KEY (a)
);

Select a,c,e from abcd where a in (1,4,5,6,7,8,9,.....);

If I use COPY command I can select columns, but I can't select from rows. How to get a csv file in cassandra where I can select from rows and columns. Is it possible to get a csv file like this?

Aaron
  • 55,518
  • 11
  • 116
  • 132
Rubayat Jinnah
  • 414
  • 4
  • 20

2 Answers2

3

you could use cqlsh capture functionality to output the result into a file. then just pass the result through sed: sed -i -e 's/|/,/g' /tmp/test.csv (or any other wrapper you can come up with :) )

cohenjo
  • 576
  • 3
  • 5
2

The COPY command just copies the complete table out to your required .csv. format file. The documentation here covers the complete synopsis of the COPY command. (Assuming you're using Cassandra 2.0 or 2.1)

http://docs.datastax.com/en/cql/3.1/cql/cql_reference/copy_r.html

I would say you'd be better off here using one of open source drivers like the Datastax python driver, then you can have more control over your select statement and only pull out the rows you need.

https://datastax.github.io/python-driver/getting_started.html

There is also a tool here you might find useful, I've seen quite a number of people use this to suit their needs:

https://github.com/brianmhess/cassandra-loader

Hope this helps.

markc
  • 2,129
  • 16
  • 27