2016-07-15 34 views
0

想知道,如何在列級應用TTL在列級應用TTL

下面的查詢設置TTL達到創紀錄的水平

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

,而我的要求是爲特定列設置TTL。有沒有辦法實現這個

回答

0

你可以用部分數據做一個INSERT

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> 

如果你每列的INSERT語句中,可以在每列設置一個TTL獨立。