I know using IN
clause in Partition key is however I would like to write an UDF
that from 2 dates returns an array/list of values that can be used for the IN
clause.
Basically what I want to achieve is the following :
CREATE OR REPLACE FUNCTION date_range(start date, end date) called on null input returns set<date> language JAVA as
$$
// function implementation here that returns a list of dates between the 2 provided dates
$$
I would then run a CQL query like
SELECT * from my_table where t_id=3 AND t_date IN (date_range('2010-01-01', '2019-01-10');
Where the table structure would be
CREATE TABLE test ( t_id number, t_date date, t_value number) primary key ((t_number, t_date));
Any way I can achieve this?
You can't do this in Cassandra - UDFs are mostly applied to an individual columns. There is a JIRA for supporting UDFs in WHERE, but it's still open: https://issues.apache.org/jira/browse/CASSANDRA-8488
I would suggest to generate this list in application, and use it with the prepared queries - it could be more effective from performance point of view.