Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started

 

question

sanjay.jadhav_181562 avatar image
sanjay.jadhav_181562 asked ·

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.

cassandra table conditional delete configuration
10 |1000 characters needed characters left characters exceeded

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 ·

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 characters needed characters left characters exceeded

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

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 · ·

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 · ·