【问题标题】:How to import column value in Cassandra like one having such values "13/01/09 23:13"?如何在 Cassandra 中导入列值,例如具有“13/01/09 23:13”这样的值?
【发布时间】:2017-02-01 17:32:03
【问题描述】:

查询:

CREATE TABLE IF NOT EXISTS "TEMP_tmp".temp (
"Date_Time" timestamp,
PRIMARY KEY ("Date_Time")
);

CSV 包含“13/01/09 23:13”值。

Error : Failed to import 1 rows: ParseError - Failed to parse 13/01/09 23:13 : invalid literal for long() with base 10: '13/01/09 23:13',  given up without retries.

我应该使用什么数据类型?

【问题讨论】:

    标签: database cassandra cloud distributed


    【解决方案1】:

    默认Cqlsh时间戳格式为:年-月-日时:分:秒+时区
    示例:

    2017-02-01 05:28:36+0000
    

    您可以将日期格式更改为上述格式,也可以从 cqlshrc 文件中更改格式
    检查这个答案custom cassandra / cqlsh time_format

    【讨论】:

    • 我在 Excel 工作表中已经有了“yyyy-mm-dd hh:mm:ss”的数据。我收到的错误是 无法解析 2009-08-11 15:53:00:无法将“2009-08-11 15:53:00”解释为格式为 %Y-%m-% 的日期d %H:%M:%S.%f%z
    • 我正在使用“cqlsh 5.0.1 | Cassandra 2.2.4 | CQL 规范 3.3.1 | 本机协议 v4”,我可以从 cqlsh 加载“2009-08-11 15:53:00”使用复制命令没有任何错误
    【解决方案2】:

    cassandra 会将timestamp 存储为2017-02-01 08:28:21+0000。例如,如果我在您描述的表中存储timestamp "TEMP_tmp".temp

    cassandra@cqlsh> INSERT INTO  TEMP_tmp.temp ("Date_Time") VALUES ( toTimestamp(now()));
    cassandra@cqlsh> SELECT * FROM TEMP_tmp.temp;
    
    Date_Time
    --------------------------
    2017-02-01 09:14:29+0000
    

    如果我们将所有数据复制到csv

    cassandra@cqlsh> COPY Temp_tmp.temp TO 'temp.csv';
    

    temp.csv 将包含:

    2017-02-01 09:14:29+0000
    

    如果我们truncate表:

    cassandra@cqlsh> TRUNCATE TABLE TEMP_tmp.temp;
    cassandra@cqlsh> SELECT * FROM TEMP_tmp.temp;
    
    Date_Time
    --------------------------
    

    那么如果我们导入temp.csv:

    cassandra@cqlsh> COPY Temp_tmp.temp FROM 'temp.csv';
    Using 1 child processes
    
    Starting copy of Temp_tmp.temp with columns [Date_Time].
    Processed: 1 rows; Rate:       1 rows/s; Avg. rate:       1 rows/s
    1 rows imported from 1 files in 0.746 seconds (0 skipped).
    

    如果您想要自定义日期/时间格式,请在您的问题中关注Ashraful Islam's answer

    【讨论】:

      猜你喜欢
      • 2018-02-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-23
      • 1970-01-01
      • 2023-01-27
      • 2018-02-23
      • 1970-01-01
      相关资源
      最近更新 更多