Perhaps you can set the default TTL when you create the table instead of on 
every insert:
http://docs.datastax.com/en/cql/3.1/cql/cql_reference/tabProp.html
(see default_time_to_live property)

Then no need for UDF.


Sean Durity
lord of the (C*) rings (Lead Cassandra Admin)
Big DATA Team
MTC 2250
#cassandra - for the latest news and updates

From: Sujeet Kumar [mailto:genioussuj...@gmail.com]
Sent: Monday, August 08, 2016 11:18 AM
To: user@cassandra.apache.org
Subject: setting ttl using timestamp field of record during insertion in 
cassandra

Hi

I want to set TTL 30 days from the time field of table record(id,name,time) 
during insertion.For this I am creating a User Defined Function(UDF) bigint 
fun(rTime,cTime) as

CREATE FUNCTION fun(rtime timestamp,ctime timestamp) CALLED ON NULL INPUT 
RETURNS bigint LANGUAGE java as 'return 2592000-((ctime.toTime() 
-rtime.toTime())/1000);';

here,function fun is calculating the time in seconds this data should live.
2592000 is the time in seconds for 30 days.

I am trying to use above function for setting TTL as

INSERT INTO record(id,name,time) VALUES (123,'data123','2016-08-08 06:06:00') 
USING TTL fun('2016-08-08 06:06:00',totimestamp(now()));

getting error as
Syntax Exception: ErrorMessage code=2000 ........

Is there any other way to set ttl based on record time field. What is problem 
with above approach.

Thanks.

Sujeet

--

--
Sujeet Kumar
ME(CSA)
IISc Banglore
sujeet.ku...@csa.iisc.ernet.in<mailto:sujeet.ku...@csa.iisc.ernet.in>
sujeet.cs...@mnnit.ac.in<mailto:sujeet.cs...@mnnit.ac.in>

________________________________

The information in this Internet Email is confidential and may be legally 
privileged. It is intended solely for the addressee. Access to this Email by 
anyone else is unauthorized. If you are not the intended recipient, any 
disclosure, copying, distribution or any action taken or omitted to be taken in 
reliance on it, is prohibited and may be unlawful. When addressed to our 
clients any opinions or advice contained in this Email are subject to the terms 
and conditions expressed in any applicable governing The Home Depot terms of 
business or client engagement letter. The Home Depot disclaims all 
responsibility and liability for the accuracy and content of this attachment 
and for any damages or losses arising from any inaccuracies, errors, viruses, 
e.g., worms, trojan horses, etc., or other items of a destructive nature, which 
may be contained in this attachment and shall not be liable for direct, 
indirect, consequential or special damages in connection with this e-mail 
message or its attachment.

Reply via email to