Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Cassandra table using cql3 with default TTL

Is it possible to create a table that has a default TTL for all rows that are inserted into it, or do you have to always remember to set the TTL when you do an insert/update?

Cant see anything on this in the documentation:

http://www.datastax.com/documentation/cql/3.0/cql/cql_reference/create_table_r.html

like image 361
Ziklag Avatar asked May 23 '14 10:05

Ziklag


People also ask

How do I change the default TTL on a Cassandra table?

From Cassandra doc : You can set a default TTL for an entire table by setting the table's default_time_to_live property. If you try to set a TTL for a specific column that is longer than the time defined by the table TTL, Apache Cassandra™ returns an error.

How do I add a TTL in Cassandra?

In Cassandra Both the INSERT and UPDATE commands support setting a time for data in a column to expire. It is used to set the time limit for a specific period of time. By USING TTL clause we can set the TTL value at the time of insertion. We can use TTL function to get the time remaining for a specific selected query.

Can we create table without primary key in Cassandra?

You can't create a table in Cassandra without a primary key, But still if you want to save your data you can add an additional column to your table (let say "pk") with data type UUID.

What is mandatory while creating a table in Cassandra?

The primary key is a column that is used to uniquely identify a row. Therefore,defining a primary key is mandatory while creating a table. A primary key is made of one or more columns of a table.


1 Answers

Yes it is possible to set TTL for the entire column family.

CREATE TABLE test_table (
    # your table definition #
) WITH default_time_to_live = 10;

Inserted rows then disappear after 10 seconds.

I believe the work was done for it here:

https://issues.apache.org/jira/browse/CASSANDRA-3974

Here's a docs reference sent by Patrick McFadin of DataStax (@PatrickMcFadin):

http://docs.datastax.com/en/cql/3.1/cql/cql_reference/tabProp.html

Cheers,

like image 91
reggoodwin Avatar answered Sep 21 '22 05:09

reggoodwin