cassandra - 如何将 CQL 时间戳配置为 %d-%m-%Y %H :%M:%S%z

标签 cassandra timestamp cql

我在 Windows 10 Pro 上使用 Cassandra。我创建了以下表架构:

CREATE TABLE testee (
               serialno int,
               changeDate timestamp,
               value text,
               devicename text,
               PRIMARY KEY ((serialno, changeDate), changeDate)
) WITH CLUSTERING ORDER BY (changeID DESC);

给定的日期格式(时间戳)为: %d-%m-%-Y%H:%M:%S%z

Cassandra 默认时间戳是: %Y-%m-%-d%H:%M:%S%z

对于日期格式的转换,我遵循了Datastax的说明:

https://docs.datastax.com/en/cql/3.3/cql/cql_reference/cqlshUsingCqlshrc.html

现在 cqlshrc 文件位于:

C:\Users\tlq\ .cassandra\cqlshrc

根据这个已解决的问题Cassandra Timestamp data type , 'time_format' 必须插入 cqlshrc 文件的 [ui] 部分。我这样做了:

[ui]

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

;;Used for used displaying timestamps generell

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

通过使用插入命令:

INSERT INTO foo(serialno, changedate, devicename) VALUES(2,'07-12-2011 13:56:20','fooname',34);

仍然出现以下消息

InvalidRequest: Error from server: code=2200 [Invalid query] message="Unable to >coerce '07-12-2014 13:56:20' to a formatted date (long)"

最佳答案

您在cqlshrc 文件中指定的选项用于显示数据,而不是用于输入字符串。 Cassandra 接受以下格式的数据,如 documentation 中所述。 :

yyyy-mm-dd[(T| )HH:MM:SS[.fff]][(+|-)NNNN]

因此您需要以正确的顺序指定日期:年-月-日...

附注当您不指定时区时,它会从客户端的配置中获取 - 您需要通过将 timezone 参数添加到 cqlshrc 文件中来指定默认时区(相同 [ ui] 部分),如下所示:

timezone = Etc/UTC

另请参阅documentation其中讨论了安装可选包,例如 pytz

关于cassandra - 如何将 CQL 时间戳配置为 %d-%m-%Y %H :%M:%S%z,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51628202/

相关文章:

cassandra - 将新节点添加到现有节点 cassandra 集群

java - 如何在 Spark 中创建必须应用于数据集的函数管道?

django - 在 centos 上使用 cassandra

c++ - 使用 CQL 准备的查询在 C++ 中管理计数器

java - Cassandra-2.1.2 中的范围扫描花费大量时间

php - UUID Cassandra 排序?

nosql - 跟踪用户关系的最佳数据库是什么?

php - 发布当前评论时间

java - 将十六进制值转换为时间戳/日期和时间

不同时区的 PostgreSQL 转储和恢复