如何在cassandra中进行查询如果我在列族中有两个簇密钥

Bir*_*mar 4 cql cassandra pycassa cassandra-2.0

我有一个列族和语法如下:

CREATE TABLE sr_number_callrecord ( 
  id int, 
  callerph text, 
  sr_number text, 
  callid text, 
  start_time text, 
  plan_id int, 
  PRIMARY KEY((sr_number), start_time, callerph) 
);
Run Code Online (Sandbox Code Playgroud)

我想做的查询如下:

  a) select * from dummy where sr_number='+919xxxx8383' 
                   and start_time >='2014-12-02 08:23:18' limit 10;

  b)  select * from dummy where sr_number='+919xxxxxx83' 
                          and start_time >='2014-12-02 08:23:18' 
                          and callerph='+9120xxxxxxxx0' limit 10;
Run Code Online (Sandbox Code Playgroud)

第一个查询工作正常,但第二个查询给出错误

Bad Request: PRIMARY KEY column "callerph" cannot be restricted 
(preceding column "start_time" is either not restricted or by a non-EQ 
relation)  
Run Code Online (Sandbox Code Playgroud)

如果我在第一个查询中得到结果,在第二个查询中,我只是添加一个
集群密钥以获取过滤结果,行将更少

Aar*_*ron 5

就像您不能跳过PRIMARY KEY组件一样,您只能在查询的最后一个组件上使用非等于运算符(这就是您的第一个查询有效的原因).

如果您确实需要提供上面列出的两个查询,那么您需要为每个查询提供单独的查询表.要为第二个查询提供服务,如果使用PRIMARY KEY定义查询表(具有相同的列)将起作用:

PRIMARY KEY((sr_number), callerph, start_time)
Run Code Online (Sandbox Code Playgroud)

这样你仍然按顺序指定PRIMARY KEY的部分,而你的非等于条件是在最后一个PRIMARY KEY组件上.