17
votes

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?

2
I believe there isn't a way to achieve this in CQL. I am, however, able to get the TTL using cassandra-cli. I'm wondering: what does it mean to specify the TTL for a column name, which is what 'D00D' effectively is in the backend. A value can expire, but can a name also expire? Of course, we can store values in the column name, but the implementation, at least CQL's, does not take that assumption into account.Nikhil
In cassandra-cli, I basically see a column (whose name has 'D00D' in it) with a blank value; this blank value is what the TTL is actually associated with. Because there are no non-primary key CQL columns, no values actually get stored, only column names. I know that you can get the TTL via cassandra-cli, but that isn't an option for me as I'm using the Datastax Java Driver to query. (Should have mentioned) Thanks for your advice.Peter
So, it's looking more and more like I'll just have to add a dummy column that's not part of the primary key, just in order to be able to retrieve the TTL. This dummy value will always be blank. Come to think of it, it's really not that different to how things are physically stored anyways: Cassandra will create a row with column names corresponding to the value in clustered_key, but the actual value will be empty.Peter

2 Answers

6
votes

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

0
votes

You could call ttl on clustered_key except that it is part of the primary key.

Perhaps clustered key doesn't need to be part of your primary key?

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

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

SELECT row_key, clustered_key, ttl(clustered_key) FROM primary_key_only;