question

sanjay.jadhav_181562 avatar image
sanjay.jadhav_181562 asked Erick Ramirez edited

Cassandra table conditional delete configuration

I have Cassandra table with huge data,is their any provision on table level configuration so that i can delete data which is before the given date range.

for e.g. I have 100 student records for 2019 and I want to set property on table level so that it can keep only last 6 month data means table itself delete the first 6 months data of 2019.

cql
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Cedrick Lunven avatar image
Cedrick Lunven answered sanjay.jadhav_181562 commented

Hi @sanjay.jadhav_181562,

Yes this is possible with use of embedded TTL capabilities.


  • At table level with property default_time_to_live
CREATE TABLE myTable ( aa uuid, bb text, PRIMARY KEY (aa, bb) ) WITH caching = { 'keys' : 'NONE', 'default_time_to_live' : '86400' };

[Documentation HERE]

And if you want to alter an existing table here is a sample :

ALTER TABLE ks.myTable WITH compaction = { 'class': 'org.apache.cassandra.db.compaction.DateTieredCompactionStrategy', 'max_window_size_seconds': '86400'} AND gc_grace_seconds = 86400 AND default_time_to_live = 86400; 



  • At column level with CQL with using TTL
INSERT INTO users (user_name, password) VALUES ('cbrown', 'ch@ngem4a') USING TTL 86400; 

[Documentation HERE] :

And if you want to alter an existing record, simply upsert it with a new TTL value


2 comments Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

sanjay.jadhav_181562 avatar image sanjay.jadhav_181562 commented ·

Hi Cedrick Lunven thanks for the answer, in my scenario i want to implement it on existing table. as you have given sample will it delete rows of the table or it will delete entire table. if it will delete entire records on the table then it's of no use for me because i want to delete some specific rows which are older one. I want to keep recent data in the table.could you please confirm

0 Likes 0 ·
sanjay.jadhav_181562 avatar image sanjay.jadhav_181562 sanjay.jadhav_181562 commented ·

I have tried by applying time to live on table it is deleting the entire tables data after mention duration of time

0 Likes 0 ·