Cassandra从时间和时间戳列复制

时间:2016-11-19 01:15:21

标签: time cassandra copy timestamp cqlsh

我正在尝试从csv文件复制,我有1个时间戳和一个时间列。 尝试用几行开始测试:

 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).

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

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

我该如何解决这个问题。

非常感谢

1 个答案:

答案 0 :(得分: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)