使用复合分区键在Cassandra中进行CQL查询

时间:2015-12-16 08:50:06

标签: cassandra cql cassandra-2.0 cql3

我的主要问题是在具有复合分区键的表上对Cassandra结果集进行分页。但是,我试图通过一个简单的场景缩小范围。说,我有一张桌子,

CREATE TABLE numberofrequests (
  cluster text,
  date text,
  time text,
  numberofrequests int,
PRIMARY KEY ((cluster, date), time)
) WITH CLUSTERING ORDER BY (time ASC)

我有一个像

这样的数据


cluster | date | time | numberofrequests ---------+------------+------+------------------ c2 | 01/04/2015 | t1 | 1 c2 | d1 | t1 | 1 c2 | 02/04/2015 | t1 | 1 c1 | d1 | t1 | 1 c1 | d1 | t2 | 2

问题:有什么办法可以查询cluster = c2的数据吗?我并不关心“约会”日期。老实说,我保留这个只是为了分区目的,以避免热点。我尝试了以下内容,


 select * from numberofrequests where token(cluster,date)>=token('c2','00/00/0000');

 select * from numberofrequests where token(cluster,date)>=token('c2','1');

 select * from numberofrequests where token(cluster,date)>=token('c2','a');

 select * from numberofrequests where token(cluster,date)>=token('c2','');

我的架构使用默认分区程序(Murmur3Partitioner)。这是否可以实现?

1 个答案:

答案 0 :(得分:1)

Cassandra需要分区键(PK)来查找查询的行。任何仅基于PK部分的查询都不起作用,因为它的murmur3哈希与基于最初由分区器创建的完整PK的哈希不匹配。你可以做的是使用ByteOrderedPartitioner。这将允许您通过保持PK的字节顺序而不是使用哈希函数来使用示例中的token()函数。但在大多数情况下,这是一个坏主意,因为数据不会在整个群集中均匀分布,您最终会得到您首先想要避免的热点。