Select TTL for an element in a map in Cassandra
Asked Answered
S

1

9

Is there any way to select TTL value for an element in a map in Cassandra with CQL3?

I've tried this, but it doesn't work:

SELECT TTL (mapname['element']) FROM columnfamily
Selena answered 11/6, 2013 at 7:7 Comment(0)
B
4

Sadly, I'm pretty sure the answer is that it is not possible as of Cassandra 1.2 and CQL3. You can't query individual elements of a collection. As this blog entry says, "You can only retrieve a collection in its entirety". I'd really love to have the capability to query for collection elements, too, though.

You can still set the TTL for individual elements in a collection. I suppose if you wanted to be assured that a TTL is some value for your collection elements, you could read the entire collection and then update the collection (the entire thing or just a chosen few elements) with your desired TTL. Or, if you absolutely needed to know the TTL for individual data, you might just need to change your schema from collections back to good old dynamic columns, for which the TTL query definitely works.

Or, a third possibility could be that you add another column to your schema that holds the TTL of your collection. For example:

CREATE TABLE test (
  key text PRIMARY KEY,
  data map<text, text>,
  data_ttl text
) WITH ...

You could then keep track of the TTL of the entire map column 'data' by always updating column 'data_ttl' whenever you update 'data'. Then, you can query 'data_ttl' just like any other column:

SELECT ttl(data_ttl) FROM test;

I realize none of these solutions are perfect... I'm still trying to figure out what will work best for me, too.

Burch answered 24/10, 2013 at 16:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.