InvalidRequest: code=2200 [无效查询] message="Invalid operator >= for PRIMARY KEY part "

InvalidRequest: code=2200 [Invalid query] message="Invalid operator >= for PRIMARY KEY part "

我在 cassandra 中有以下数据集:

Table结构

CREATE TABLE userlog (
 term text,
 ts timestamp,
 year int,
 month int,
 day int,
 hour int,
 weekofyear int,
 dayofyear int,
 count counter,
 PRIMARY KEY (term, ts, year,month,day,hour,weekofyear,dayofyear)
);

.

term             | ts                       | year | month | day | hour | weekofyear | dayofyear | count
------------------+--------------------------+------+-------+-----+------+------------+-----------+-------
www.datastax.com | 2028-07-13 17:06:28+0530 | 2015 |     7 |  28 |   16 |         31 |       209 |     2
www.datastax.com | 2015-07-28 16:17:36+0530 | 2015 |     7 |  28 |   16 |         31 |       209 |     6
www.datastax.com | 2015-07-28 16:17:36+0530 | 2015 |     7 |  28 |   16 |         31 |       209 |     2
www.datastax.com | 2015-07-28 16:17:36+0530 | 2015 |     7 |  28 |   16 |         31 |       209 |     2
www.datastax.com | 2015-07-28 16:21:15+0530 | 2015 |     7 |  28 |   16 |         31 |       209 |     2
www.datastax.com | 2015-07-28 16:21:33+0530 | 2015 |     7 |  28 |   16 |         31 |       209 |     2
www.datastax.com | 2015-07-28 16:21:50+0530 | 2015 |     7 |  28 |   16 |         31 |       209 |     2
www.datastax.com | 2015-07-28 16:21:52+0530 | 2015 |     7 |  28 |   16 |         31 |       209 |     2
www.datastax.com | 2015-07-28 16:21:53+0530 | 2015 |     7 |  28 |   16 |         31 |       209 |     2
             www | 2015-07-28 16:46:00+0530 | 2015 |     7 |  28 |   16 |         31 |       209 |     2
            www. | 2015-07-28 16:47:00+0530 | 2015 |     7 |  28 |   16 |         31 |       209 |     2
            www. | 2015-07-28 16:48:00+0530 | 2015 |     7 |  28 |   16 |         31 |       209 |     2
            www. | 2015-07-28 16:50:00+0530 | 2015 |     7 |  28 |   16 |         31 |       209 |     2
            www. | 2015-07-28 16:55:00+0530 | 2015 |     7 |  28 |   16 |         31 |       209 |     2

当我 运行 这个查询时 :

SELECT * FROM userlog  WHERE ts >= '2015-07-28 16:46' AND  ts <= '2015-07-28 16:55' ALLOW FILTERING;

我得到正确的结果:

term | ts                       | year | month | day | hour | weekofyear | dayofyear | count
------+--------------------------+------+-------+-----+------+------------+-----------+-------
www  | 2015-07-28 16:46:00+0530 | 2015 |     7 |  28 |   16 |         31 |       209 |     2
www. | 2015-07-28 16:47:00+0530 | 2015 |     7 |  28 |   16 |         31 |       209 |     2
www. | 2015-07-28 16:48:00+0530 | 2015 |     7 |  28 |   16 |         31 |       209 |     2
www. | 2015-07-28 16:50:00+0530 | 2015 |     7 |  28 |   16 |         31 |       209 |     2
www. | 2015-07-28 16:55:00+0530 | 2015 |     7 |  28 |   16 |         31 |       209 |     2

但是当我尝试删除具有相同条件的行时

DELETE FROM userlog WHERE ts >= '2015-07-28 16:46' AND  ts <= '2015-07-28 16:55';

它抛出以下错误:

InvalidRequest: code=2200 [Invalid query] message="Invalid operator >= for PRIMARY KEY part ts"

我错过了什么吗?如何删除指定时间范围内的数据?还有,有什么方法可以获取指定时间范围内的数据(除了我做的?)

DELETE 命令不支持范围查询或 ALLOW FILTERING 子句。从文档中它只支持 = 和 IN 运算符:

您可以通过完全指定分区列和集群列来删除单个行。

您只需指定分区键即可删除整个分区。

并且您可以使用 IN 运算符同时执行其中的一些操作。

如果您想从分区中有选择地删除行,您可以先使用 SELECT 查询它们,然后在您的应用程序中为从 SELECT 返回的每一行发出删除。

通常您不想在 SELECT 语句上使用 ALLOW FILTERING,因为这非常低效,因此通常您会在执行范围查询 SELECT 时指定分区键。您将构建您的架构,以便操作所需的信息位于已知分区中,这样您就不需要进行完整的 table 扫描来查找内容。