如何模拟cassandra columnfamily

时间:2014-09-29 09:30:26

标签: cassandra cql cql3 cqlsh

我已经定义的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列&#34;时间&#34;不能被限制(前一列&#34; record_link_id&#34;不受限制或非均衡关系)

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

错误请求:PRIMARY KEY列&#34; record_link_id&#34;不能被限制(前一栏&#34;操作&#34;不受限制或非EQ关系)

1 个答案:

答案 0 :(得分: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