首页 文章

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

提问于
浏览
1

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

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 回答

  • 1

    Cassandra需要分区键(PK)来定位查询的行 . 任何仅基于PK部分的查询都不起作用,因为它的murmur3哈希与基于最初由分区器创建的完整PK的哈希不匹配 . 你可以做的是使用 ByteOrderedPartitioner . 这将允许您通过保持PK的字节顺序而不是使用散列函数来使用示例中的 token() 函数 . 但在大多数情况下,最终会出现你试图避免的热点 .

相关问题