2

I have Following Data Model :-

 campaigns {
  id int PRIMARY KEY,
  scheduletime text,
  SchduleStartdate text,
  SchduleEndDate text,
  enable boolean,
  actionFlag boolean,
.... etc   
 }

Here i need to fetch the data basing on start date and end data with out ALLOW FILTERING . I got more suggestions to re-design schema to full fill the requirement But i cannot filter the data basing on id since i need the data in b/w the dates .

Some one give me a good suggestion to full fill this scenario to execute Following Query :-

select * from campaings WHERE startdate='XXX' AND endDate='XXX' ; // With out Allow Filtering thing

4
  • 1
    ((startdate,enddate,(id)) - keeping the start and end as partition and id as clustering - if your requirement is only the above query but again it will depend on how much data you will have in each range of dates - or else can you explain more about the requirement and nature of data ?
    – M P
    Mar 19, 2019 at 9:29
  • can you update the table with the syntax you mentioned ? Thanks for Quick response. I have only one primary key . But i dont need it to fetch the campaigns data since every campaign have diferent campaign ids . Needed it Basing on Start&End Date
    – Prasad
    Mar 19, 2019 at 9:54
  • 1
    CREATE TABLE campaigns (SchduleStartdate text, SchduleEndDate text, id int, scheduletime text,enable boolean, PRIMARY KEY ((SchduleStartdate, SchduleEndDate),id));
    – M P
    Mar 19, 2019 at 10:29
  • Can you Make it answer and extend the Explanation so it will be Useful for the beginners it is working in my case ..
    – Prasad
    Mar 19, 2019 at 10:59

1 Answer 1

2
CREATE TABLE campaigns (
SchduleStartdate text, 
SchduleEndDate text, 
id int, 
scheduletime text,
enable boolean, 
PRIMARY KEY ((SchduleStartdate, SchduleEndDate),id));

You can make the below queries to the table,

slect * from campaigns where  SchduleStartdate = 'xxx' and SchduleEndDate = 'xx'; -- to get the answer to above question.

slect * from campaigns where  SchduleStartdate = 'xxx' and SchduleEndDate = 'xx' and id = 1; -- if you want to filter the data again for specific ids

Here the SchduleStartdate and SchduleEndDate is used as the Partition Key and the ID is used as the Clustering key to make sure the entries are unique.

By this way, you can filter based on start, end and then id if needed.

One downside with this will be if you only need to filter by id that wont be possible as you need to first restrict the partition keys.

3
  • How to restrict Partition keys .. ? could you update with that if you can plz .. Actually get operation now asking me to Use ALLOW Filtering. Since i am new i need to ask you . How restrict partition keys in Get Operation
    – Prasad
    Mar 19, 2019 at 12:49
  • 1
    I have added the two Get queries - hope that helps
    – M P
    Mar 19, 2019 at 13:29
  • This question helped what is asked but it disturbed existing flow . So i just Up voted Hope you can understand, I created 2 tables and handled the data as per the need
    – Prasad
    Apr 2, 2019 at 13:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.