2016-11-19 77 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 –