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

2

18

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?

Platinize answered 30/9, 2013 at 15:25 Comment(3)
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.Durstin
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.Platinize
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.Platinize
S
8

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

Soulless answered 19/10, 2015 at 13:18 Comment(1)
Ticket to fix this seems to be still openHurleigh
M
0

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;
Melanoid answered 1/10, 2013 at 20:0 Comment(1)
Thanks, but this won't work. The whole point of having the clustered_key column be part of the primary key is that I need the value of clustered_key to be part of the actual column name, which takes advantage of the column ordering within rows. Also, if clustered_key is not part of the primary key, then I can really only store one value per row_key.Platinize

© 2022 - 2024 — McMap. All rights reserved.