2016-11-19 34 views
0

我想复制从csv文件,我有1时间戳和时间列。 试图与一对夫妇行的测试开始与:Cassandra复制从时间和时间戳列

cqlsh:tests> CREATE TABLE testts (
     ...     ID int PRIMARY KEY, 
     ...     mdate timestamp, 
     ...     ttime time); 
cqlsh:tests> INSERT INTO testts (ID , mdate, ttime) 
     ... VALUES (1, '2015-10-12', '1055') ; 
cqlsh:tests> INSERT INTO testts (ID , mdate, ttime) 
     ... VALUES (2, '2014-06-25', '920') ; 
cqlsh:tests> select * from testts; 

id | mdate     | ttime 
----+--------------------------+-------------------- 
    1 | 2015-10-12 07:00:00+0000 | 00:00:00.000001055 
    2 | 2014-06-25 07:00:00+0000 | 00:00:00.000000920 

(2 rows) 

以上的作品,现在我尝试导入文件

cqlsh:tests> COPY testts (ID, 
     ...   mdate, 
     ...   ttime) 
     ... FROM 'c:\cassandra228\testtime.csv' WITH HEADER = FALSE AND DELIMITER = ',' AND DATETIMEFORMAT='%Y/%m/%d'; 
Using 3 child processes 

Starting copy of tests.testts with columns [id, mdate, ttime]. 
Failed to import 1 rows: ParseError - Failed to parse 1130 : can't interpret '1130' as a time, given up without retries 
Failed to import 1 rows: ParseError - Failed to parse 1230 : can't interpret '1230' as a time, given up without retries 
Failed to import 1 rows: ParseError - Failed to parse 930 : can't interpret '930' as a time, given up without retries 
Failed to process 3 rows; failed rows written to import_tests_testts.err 
Processed: 3 rows; Rate:  0 rows/s; Avg. rate:  1 rows/s 
3 rows imported from 1 files in 3.269 seconds (0 skipped). 

我的时间戳coulmn的格式YYYY/MM/DD,直到我给了这个DATETIMEFORMAT ='%Y /%m /%d'我会在时间戳列上发生错误,但在此之后,错误停止。

CSV文件:3,2010年 /02/08930 4,2015/05/20,1130 5,2016/08/15,1230

我该如何解决这个问题。

感谢很多

+0

告诉我们您的架构,并从CSV –

+0

这里是一些行是整个事情 –

+0

这Cassandra的CQL版本您使用的? –

回答

0

我有相同的架构和数据cassandra-2.2.4的cqlsh 所有值检查该插入没有任何错误。

但与cassandra-2.2.8的cqlsh,它给我与你的相同的错误。 你可以修改cqlsh代码中的小改动。

1。打开copyutil.py文件。在我的情况下,它是/opt/apache-cassandra-2.2.8/pylib/cqlshlib/copyutil.py
2。找对方法convert_time(),并把它改成这个

def convert_time(v, **_): 
    try: 
     return Time(int(v)) 
    except ValueError, e: 
     pass 
    return Time(v) 
+0

感谢你们,**我试图尝试这个**,但现在已经进入Python缩进混乱。无论我做什么,我都会收到'缩进错误,甚至无法恢复。使用记事本++我认为它是正确缩进,但不能调出cqlsh文件“C:\ Cassandra228 \ apache-cassandra \ bin \ .. \ pylib \ cqlshlib \ copyutil.py”,lin e 1901 return Time(v) ^ IndentationError:预计有一个缩进块。我不知道如何解决这个问题 - 尝试评论,也日食/ Pylib没有帮助。你可以分享一份文件,否则我只需要重新安装卡桑德拉 - 完全卡住 –

+1

我修正了编译错误(呜!)记事本++ **显示特殊字符** –

+0

这是我的copyutil文件https://驱动器.google.com /开?ID = 0B3G1hA-Owg0SNThLTW11UGRfZlU –