Cassandra时间戳数据类型

时间:2018-01-16 07:48:35

标签: ubuntu cassandra

这是我的数据库结构

CREATE TABLE stack (
    id UUID,
    entrytime TIMESTAMP,
    name TEXT,
    PRIMARY KEY (id, entrytime)
) WITH CLUSTERING ORDER BY ( entrytime DESC );

当我使用Insert语句时。

INSERT INTO stack ( id, entrytime, name )
VALUES ( now(), toTimestamp( now() ), 'Nik' );

但它将输入时间列存储为2018-01-15 08:29:58.174000+0000

我想删除Cassandra提供的额外精度。 我知道这必须对cqlshrc.sample文件做一些事情,但我无法做到。

有人可以帮助我吗?

这是我的cqlshrc文件的一部分

[ui]
;; Whether or not to display query results with colors
; color = on

;; Used for displaying timestamps (and reading them with COPY)
time_format = %Y-%m-%d %H:%M:%S

;; Display timezone
;timezone = Etc/UTC

现在,当我运行我的cql shell时,会发生以下错误。

  Traceback (most recent call last):
    File "/var/www/html/cassandra/apache-cassandra-
   3.11.1/bin/cqlsh.py", line 2434, in <module>
     main(*read_options(sys.argv[1:], os.environ))
   File "/var/www/html/cassandra/apache-cassandra-
   3.11.1/bin/cqlsh.py", line 2211, in read_options
     configs.read(CONFIG_FILE)
   File "/usr/lib/python2.7/ConfigParser.py", line 305, in read
     self._read(fp, filename)
   File "/usr/lib/python2.7/ConfigParser.py", line 512, in _read
      raise MissingSectionHeaderError(fpname, lineno, line)
   ConfigParser.MissingSectionHeaderError: File contains no section headers.
    file: /home/ubuntu/.cassandra/cqlshrc, line: 1

'\ XEF \ XBB \ XBF;在一个\ n'

下获得Apache Software Foundation(ASF)的许可

1 个答案:

答案 0 :(得分:2)

只需插入~/.cassandra/cqlshrc文件,然后插入以下[ui]部分(这是针对3.x):

time_format = %Y-%m-%d %H:%M:%S%z

您可以找到的%字段说明here

P.S。我修改了答案,因为datetimeformat仅用于COPY FROM选项,而不是cqlshrc ...