Apply TTL in column level

让人想犯罪 __ 提交于 2019-12-24 06:04:26

问题


Want to know, how to apply TTL in column level.

below query set the TTL at record level

  INSERT INTO excelsior.clicks (
  userid, url, date, name)
  VALUES 
    (
    3715e600-2eb0-11e2-81c1-0800200c9a66,
   'http://apache.org',
   '2013-10-09', 'Mary'
     )
    USING TTL 86400;

whereas my requirement is setting TTL for a particular column. Is there any way to achieve this


回答1:


You can do an INSERT with partial data:

cqlsh> create KEYSPACE test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
cqlsh> use test;
cqlsh:test> create table test(userid uuid, url text, date text, name text, primary key(userid));
cqlsh:test> 
cqlsh:test> insert into test(userid, url, date, name) VALUES 
        ...     (
        ...     3715e600-2eb0-11e2-81c1-0800200c9a66,
        ...    'http://apache.org',
        ...    '2013-10-09', 'Mary'
        ...      )
        ...     USING TTL 86400;
cqlsh:test> 
cqlsh:test> select userid, url, TTL(url), date, TTL(date), name, TTL(name) from test;

 userid                               | url               | ttl(url) | date       | ttl(date) | name | ttl(name)
--------------------------------------+-------------------+----------+------------+-----------+------+-----------
 3715e600-2eb0-11e2-81c1-0800200c9a66 | http://apache.org |    86342 | 2013-10-09 |     86342 | Mary |     86342

(1 rows)    
cqlsh:test> insert into test(userid, url ) VALUES (3715e600-2eb0-11e2-81c1-0800200c9a66,    'http://apache.org'   ) USING TTL 864000; 
cqlsh:test> 
cqlsh:test> select userid, url, TTL(url), date, TTL(date), name, TTL(name) from test;

 userid                               | url               | ttl(url) | date       | ttl(date) | name | ttl(name)
--------------------------------------+-------------------+----------+------------+-----------+------+-----------
 3715e600-2eb0-11e2-81c1-0800200c9a66 | http://apache.org |   863992 | 2013-10-09 |     86109 | Mary |     86109

(1 rows)
cqlsh:test> 

If you do an insert statement per column, you can set a TTL on each column individually.



来源:https://stackoverflow.com/questions/38388013/apply-ttl-in-column-level

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!