Skip to content
Related Articles
Open in App
Not now

Related Articles

Single-Row and Multi-Row Partitions in Cassandra

Improve Article
Save Article
  • Last Updated : 15 Feb, 2021
Improve Article
Save Article

In Cassandra, CQL(Cassandra Query Language) has two partitions as follows –

  • Single-Row Partitions
  • Multi-Row Partitions

Single-Row Partitions :
In Cassandra, the primary key represents a unique data partition and the clustering columns part are also helpful for data arrangement and are used to handle the data arrangement part. In Single-Row partitions, there is only a partitioning key on single column.

Example –
Let us take the Employee table having fields like Emp_id, Emp_name, Emp_email, where Emp_id is the primary key. 

CREATE table Employee(
Emp_id UUID, 
Emp_name TEXT, 
Emp_email TEXT,
primary key(Emp_id)
);

You can check the partitioning logical reference model for the above example as follows –

K - Primary key
C - Clustering column
S - Static column
Employee
Fields_nameData TypeKey
Emp_id UUIDK
Emp_nameTEXT 
Emp_emailTEXT 

In Cassandra, the Primary key is the combination of the Partitioning key and Clustering column if any. 

Primary Key = Partition Key + [Clustering Columns]

Multi-Row Partitions :
In Multi-Row partitions, partitioning key is applied on more than one single column and clustering column for arrangement or partitioning data modelling.

Example –
Let us take the Event table having fields like Event_venue, Event_year, Event_artifact, Events_title, Events_country, where Event_venue, Event_year are the primary keys and Event_artifact is the clustering column key. 

CREATE table Events(
Event_venue TEXT, 
Event_year INT,
Event_artifact TEXT,
Events_title TEXT,
Events_country TEXT STATIC,
primary key((Event_venue, Event_year), Event_artifact)
);

You can check partitioning logical reference model for above example as follows –

K - Primary key
C - Clustering column
S - Static column
Events
Fields_nameData TypeKey
Event_venueTEXTK
Event_yearINTK
Event_artifactTEXT 
Events_titleTEXT 
Events_country TEXTS
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!