Vikram
Vikram

Reputation: 837

Unable to copy data from CSV file

Unable to import data into Cassandra Table / Column Family using the 'COPY from' command.

We tried

cqlsh> copy eqdata from '/home/swiftguy/cassandra/earthquakedata/weather-data-with-uuid.csv';
Bad Request: line 1:298 no viable alternative at input ')'
Aborting import at record #0 (line 1). Previously-inserted values still present.

Table details

create table earthquakedata ( eqtime timestamp, Longitude float, Latitude float, Depth float, Magnitude float, MagType text, NbStations float, Gapv float, distance float, RMS float, Source text, EventID text, Version text, id uuid, primary key (eqtime, id));

This is the csv file we are trying to import

Please help me out. Thanks in advance.

Upvotes: 0

Views: 1960

Answers (1)

catpaws
catpaws

Reputation: 2283

Download the gis.zip from http://www.datastax.com/documentation/tutorials/gis.zip with the earthquake data and compare the CSV with the CSV you're using. There's a header and commas are used as the delimiter, but essentially unaltered from the available public data. In cqlsh, do this remembering to adjust the 'path/earthquakes.csv' in the COPY command and using the default COPY options:

CREATE TABLE earthquakes ( 
             datetime text PRIMARY KEY, 
             latitude double, 
             longitude double, 
             depth double, 
             magnitude double, 
             magtype text, 
             nbstations int, 
             gap double, 
             distance double, 
             rms double, 
             source text, 
             eventid int 
           );
COPY earthquakes (datetime, latitude, longitude, depth, magnitude, magtype, nbstations, gap, distance, rms, source, eventid) FROM 'path/earthquakes.csv' WITH HEADER = 'true';

After running Brian's python script to add UUIDs, and adjusting the table for the UUID, running this command imported all the rows:

cqlsh:mykeyspace> COPY earthquakes (datetime, latitude, longitude, depth, magnitude, magtype, nbstations, gap, distance, rms, source, eventid,newid) FROM '/Users/krishahn/Downloads/gis/out.csv' WITH HEADER = 'true';
77037 rows imported in 2 minutes and 35.913 seconds.

Upvotes: 1

Related Questions