【问题标题】:Cassandra Timestamp data typeCassandra 时间戳数据类型
【发布时间】:2018-06-24 20:52:03
【问题描述】:

这是我的数据库结构

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;获得 Apache 软件基金会 (ASF) 的许可\n'

【问题讨论】:

    标签: ubuntu cassandra


    【解决方案1】:

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

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

    您可以找到here% 字段的描述。

    附:我修改了答案,因为datetimeformat 仅用于COPY FROM 的选项,而不是cqlshrc...

    【讨论】:

    • 我必须在我的 Cassandra 安装目录中创建一个 .cassandra 文件夹吗?
    • 不,~/ 表示您的主目录 - 有关详细信息,请参阅文档:docs.datastax.com/en/cql/3.3/cql/cql_reference/…
    • 我的 cqlshrc.sample 文件在 ~/ .cassandra/bin 中,所以如果我对该文件进行更改,然后将该文件粘贴到我安装 cassandra 的主目录中,它会起作用吗?
    • 您需要将conf/cqlshrc.sample复制为~/.cassandra/.cqlshrc。请注意,由于文档中的错误,我更改了答案-配置参数实际上称为time_format
    • 它对你有用是因为它不适合我吗?我的 cassandra 正在 AWS 服务器上运行,所以我认为我不需要再次重新启动它?
    猜你喜欢
    • 1970-01-01
    • 2017-04-12
    • 1970-01-01
    • 2012-02-17
    • 1970-01-01
    • 1970-01-01
    • 2015-12-30
    • 2012-08-19
    • 1970-01-01
    相关资源
    最近更新 更多