Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check a rows TTL in cassandra?

Tags:

I have a table/column family which I am inserting rows that expire after a certain amount of time. Is it possible to then query the table to check which rows are going to expire soon (for diagnostic purposes, ie something like this:

select subject, ?ttl? from discussions; 
like image 726
Jay Avatar asked Sep 28 '13 12:09

Jay


People also ask

What is TTL in Cassandra?

Use time-to-live (TTL) to expire data in a column or table. Expiring data with TTL example. Use the INSERT and UPDATE commands for setting the expire time (TTL) for data in a column. Inserting data using COPY and a CSV file. Inserting data with the cqlsh command COPY from a CSV file is common for testing queries.

Does Cassandra have TTL?

In Cassandra Both the INSERT and UPDATE commands support setting a time for data in a column to expire. It is used to set the time limit for a specific period of time. By USING TTL clause we can set the TTL value at the time of insertion. We can use TTL function to get the time remaining for a specific selected query.

How do you check row count in Cassandra?

A SELECT expression using COUNT(*) returns the number of rows that matched the query. Alternatively, you can use COUNT(1) to get the same result.


1 Answers

You can do

select subject, TTL(subject) from discussions; 

to return the remaining TTL in seconds for subject.

E.g.

> insert into discussions (uid, subject) VALUES (now(), 'hello') using ttl 100; > select subject, TTL(subject) from discussions;   subject | ttl(subject) ---------+--------------    hello |           84 

since I waited 16 seconds before running the select.

like image 74
Richard Avatar answered Nov 02 '22 19:11

Richard