cassandra 的副本不插入一行
cassandra's copy does not insert a single row
在 cassandra ([cqlsh 5.0.1 | Cassandra 2.2.0 | CQL spec 3.3.0 | Native protocol v4]
) 中我创建了以下 table
create table flotilla.events1 (
f1 int,
f2 int,
f3 int,
f4 timestamp,
f5 text,
f6 text,
f7 text,
f8 int,
f9 text,
f10 double,
f11 int,
primary key (f2, f1)
);
并尝试插入以下数据 (/tmp/b.csv
):
f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11
1,751168360,0,'2014-04-01T09:56:13.491','a','G','G',296,'G',242,242
2,751168360,0,'2014-04-01T09:56:13.491','a','G','G',296,'G',8,8
3,751168360,0,'2014-04-01T09:56:13.491','a','G','G',296,'G',0,0
4,751168360,0,'2014-04-01T09:56:13.491','a','G','G',296,'G',1,1
5,751168360,0,'2014-04-01T09:56:13.491','a','G','G',296,'G',0,0
6,751168360,0,'2014-04-01T09:56:13.491','a','G','G',296,'G',0,0
7,751168360,0,'2014-04-01T09:56:13.491','a','A','A',279,'P',2.55,255
8,751168360,0,'2014-04-01T09:56:13.491','a','A','A',279,'P',0,0
使用以下命令:
copy flotilla.events1 (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11) from '/tmp/b.csv' with header=true;
卡桑德拉说:
8 rows imported in 0.550 seconds.
当我检查 table:
SELECT * from flotilla.events1 ;
f2 | f1 | f10 | f11 | f3 | f4 | f5 | f6 | f7 | f8 | f9
----+----+-----+-----+----+----+----+----+----+----+----
(0 rows)
没有一个错误。多么骇人听闻?
但是如果我插入第一行 INSERT INTO
:
insert into flotilla.events1 (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11) values (1,751168360,0,'2014-04-01T09:56:13.123','a','G','G',296,'G',242,242) ; select * from flotilla.events1;
f2 | f1 | f10 | f11 | f3 | f4 | f5 | f6 | f7 | f8 | f9
-----------+----+-----+-----+----+--------------------------+----+----+----+-----+----
751168360 | 1 | 242 | 242 | 0 | 2014-04-01 09:56:13+0200 | a | G | G | 296 | G
(1 rows)
多么骇人听闻?
与我一小时前回答此问题的方式类似 ,为了使其正常工作,我只是从您的 CSV 文件中删除了所有单引号。
f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11
1,751168360,0,2014-04-01T09:56:13.491,a,G,G,296,G,242,242
2,751168360,0,2014-04-01T09:56:13.491,a,G,G,296,G,8,8
3,751168360,0,2014-04-01T09:56:13.491,a,G,G,296,G,0,0
4,751168360,0,2014-04-01T09:56:13.491,a,G,G,296,G,1,1
5,751168360,0,2014-04-01T09:56:13.491,a,G,G,296,G,0,0
6,751168360,0,2014-04-01T09:56:13.491,a,G,G,296,G,0,0
7,751168360,0,2014-04-01T09:56:13.491,a,A,A,279,P,2.55,255
8,751168360,0,2014-04-01T09:56:13.491,a,A,A,279,P,0,0
然后,COPY
命令工作正常:
aploetz@cqlsh:Whosebug> COPY events1 (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11) FROM '/home/aploetz/cassandra_stack/b.csv' WITH header=true;
8 rows imported in 0.627 seconds.
aploetz@cqlsh:Whosebug> SELECT * FROM events1 ;
f2 | f1 | f10 | f11 | f3 | f4 | f5 | f6 | f7 | f8 | f9
-----------+----+------+-----+----+--------------------------+----+----+----+-----+----
751168360 | 1 | 242 | 242 | 0 | 2014-04-01 09:56:13-0500 | a | G | G | 296 | G
751168360 | 2 | 8 | 8 | 0 | 2014-04-01 09:56:13-0500 | a | G | G | 296 | G
751168360 | 3 | 0 | 0 | 0 | 2014-04-01 09:56:13-0500 | a | G | G | 296 | G
751168360 | 4 | 1 | 1 | 0 | 2014-04-01 09:56:13-0500 | a | G | G | 296 | G
751168360 | 5 | 0 | 0 | 0 | 2014-04-01 09:56:13-0500 | a | G | G | 296 | G
751168360 | 6 | 0 | 0 | 0 | 2014-04-01 09:56:13-0500 | a | G | G | 296 | G
751168360 | 7 | 2.55 | 255 | 0 | 2014-04-01 09:56:13-0500 | a | A | A | 279 | P
751168360 | 8 | 0 | 0 | 0 | 2014-04-01 09:56:13-0500 | a | A | A | 279 | P
(8 rows)
删除你的单引号,然后它应该工作。
我发布了一个额外的答案,因为最初的问题是导入此数据(驻留在压缩的 csv.gz 文件中):
f1;f2;f3;f4;f5;f6;f7;f8;f9;f10;f11
1;751168360;0;'2014-04-01T09:56:13.491111';'a';'G';'G';296;'G';242;242
2;751168360;0;'2014-04-01T09:56:13.491111';'a';'G';'G';296;'G';8;8
3;751168360;0;'2014-04-01T09:56:13.491111';'a';'G';'G';296;'G';0;0
4;751168360;0;'2014-04-01T09:56:13.491111';'a';'G';'G';296;'G';1;1
5;751168360;0;'2014-04-01T09:56:13.491111';'a';'G';'G';296;'G';0;0
6;751168360;0;'2014-04-01T09:56:13.491111';'a';'G';'G';296;'G';0;0
7;751168360;0;'2014-04-01T09:56:13.491111';'a';'A';'A';279;'P';2.55;255
8;751168360;0;'2014-04-01T09:56:13.491111';'a';'A';'A';279;'P';0;0
仔细选择参数 (DELIMITER, QUOTE, HEADER
) 可以无误地导入数据:
zcat /tmp/a.csv.gz | cqlsh -e "copy flotilla.events1 (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11) from STDIN WITH DELIMITER=';' and QUOTE='''' and header=true;"
但是我仍然认为微秒 (.491111
) 会导致错误,因为 cassandra 只能处理毫秒
在 cassandra ([cqlsh 5.0.1 | Cassandra 2.2.0 | CQL spec 3.3.0 | Native protocol v4]
) 中我创建了以下 table
create table flotilla.events1 (
f1 int,
f2 int,
f3 int,
f4 timestamp,
f5 text,
f6 text,
f7 text,
f8 int,
f9 text,
f10 double,
f11 int,
primary key (f2, f1)
);
并尝试插入以下数据 (/tmp/b.csv
):
f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11
1,751168360,0,'2014-04-01T09:56:13.491','a','G','G',296,'G',242,242
2,751168360,0,'2014-04-01T09:56:13.491','a','G','G',296,'G',8,8
3,751168360,0,'2014-04-01T09:56:13.491','a','G','G',296,'G',0,0
4,751168360,0,'2014-04-01T09:56:13.491','a','G','G',296,'G',1,1
5,751168360,0,'2014-04-01T09:56:13.491','a','G','G',296,'G',0,0
6,751168360,0,'2014-04-01T09:56:13.491','a','G','G',296,'G',0,0
7,751168360,0,'2014-04-01T09:56:13.491','a','A','A',279,'P',2.55,255
8,751168360,0,'2014-04-01T09:56:13.491','a','A','A',279,'P',0,0
使用以下命令:
copy flotilla.events1 (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11) from '/tmp/b.csv' with header=true;
卡桑德拉说:
8 rows imported in 0.550 seconds.
当我检查 table:
SELECT * from flotilla.events1 ;
f2 | f1 | f10 | f11 | f3 | f4 | f5 | f6 | f7 | f8 | f9
----+----+-----+-----+----+----+----+----+----+----+----
(0 rows)
没有一个错误。多么骇人听闻?
但是如果我插入第一行 INSERT INTO
:
insert into flotilla.events1 (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11) values (1,751168360,0,'2014-04-01T09:56:13.123','a','G','G',296,'G',242,242) ; select * from flotilla.events1;
f2 | f1 | f10 | f11 | f3 | f4 | f5 | f6 | f7 | f8 | f9
-----------+----+-----+-----+----+--------------------------+----+----+----+-----+----
751168360 | 1 | 242 | 242 | 0 | 2014-04-01 09:56:13+0200 | a | G | G | 296 | G
(1 rows)
多么骇人听闻?
与我一小时前回答此问题的方式类似
f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f11
1,751168360,0,2014-04-01T09:56:13.491,a,G,G,296,G,242,242
2,751168360,0,2014-04-01T09:56:13.491,a,G,G,296,G,8,8
3,751168360,0,2014-04-01T09:56:13.491,a,G,G,296,G,0,0
4,751168360,0,2014-04-01T09:56:13.491,a,G,G,296,G,1,1
5,751168360,0,2014-04-01T09:56:13.491,a,G,G,296,G,0,0
6,751168360,0,2014-04-01T09:56:13.491,a,G,G,296,G,0,0
7,751168360,0,2014-04-01T09:56:13.491,a,A,A,279,P,2.55,255
8,751168360,0,2014-04-01T09:56:13.491,a,A,A,279,P,0,0
然后,COPY
命令工作正常:
aploetz@cqlsh:Whosebug> COPY events1 (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11) FROM '/home/aploetz/cassandra_stack/b.csv' WITH header=true;
8 rows imported in 0.627 seconds.
aploetz@cqlsh:Whosebug> SELECT * FROM events1 ;
f2 | f1 | f10 | f11 | f3 | f4 | f5 | f6 | f7 | f8 | f9
-----------+----+------+-----+----+--------------------------+----+----+----+-----+----
751168360 | 1 | 242 | 242 | 0 | 2014-04-01 09:56:13-0500 | a | G | G | 296 | G
751168360 | 2 | 8 | 8 | 0 | 2014-04-01 09:56:13-0500 | a | G | G | 296 | G
751168360 | 3 | 0 | 0 | 0 | 2014-04-01 09:56:13-0500 | a | G | G | 296 | G
751168360 | 4 | 1 | 1 | 0 | 2014-04-01 09:56:13-0500 | a | G | G | 296 | G
751168360 | 5 | 0 | 0 | 0 | 2014-04-01 09:56:13-0500 | a | G | G | 296 | G
751168360 | 6 | 0 | 0 | 0 | 2014-04-01 09:56:13-0500 | a | G | G | 296 | G
751168360 | 7 | 2.55 | 255 | 0 | 2014-04-01 09:56:13-0500 | a | A | A | 279 | P
751168360 | 8 | 0 | 0 | 0 | 2014-04-01 09:56:13-0500 | a | A | A | 279 | P
(8 rows)
删除你的单引号,然后它应该工作。
我发布了一个额外的答案,因为最初的问题是导入此数据(驻留在压缩的 csv.gz 文件中):
f1;f2;f3;f4;f5;f6;f7;f8;f9;f10;f11
1;751168360;0;'2014-04-01T09:56:13.491111';'a';'G';'G';296;'G';242;242
2;751168360;0;'2014-04-01T09:56:13.491111';'a';'G';'G';296;'G';8;8
3;751168360;0;'2014-04-01T09:56:13.491111';'a';'G';'G';296;'G';0;0
4;751168360;0;'2014-04-01T09:56:13.491111';'a';'G';'G';296;'G';1;1
5;751168360;0;'2014-04-01T09:56:13.491111';'a';'G';'G';296;'G';0;0
6;751168360;0;'2014-04-01T09:56:13.491111';'a';'G';'G';296;'G';0;0
7;751168360;0;'2014-04-01T09:56:13.491111';'a';'A';'A';279;'P';2.55;255
8;751168360;0;'2014-04-01T09:56:13.491111';'a';'A';'A';279;'P';0;0
仔细选择参数 (DELIMITER, QUOTE, HEADER
) 可以无误地导入数据:
zcat /tmp/a.csv.gz | cqlsh -e "copy flotilla.events1 (f1, f2, f3, f4, f5, f6, f7, f8, f9, f10, f11) from STDIN WITH DELIMITER=';' and QUOTE='''' and header=true;"
但是我仍然认为微秒 (.491111
) 会导致错误,因为 cassandra 只能处理毫秒