【发布时间】:2023-03-15 18:10:01
【问题描述】:
我在 cassandra 中有以下数据集:
表结构
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"
我错过了什么吗?如何删除指定时间范围内的数据?另外,有什么方法可以获取指定时间范围内的数据(除了我在做什么?)
【问题讨论】: