Exporting Data from Cassandra to CSV file

11.5k views Asked by At

Table Name : Product

uid                                  | productcount | term                 | timestamp

304ad5ac-4b6d-4025-b4ea-8b7991a3fe72 |           26 |                dress | 1433110980000
6097e226-35b5-4f71-b158-a1fe39a430c1 |            0 |              #751104 | 1433861040000

Command :

COPY product (uid, productcount, term, timestamp) TO 'temp.csv';

Error:

Improper COPY command.

Am I missing something?

3

There are 3 answers

1
medvekoma On BEST ANSWER

The syntax of your original COPY command is also fine. The problem is with your column named timestamp, which is a data type and is a reserved word in this context. For this reason you need to escape your column name as follows:

COPY product (uid, productcount, term, "timestamp") TO 'temp.csv';

Even better, try to use a different field name, because this can cause other problems as well.

0
Ritesh Sinha On

I am able to export the data into CSV files by using by below command. Avoiding the column names did the trick.

copy product to 'temp.csv' ;
0
Nilesh Shinde On

Use following commands to get the data from Cassandra Tables to CSV

This command will copy Top 100 rows to CSV file.

cqlsh -e"SELECT * FROM employee.employee_details" > /home/hadoop/final_Employee.csv

This command will copy All the rows to CSV file.

cqlsh -e"PAGING OFF;SELECT * FROM employee.employee_details" > /home/hadoop/final_Employee.csv