📔
Databases
  • Table of contents
  • SQL
    • Getting Started
      • PgAdmin Tool
    • Data Types
      • Arrays
      • Date/Time/Stamps
      • JSON
      • Internal Functions
      • Sequences
      • User Defined Data Types
    • Database
      • Schema
    • Table
      • Aggregation
      • Usefull Functions
      • Combining Tables
      • Constraints
      • Common Table Expression
      • GROUP BY and HAVING
      • OPERATORS
      • ORDER BY and DISTINCT
      • Views
      • WHERE Clause
    • Order of SQL Execution
    • Advance Table
      • Internals
      • Managing Tables
      • Partitioning Tables
      • Pivotal or Crosstab Tables
    • Joins
      • Cross & Natural Joins
      • Full, Multiple & Self Joins
      • Inner Join
      • Left and Right JOIN
    • Functions
      • Cursors
      • PL/pgSQL
      • Stored Procedures
      • Triggers
        • More on Triggers
    • Indexing
      • Custom Indexes
      • GIN Index
      • Indexes
      • SQL
      • Unique Index
    • Summarization
      • SubQueries
      • Window
  • MongoDB
    • Mongo Administration
    • MongoDB Aggregation
    • MQL
  • Redis
  • Cassandra
    • CQL
    • Data Modelling
      • Advance Data Modelling
    • Cassandra Administration
    • Cassandra Features
Powered by GitBook
On this page
  • Time to Live
  • Counter

Was this helpful?

  1. Cassandra

Cassandra Features

PreviousCassandra Administration

Last updated 2 years ago

Was this helpful?

  • User defined Data Type :

  • Denormalization :

Time to Live

more info :

Can be set when

  • When defining table

  • insert or update operation

Example : Insert and Update operations

CREATE TABLE heartrate (
    pet_chip_id  uuid,
    name text,
    heart_rate int,
    PRIMARY KEY (pet_chip_id)
);

INSERT INTO heartrate(pet_chip_id, name, heart_rate) 
VALUES (123e4567-e89b-12d3-a456-426655440b23, 'Duke', 90);

-- check for ttl of heart rate
SELECT name, TTL(heart_rate)
FROM heartrate WHERE  pet_chip_id = 123e4567-e89b-12d3-a456-426655440b23;

-- set ttl for heart rate
UPDATE heartrate USING TTL 600 SET heart_rate =
110 WHERE pet_chip_id = 123e4567-e89b-12d3-a456-426655440b23;

-- for the entire row
INSERT INTO heartrate(pet_chip_id, name, heart_rate) 
VALUES (c63e71f0-936e-11ea-bb37-0242ac130002, 'Rocky', 87) USING TTL 30;

Example : For Table

CREATE TABLE heartrate_ttl (
    pet_chip_id  uuid,
    name text,
    heart_rate int,
    PRIMARY KEY (pet_chip_id))
WITH default_time_to_live = 500;

Counter

It’s a special data type (column) that only allows its value to be incremented, decremented, read or deleted. As a type, counters are a 64-bit signed integer. Updates to counters are atomic, making them perfect for counting and avoiding the issue of possible concurrent updates on the same value.

Counters can only be defined in a dedicated table that includes:

  • The primary key (can be compound)

  • The counter column

CREATE TABLE pet_type_count (
    pet_type text PRIMARY KEY, 
    pet_counter counter
);

Loading data to a counter table is different than other tables, it’s done with an UPDATE operation

UPDATE pet_type_count SET pet_counter = pet_counter + 6 
WHERE pet_type = 'dog';

more info :

https://university.scylladb.com/courses/data-modeling/lessons/advanced-data-modeling/topic/user-defined-types-udt/
https://university.scylladb.com/courses/data-modeling/lessons/advanced-data-modeling/topic/denormalization/
https://university.scylladb.com/courses/data-modeling/lessons/advanced-data-modeling/topic/expiring-data-with-ttl-time-to-live/
https://university.scylladb.com/courses/data-modeling/lessons/advanced-data-modeling/topic/counters/