Search code examples
cassandraapache-sparkconnectorttl

Spark saving to Cassandra with TTL


I am using Spark-Cassandra connector 1.1.0 with Cassandra 2.0.12.

I write RDDs to Cassandra via the saveToCassandra() Java API method.

Is there a way to set the TTL property of the persisted records with the connector?

Thanks,

Shai


Solution

  • Unfortunately it doesn't seem like there is a way to do this (that I know of) with version 1.1.0 of the connector. There is a way in 1.2.0-alpha3 however.

    saveToCassandra() is a wrapper over WriterBuilder which has a withTTL method. Instead of using saveToCassandra you could use writerBuilder(keyspace,table,rowWriter).withTTL(seconds).saveToCassandra().