Here's another idea (somewhat unconventional). You can create a user-defined function to implement a second-range filter (in Cassandra 2.2 and later).
Suppose you define your table like this (shown using ints instead of timestamps, for a simple example):
CREATE TABLE tasks (
p int,
task_id timeuuid,
start int,
end int,
end_range int static,
PRIMARY KEY(p, start));
Now we create a user-defined function to check the returned rows based on the end time and return the task_id of the matching rows, for example:
CREATE FUNCTION my_end_range(task_id timeuuid, end int, end_range int)
CALLED ON NULL INPUT RETURNS timeuuid LANGUAGE java AS
'if (end <= end_range) return task_id; else return null;';
Now I use the trick with the third parameter. With explicit (large?) Supervision, it seems you cannot pass a constant to a specific function. Therefore, to get around this, we pass a static column (end_range) as our constant.
So, first we need to set the desired end_range:
UPDATE tasks SET end_range=15 where p=1;
, :
SELECT * FROM tasks;
p | start | end_range | end | task_id
---+-------+-----------+-----+--------------------------------------
1 | 1 | 15 | 5 | 2c6e9340-4a88-11e5-a180-433e07a8bafb
1 | 2 | 15 | 7 | 3233a040-4a88-11e5-a180-433e07a8bafb
1 | 4 | 15 | 22 | f98fd9b0-4a88-11e5-a180-433e07a8bafb
1 | 8 | 15 | 15 | 37ec7840-4a88-11e5-a180-433e07a8bafb
task_id, start >= 2 end <= 15:
SELECT start, end, my_end_range(task_id, end, end_range) FROM tasks
WHERE p=1 AND start >= 2;
start | end | test.my_end_range(task_id, end, end_range)
2 | 7 | 3233a040-4a88-11e5-a180-433e07a8bafb
4 | 22 | null
8 | 15 | 37ec7840-4a88-11e5-a180-433e07a8bafb
, task_id, ( UDF). , start >= 2 , UDF.
, , , .:)