【问题标题】:Cassandra COPY FROM Time and Timestamp columnsCassandra COPY FROM 时间和时间戳列
【发布时间】:2017-04-02 23:04:03
【问题描述】:

我正在尝试从 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).

我的 Timestamp coulmn 的格式是 YYYY/MM/DD ,直到我给出这个 DATETIMEFORMAT='%Y/%m/%d' 我会在时间戳列上得到错误,但在此之后那个错误停了下来。

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

我该如何解决这个问题。

非常感谢

【问题讨论】:

  • 向我们展示您的架构和 csv 中的某些行
  • 这就是全部内容
  • 你使用的是哪个 cassandra cql 版本?
  • 它适用于 [cqlsh 5.0.1 |卡桑德拉 2.2.4 | CQL 规范 3.3.1 |原生协议 v4]
  • **5.01 和 2.2.8**Connected to Test Cluster at 127.0.0.1:9042. [cqlsh 5.0.1 | Cassandra 2.2.8 | CQL spec 3.3.1 | Native protocol v4]

标签: time cassandra copy timestamp cqlsh


【解决方案1】:

我已经用 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)

【讨论】:

  • 谢谢你,我试过这个但不知何故现在已经陷入了 Python 缩进的混乱中。无论我做什么,我都会不断收到'缩进错误,甚至无法恢复。使用记事本++,我认为它缩进正确,但无法调出 cqlsh 文件“C:\Cassandra228\apache-cassandra\bin\..\pylib\cqlshlib\copyutil.py”,行 1901 返回时间(v)^ IndentationError:预期一个缩进的块。我不知道如何解决这个问题 - 尝试评论,eclipse/Pylib 也没有帮助。你能分享一份文件的副本吗,否则我只需要重新安装 Cassandra - 完全卡住了
  • 我以某种方式修复了编译错误(哇!)notepad++ 显示特殊字符
猜你喜欢
  • 2014-04-22
  • 2020-04-12
  • 2017-04-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-02
  • 2016-07-11
  • 2018-10-06
相关资源
最近更新 更多