A technical troubleshooting blog about Oracle with other Databases & Cloud Technologies.

Cassandra import & export

1 min read
pile of cylinder silver keg tank lot

Photo by ELEVATE on Pexels.com

Cassandra.csv file data:

car_make,car_model,start_year,id,first_name,last_name,department
BMW,Saloon,2011,1,Johny,Depp,IT
AUDI,Saloon,2013,2,Meryl,Streep,HR
LEXUS,Sports,2011,3,Brad,Pitt,IT
AUDI,Sports,2012,4,Tom,Hanks,FI
BMW,Compact,2012,5,Angelina,Jolie,FI
BMW,Saloon,2011,6,Tom,Cruise,HR
AUDI,Compact,2013,7,Scarlett,Johansson,IT
LEXUS,Compact,2013,8,Matt,Damon,IT
NISSAN,Saloon,2013,9,Julia,Roberts,FI
BMW,Saloon,2011,10,Nicole,Kidman,HR
NISSAN,Compact,2012,11,George,Clooney,HR
AUDI,Saloon,2012,12,Dwayne,Johnson,IT
AUDI,Sports,2011,13,Natalie,Portman,FI

Create keyspace and create tables and then importing the data form local system to Cassandra:

$./bin/nodetool status
$./cqlsh 192.168.0.104
Cqlsh>CREATE KEYSPACE test_keyspace WITH replication = {‘class’:’SimpleStrategy’, ‘replication_factor’:1};

Cqlsh>use test_keyspace;

Cqlsh>CREATE TABLE test_csv_import (car_make text, car_model text, start_year int, id int, first_name text,last_name text, department text, PRIMARY KEY(car_make, car_model, start_year,id);

Below are copied csv data from local system:

Cqlsh>COPY test_csv_import(car_make, car_model,start_year, id, first_name,last_name,department) FROM ‘/home/jumpstartcs/Desktop/Cassandra.csv ‘WITH DELIMITER=’,’ AND HEADERS=TRUE;

Now we will export data from Cassandra to local file system: