以下内容按预期工作。但是我该由谁来执行范围查询,例如“whereage > 40 andage < 50”
create keyspace Keyspace1;
use Keyspace1;
create column family Users with comparator=UTF8Type and default_validation_class=UTF8Type and key_validation_class=UTF8Type;
set Users[jsmith][first] = 'John';
set Users[jsmith][last] = 'Smith';
set Users[jsmith][age] = long(42);
get Users[jsmith];
=> (column=age, value=42, timestamp=1341375850335000)
=> (column=first, value=John, timestamp=1341375827657000)
=> (column=last, value=Smith, timestamp=1341375838375000)
最佳答案
在 Cassandra 中执行此操作的最佳方法根据您的要求而有所不同,但支持这些类型的范围查询的方法非常相似。
基本上,您将利用行中的列按名称排序的事实。因此,如果您使用年龄作为列名(或列名的一部分),则该行将按年龄排序。
您会发现这与存储时间序列数据之间有很多相似之处。我建议你看看Basic Time Series with Cassandra基础知识,以及 latest CQL features 介绍的后半部分这给出了一个更强大的方法的例子。
内置二级索引的设计基本上类似于哈希表,并且不适用于范围查询,除非该范围表达式在索引列上附带等式表达式。因此,您可以要求 select * from users where name = 'Joe' and Age > 54
,但不能简单地要求 select * from users where age > 54
,因为这样会需要全表扫描。请参阅二级索引 doc了解更多详情。
关于cassandra - cassandra 中的范围查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11322477/