In this article we will learn about these three data model in Cassandra: Conceptual, Logical, and Physical.
Learning Objective:
Figure - ER diagram for conceptual model in Cassandra with M:N cardinality
In this Example s_id, s_name, s_course, s_branch is an attribute of student Entity and p_id, p_name, p_head is an attribute of project Entity and 'enrolled in' is a relationship in student record. This is how we will be convert ER diagram into Conceptual data model.
Figure - Data Model Flow diagram
This is actual Data model flow diagram from DataStax.
2. Logical Data Model:
In logical data model we will define each attribute or field or column with functionality such that S_id is a key partition in Student Entity And P_id is a partition key in Project Entity. Partition key is play a vital role in Cassandra in which we can execute query accordingly. In Cassandra Partition key is helpful when we will execute the CQL query and in indexing as well. For example, in Relational database this query would work but in Cassandra it would not work like this.
Figure -
3. Physical Data Model:
In this data model we will describe table Query and we will write query to build table and this is one of the actual data model where we need to write Query specifically required and implement the database functionality what we actual want. For example, lets define table one by one for student_record database by using CQL query.
Table: Student
- To Build database using quick design techniques in Cassandra.
- To Improve existing model using a query driven methodology in Cassandra.
- To Optimize Existing model via analysis and validation techniques in Cassandra.
- To understand data which is applicable for data modeling.
- To define Essential objects.
- To define constraints which is applicable for data modeling.
Student(S_id, S_name, S_branch, S_course) Project(P_id, P_name, P_head) enrolled in(S_id, P_id, S_name)Application Workflow: In each application there is work flow in which task and dependencies such that In application where number of students want to enroll for many projects.
Select * From student_data Where S_branch = 'CSE';Because, in Cassandra S_branch is not a part of partition key of the table, so first defined the partition key for such type of Query in Cassandra.
Select * From student_data Where S_id = '123';This query would work fine in Cassandra.
CREATE TABLE student_record.student ( S_id int, S_name text, S_branch, S_course, PRIMARY KEY((S_id), S_name), );Table: Project
CREATE TABLE student_record.Project ( P_id int, P_name text, P_head, PRIMARY KEY(P_id), );Table: Enrolled_in
CREATE TABLE student_record.Enrolled_in ( S_id int, P_id int, S_name text, PRIMARY KEY((S_id, P_id), S_name)), );