我想你是誤解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我讀過你的博客。有沒有其他辦法可以解決我的問題? –