无法从CSV文件复制数据

时间:2014-09-12 15:04:09

标签: python csv cassandra nosql

无法使用'来自'的COPY将数据导入Cassandra表/列系列命令。

我们尝试了

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.

表格详情

  

create table earthquakedata(eqtime timestamp,Longitude float,   纬度浮点数,深度浮点数,幅度浮点数,MagType文本,NbStations   float,Gapv float,distance float,RMS float,Source text,EventID   text,Version text,id uuid,primary key(eqtime,id));

这是我们要导入的csv file

请帮帮我。提前谢谢。

1 个答案:

答案 0 :(得分:1)

http://www.datastax.com/documentation/tutorials/gis.zip下载带有地震数据的gis.zip,并将CSV与您正在使用的CSV进行比较。有一个标题和逗号用作分隔符,但基本上不会更改可用的公共数据。在cqlsh中,请记住在COPY命令中调整'path / earthquakes.csv'并使用默认的COPY选项:

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';

运行Brian的python脚本以添加UUID并调整UUID的表后,运行此命令导入所有行:

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.