gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 03:47:46 25 4
gpt4 key购买 nike

运行查询时。

"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)

关于python - 使用 Python 和 CQL 时如何从 Cassandra 返回时间戳?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22843478/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com