我想你是误解cassandra集群的关键顺序。 Cassandra使用单个分区内的集群密钥对数据进行排序。
这是为你的情况cassandra排序数据与集群关键时间在一个单一的名称和日期。
例子:让我们插入一些数据
INSERT INTO test (name , date , time , entry) VALUES ('anand', '2017-04-01', 1, 'a');
INSERT INTO test (name , date , time , entry) VALUES ('anand', '2017-04-01', 2, 'b');
INSERT INTO test (name , date , time , entry) VALUES ('anand', '2017-04-01', 3, 'c');
INSERT INTO test (name , date , time , entry) VALUES ('anand', '2017-04-02', 0, 'nil');
INSERT INTO test (name , date , time , entry) VALUES ('anand', '2017-04-02', 4, 'd');
如果我们选择与您的查询数据:
SELECT * FROM test where name ='anand' and date in ('2017-04-01','2017-04-02','2017-04-03','2017-04-05') ;
输出:
name | date | time | details | entry
-------+------------+------+---------+-------
anand | 2017-04-01 | 3 | null | c
anand | 2017-04-01 | 2 | null | b
anand | 2017-04-01 | 1 | null | a
anand | 2017-04-02 | 4 | null | d
anand | 2017-04-02 | 0 | null | nil
你可以看到时间3,2,1
不到单个分区anand:2017-04-01
按照desc和时间排序4,0
在单个分区内anand:2017-04-02
是按照desc。卡桑德拉不会照顾不同分区之间的分类。
这里是DOC:
在该表中定义,聚类列是列,它是所述化合物的主键定义的一部分,而不是第一列,它是为分区保留的位置键。列在单个分区内聚集成多行。聚类顺序由复合主键定义中列的位置确定。
来源:http://docs.datastax.com/en/cql/3.1/cql/ddl/ddl_compound_keys_c.html
通过,为什么你的数据字段是text
类型和time
场double
类型的方法是什么?
您可以使用date
字段作为date
类型和time
作为timestamp
类型。
显示例子,而您没有得到排序结果 –
不要自我宣传或任何东西,但我在2015年写了一篇关于此主题的文章,可能有所帮助:http://www.datastax。com/dev/blog/we-shall-order – Aaron
@Aaron我读过你的博客。有没有其他办法可以解决我的问题? –