Caasandra PRIMARY KEY列“ user”不能受到限制,因为前列“ eventtype”不受限制

时间:2018-10-23 10:37:24

标签: cassandra

我开发的表格在下面

create table userevent(id uuid,eventtype text,sourceip text,user text,sessionid text,roleid int,menu text,action text,log text,date timestamp,PRIMARY KEY (id,eventtype,user));

 id                                   | eventtype | user    | action | date                     | log      | menu      | roleid | sessionid | sourceip
--------------------------------------+-----------+---------+--------+--------------------------+----------+-----------+--------+-----------+--------------
 b15c6780-d69e-11e8-bb9a-59dfa00365c6 |  DemoType |    Aqib |  Login | 2018-10-01 04:05:00+0000 |  demolog |  demomenu |      1 |    Demo_1 | 121.11.11.12
 95df3410-d69e-11e8-bb9a-59dfa00365c6 |  DemoType |    Aqib |  Login | 2018-09-30 22:35:00+0000 |  demolog |  demomenu |      1 |    Demo_1 | 121.11.11.12
 575b05c0-d69e-11e8-bb9a-59dfa00365c6 |  DemoType |    Aqib |  Login | 2018-10-01 04:05:00+0000 |  demolog |  demomenu |      1 |    Demo_1 | 121.11.11.12
 e6cbc190-d69e-11e8-bb9a-59dfa00365c6 | DemoType3 |   Jasim |  Login | 2018-05-31 22:35:00+0000 | demolog3 | demomenu3 |      3 |    Demo_3 | 121.11.11.12
 d66992a0-d69e-11e8-bb9a-59dfa00365c6 |  DemoType | Shafeer |  Login | 2018-07-31 22:35:00+0000 |  demolog |  demomenu |      2 |    Demo_2 | 121.11.11.12

但是当我如下查询时,

select * from userevent where user='Aqib'; 

它显示了这样的内容:InvalidRequest: Error from server: code=2200 [Invalid query] message="PRIMARY KEY column "user" cannot be restricted as preceding column "eventtype" is not restricted"

什么是错误...........

1 个答案:

答案 0 :(得分:0)

您需要阅读有关data modelling for Cassandra的知识,例如阅读DS220 course on the DataStax Academy。每行都有主键,主键由定义数据所在节点的分区键和定义分区内位置的聚类键组成。在您的情况下,您的主键至少包含id, eventtype, user。要为用户设置条件,您需要同时指定ideventtype

您可以添加索引或物化视图以仅通过user进行访问,但是我建议先对数据建模进行更多了解-定义查询,然后针对需要执行的查询构建表结构。