2014-09-29 65 views
0

下面的select查詢對於我定義的columnfamily是可能的,因爲我收到了錯誤的請求錯誤。我應該如何模擬我的柱狀家族以獲得正確的結果。如何建模cassandra columnfamily

CREATE TABLE recordhistory ( userid bigint, objectid bigint, operation text, record_link_id bigint, time timestamp, username text, value map<bigint, text>, PRIMARY KEY ((userid, objectid), operation, record_link_id, time) ) WITH CLUSTERING ORDER BY (operation ASC, record_link_id ASC, time DESC)

選擇查詢:

SELECT * FROM recordhistory WHERE userid=439035 AND objectid=20011009 AND operation='update' AND time>=1389205800000 AND time<=1402338600000 ALLOW FILTERING; 

錯誤的請求:PRIMARY KEY列 「時間」 不能被限制(列 「record_link_id」 前面是要麼沒有限制或由非EQ關係)

SELECT * FROM recordhistory WHERE userid=439035 AND objectid=20011009 AND record_link_id=20011063 ALLOW FILTERING; 

錯誤請求:PRIMARY KEY列「record_link_id」不能被限制(前一列「操作」不是受限制的或者是非EQ關係上)

+0

[「錯誤的請求:PRIMARY KEY部分\ _id不能被限制」當試圖選擇使用條件](http://stackoverflow.com/questions/22989708/bad-request -primary-key-part-to-id-can-be-restricted-when-trying-to-select) – fedorqui 2014-09-29 10:28:54

+0

其實在這裏我在查詢中使用分區鍵,並試圖通過跳過一些聚簇列來使用ALLOW FILTERING。 – Aftab 2014-09-29 11:04:30

回答

0
create table recordhistory (
userid bigint, 
objectid bigint, 
operation text, 
record_link_id bigint, 
time timestamp, 
username text, 
value map<bigint, text>, 
PRIMARY KEY ((userid, objectid), time, operation, record_link_id)) WITH CLUSTERING ORDER BY (time DESC, operation ASC, record_link_id ASC); 

select * from recordhistory where userid=12346 AND objectid=45646 and time >=1389205800000 and time <1402338700000 ALLOW FILTERING; 

userid | objectid | time      | operation | record_link_id | username | value 
--------+----------+--------------------------+-----------+----------------+----------+------- 
    12346 | 45646 | 2014-06-09 11:30:00-0700 |  myop4 |   78946 | name3 | null 
    12346 | 45646 | 2014-01-08 10:30:00-0800 | myop99999 |   999999 | name3 | null 
+0

謝謝你的回答,如果我在record_link_id上創建一個索引,並且我會像select *一樣從recordhistory查詢,其中userid = 12346和objectid = 45646和record_link_id = 78946;在這個查詢中,cassandra會觸及所有節點? – Aftab 2014-09-30 07:14:50

+0

是的,我認爲是。卡桑德拉不會讓你執行這樣一個潛在的昂貴查詢,可能會導致系統崩潰。要進行範圍查詢,數據必須在磁盤上連續排列。因此,如果您將Time設爲第一個羣集列,則可以按時間範圍進行查詢。 – catpaws 2014-09-30 13:54:23

相關問題