Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CQL3: How to retrieve the TTL when there is only a primary key?

I have a CQL table defined like this:

CREATE table primary_key_only(
  row_key varchar,
  clustered_key varchar,
  primary key(row_key, clustered_key)
)

Assuming I insert values like this:

INSERT INTO primary_key_only (row_key, clustered_key) VALUES ('FACE', 'D00D') USING TTL 86400;

How would I go about retrieving the TTL for the inserted data? Normally, if there was a CQL column that wasn't part of the primary key, then I could use a statement like:

SELECT ttl(<column_name>) FROM table WHERE row_key='key';

But since there are only primary key columns, functions like ttl and writetime won't work. How can I obtain the TTL, beyond adding an additional "dummy" column to the table that is not part of the primary key?

like image 471
Peter Avatar asked Sep 30 '13 15:09

Peter


People also ask

What is a primary key in Keyspace in Cassandra?

The primary key consists of only the partition key in this case. Data stored with a simple primary key will be fast to insert and retrieve if many values for the column can distribute the partitions across many nodes. Often, your first venture into using Cassandra involves tables with simple primary keys.

How do I set the TTL on a Cassandra table?

Setting a TTL for a specific columnUse CQL to set the TTL. To change the TTL of a specific column, you must re-insert the data with a new TTL. Cassandra upserts the column with the new TTL. To remove TTL from a column, set TTL to zero.

How does TTL work in Cassandra?

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.


1 Answers

Just for the sake of any future visitors, as of 2.2 this is still not possible without adding a dummy column.

like image 173
Jon Haddad Avatar answered Oct 11 '22 12:10

Jon Haddad