[cqlsh 5.0.1 | Cassandra 2.1.0 | CQL 规范 3.2.0 |原生协议(protocol)v3]
table:
CREATE TABLE dc.event (
id timeuuid PRIMARY KEY,
name text
) WITH bloom_filter_fp_chance = 0.01;
如何从 Cassandra 获取时间范围内的数据?
例如,当我尝试 'select * from event where id> maxTimeuuid('2014-11-01 00:05+0000') 和 minTimeuuid('2014-11-02 10:00+0000' )'
,如此处所示 http://www.datastax.com/documentation/cql/3.0/cql/cql_reference/timeuuid_functions_r.html
我收到以下错误:'code=2200 [无效查询] message="分区键仅支持 EQ 和 IN 关系(除非您使用 token() 函数)"'
我可以保留timeuuid
作为主键并满足要求吗?
谢谢
最佳答案
Can I keep timeuuid as primary key and meet the requirement?
不完全是,不。来自 http://www.datastax.com/documentation/cql/3.1/cql/cql_reference/select_r.html
WHERE clauses can include a greater-than and less-than comparisons, but for a given partition key, the conditions on the clustering column are restricted to the filters that allow Cassandra to select a contiguous ordering of rows.
您可以尝试在查询中添加“允许过滤”...但我怀疑这是否有效。我不知道有什么好方法(我也不相信有什么好方法)来标记 timeuuid。我大约 99% 确信分区程序的排序会产生意外的不良结果,即使查询本身会执行并且在您深入研究之前显示为正确的。
顺便说一句,您确实应该检查一下大约一年前提出的类似问题:time series data, selecting range with maxTimeuuid/minTimeuuid in cassandra
关于cassandra - 如何从 Cassandra 获取一系列数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26985669/