Skip to main content
 首页 » 编程设计

python之使用 Python 和 CQL 时如何从 Cassandra 返回时间戳

2024年11月01日8langtianya

运行查询时。

"select * from temperature_by_day" 

Cassandra 正在为时间戳返回字符串 '\x00\x00\x017\xa7\xea\x9e\x00'。

如果我从服务器上的 cqlsh 查询,它会返回我设置的日期。

我读过这篇文章:How to retrieve the timestamp from cassandra?

它声明“不建议直接在客户端代码中使用列 Cassandra 时间戳;”。

为什么?

这里的教程说直接查询时间戳。

http://planetcassandra.org/blog/post/getting-started-with-time-series-data-modeling/

那么添加一个不属于主键的额外时间戳并针对该时间戳进行查询是否是正确的做法?

提前致谢。

请您参考如下方法:

Datastax Python driver支持时间戳类型。如果您想了解如何反序列化它,请查看 DataType.deserialize方法:

return datetime.utcfromtimestamp(int64_unpack(byts) / 1000.0)