Anseh Danesh
Anseh Danesh

Reputation: 633

Import .csv file into cassandra

I want to import a CSV file into cassandra. When I write this command on cassandra cqlsh, I got an error: command is:

COPY table ( ID,  name) FROM 'table.csv' WITH HEADER = TRUE;

and the error:

Can't open 'table.csv' for reading: [Errno 2] No such file or directory: 'table.csv'

Can any one tell me what does it mean?

Upvotes: 7

Views: 12122

Answers (4)

mirekphd
mirekphd

Reputation: 6753

Here's my checklist for this error for the containerized use cases (e.g. when using bitnami/cassandra:latest):

  1. Make sure the path you are supplying to the COPY command is the internal (container) path, not an external one (host, PVC etc).

  2. Make sure the CSV file has correct read permissions for the internal container user ID, not the external one (host, PVC etc), especially if the CSV was created in another containerized app (e.g. Jupyter Notebook).

For example, assuming you have run your Cassandra container like this:

$ docker run -d --rm --name cassandra -v /tmp:/bitnami -u 1001 bitnami/cassandra:4.0

Then the COPY command issued in cqlsh to import a /tmp/random_data1.csv from the host should be:

> COPY dicts.dict1 (key, value) FROM '/bitnami/random_data1.csv' WITH HEADER = true;

and the /tmp/random_data1.csv file should be owned by user 1001 or accessible for reading for all users.

Upvotes: 0

reddy malathi
reddy malathi

Reputation: 15

In cassandra, It is required to mention the file name correctly (case sensitive).

use pwd command to know the current path in ubuntu and then give the file name.

For example if my path after executing pwd command is /home/xyz/Docs

Then cassandra command to copy the file is

COPY table ( ID,  name) FROM '/home/xyz/Docs/table.csv' WITH HEADER = TRUE;

Upvotes: 0

manish1706
manish1706

Reputation: 1599

make sure your local directory should be same and there also same file put up.

cqlsh.bat 192.168.1.xx -k [keyspace name] -e "COPY [domain] FROM 'filename' WITH HEADER=true"

Upvotes: 1

karthi
karthi

Reputation: 243

table.csv file should be in cassandra installation directory(where you run cqlsh).

File name is case senstive, so check with orginal file name case.

Upvotes: 2

Related Questions