[ 
https://issues.apache.org/jira/browse/CASSANDRA-8877?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17569390#comment-17569390
 ] 

Andres de la Peña commented on CASSANDRA-8877:
----------------------------------------------

The proposed patch provides CQL support for getting the writetime/ttl of the 
cells of:

* Entire collections/UDTs

* Single collections/UDTs elements 

* Slices of collection elements

||PR||CI||
|[trunk|https://github.com/apache/cassandra/pull/1739]|[j8|https://app.circleci.com/pipelines/github/adelapena/cassandra/1943/workflows/947857e9-c2a5-4ad3-9c4c-c99869dd868b]
 
[j11|https://app.circleci.com/pipelines/github/adelapena/cassandra/1943/workflows/2851c046-e704-4c51-a8a4-b995475530be]|

It is based on an old patch that I wrote some time ago with the invaluable help 
of [~blerer].

Here is an example of the behaviour for frozen collections:
{code}
CREATE TABLE IF NOT EXISTS t (k int PRIMARY KEY, s frozen<set<int>>);
INSERT INTO t (k, s) VALUES (1, {1, 2, 3}) USING TIMESTAMP 100 AND TTL 10000;

SELECT s, WRITETIME(s), TTL(s) FROM t;

 s         | writetime(s) | ttl(s)
-----------+--------------+--------
 {1, 2, 3} |          100 |  10000


SELECT s[2], WRITETIME(s[2]), TTL(s[2]) FROM t;

 s[2] | writetime(s[2]) | ttl(s[2])
------+-----------------+-----------
    2 |             100 |     10000


SELECT s[4], WRITETIME(s[4]), TTL(s[4]) FROM t;

 s[4] | writetime(s[4]) | ttl(s[4])
------+-----------------+-----------
 null |            null |      null


SELECT s[2..], WRITETIME(s[2..]), TTL(s[2..]) FROM t;

 s[2..] | writetime(s[2..]) | ttl(s[2..])
--------+-------------------+-------------
 {2, 3} |               100 |        9897
{code}
For not-frozen collections:
{code}
CREATE TABLE IF NOT EXISTS t (k int PRIMARY KEY, s set<int>);
INSERT INTO t (k, s) VALUES (1, {1, 2}) USING TIMESTAMP 100 AND TTL 10000;
UPDATE t USING TIMESTAMP 200 AND TTL 20000 SET s += {3} WHERE k=1;

SELECT s, WRITETIME(s), TTL(s) FROM t;

 s         | writetime(s)    | ttl(s)
-----------+-----------------+-----------------------
 {1, 2, 3} | [100, 100, 200] | [10000, 10000, 20000]


SELECT s[2], WRITETIME(s[2]), TTL(s[2]) FROM t;

 s[2] | writetime(s[2]) | ttl(s[2])
------+-----------------+-----------
    2 |             100 |     10000


SELECT s[4], WRITETIME(s[4]), TTL(s[4]) FROM t;

 s[4] | writetime(s[4]) | ttl(s[4])
------+-----------------+-----------
 null |            null |      null


SELECT s[2..], WRITETIME(s[2..]), TTL(s[2..]) FROM t;

 s[2..] | writetime(s[2..]) | ttl(s[2..])
--------+-------------------+----------------
 {2, 3} |        [100, 200] | [10000, 20000]
{code}
For frozen UDTs:
{code}
CREATE TYPE udt (f1 int, f2 int, f3 int);
CREATE TABLE t (k int PRIMARY KEY, t frozen<udt>);
INSERT INTO t (k, t) VALUES (1, {f1: 1, f2: 2}) USING TIMESTAMP 100 AND TTL 
10000;

SELECT t, WRITETIME(t), TTL(t) FROM t;

 t                        | writetime(t) | ttl(t)
--------------------------+--------------+--------
 {f1: 1, f2: 2, f3: null} |          100 |  10000


SELECT t.f1, WRITETIME(t.f1), TTL(t.f1) FROM t;

 t.f1 | writetime(t.f1) | ttl(t.f1)
------+-----------------+-----------
    1 |             100 |     10000


SELECT t.f2, WRITETIME(t.f2), TTL(t.f2) FROM t;

 t.f2 | writetime(t.f2) | ttl(t.f2)
------+-----------------+-----------
    2 |             100 |     10000


SELECT t.f3, WRITETIME(t.f3), TTL(t.f3) FROM t;

 t.f3 | writetime(t.f3) | ttl(t.f3)
------+-----------------+-----------
 null |            null |      null
{code}
For not-frozen UDTs:
{code}
CREATE TYPE udt (f1 int, f2 int, f3 int);
CREATE TABLE t (k int PRIMARY KEY, t udt);
INSERT INTO t (k, t) VALUES (1, {f1: 1}) USING TIMESTAMP 100 AND TTL 10000;
UPDATE t USING TIMESTAMP 200 AND TTL 20000 SET t.f2 = 2 WHERE k = 1;

SELECT t, WRITETIME(t), TTL(t) FROM t;

 t                        | writetime(t)     | ttl(t)
--------------------------+------------------+----------------------
 {f1: 1, f2: 2, f3: null} | [100, 200, None] | [10000, 20000, None]


SELECT t.f1, WRITETIME(t.f1), TTL(t.f1) FROM t;

 t.f1 | writetime(t.f1) | ttl(t.f1)
------+-----------------+-----------
    1 |             100 |     10000


SELECT t.f2, WRITETIME(t.f2), TTL(t.f2) FROM t;

 t.f2 | writetime(t.f2) | ttl(t.f2)
------+-----------------+-----------
    2 |             200 |     20000


SELECT t.f3, WRITETIME(t.f3), TTL(t.f3) FROM t;

 t.f3 | writetime(t.f3) | ttl(t.f3)
------+-----------------+-----------
 null |            null |      null
{code}
As for the {{MAXWRITETIME}} function added by CASSANDRA-17425, I have adapted 
it so it can also used on items of a collection. It's possible to query things 
like {{MAXWRITETTIME(phones[2..4])}} or {{MAXWRITETTIME(user.name)}}. However, 
I think we should try to get rid of that function and instead provide generic 
functions to aggregate the elements of a collection, so instead of 
{{MAXWRITETTIME(phones[2..4])}} we would write something like 
{{GREATEST(WRITETTIME(phones[2..4]))}}. In any case, I think that should 
probably done in a followup ticket. [~yifanc] wdyt?


> Ability to read the TTL and WRITE TIME of an element in a collection
> --------------------------------------------------------------------
>
>                 Key: CASSANDRA-8877
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-8877
>             Project: Cassandra
>          Issue Type: Improvement
>          Components: Legacy/CQL
>            Reporter: Drew Kutcharian
>            Assignee: Andres de la Peña
>            Priority: Low
>             Fix For: 4.x
>
>
> Currently it's possible to set the TTL and WRITE TIME of an element in a 
> collection using CQL, but there is no way to read them back. 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to