Вы находитесь на странице: 1из 16

Cassandra Data Model

Author: Soumyajit Swain


Cassandra
Cassandra is a distributed data based system with high availability
feature.

• Distributed
• Columnar database
• High availibilty
• Faster read-write operation
keySpace
The keyspace in Cassandra is equivalent to databse in RDBMS.

Query for keyspace


create keyspace crp_space with replication_factor=1
Data Model

Column Family 1 Column Family 2


RowKey Column 1 Column2 Column3 Column4
RowKey
• RowKey can be defined as partitioned key
• RowKey should be unique
• RowKey can be associated with multiple column family
• It should be unique
Column Family
• Column Family is same as Table in RDBMS
• Column Family contains column
• Column Family is associated with comparators
• Column Family can be static or dynamic.
Column
• Column are the minimum unit in Cassandra.
• It has name, value and timestamp property.
• The get operation will always fetch the property with latest
timestamp.
Inventory Tracking (zymeid,locid,partnercode)
zymeid partnercode locationid Sku1|t Sku2|t Sku1|O Sku1|sellIn|tim Sku2|sellIn|tim
otal otal peningb stamp stamp
Zymeid|partner alance|
code|LocationId timsta
mp

12344 345566 30 1100 90 1000 100 SN1, 90 SN5,


SN2 SN6
Inventory Tracking(zymeId)
zymeid Sku1|total Sku2|total Sku1|opendi Sku1|sellin|t Sku2|openin Sku2|return Sku2|sellin|t
zymeid ngbn|timsta imestamp gbn|timstam |timstamp imstamp
mp p

3445566 1090 2100 1000 90 2000 200 100


Detail View of Column Family
Sku1|opendingbn|timstamp

Event Event Qty Available Qty Source Txn ID UDF SN1 SN2

Opening 1000 1000 TDAWB 1223 l1 A A


Balance
CRP Data Model
RowKey – It is combination of zymeid and location Id
Cf – PartnerCodes – List of partner codes for that zymeid
Cf – {partnercode}|Total – It is a dynamic column family.Give the total
count for that partner code.
Cf-{partnercode}|{event}|{timestamp} – It captures the event wise
inventory count.
Motivation
• Dynamic and static column families
• Different types of comparator for column families
• Specific zymeId and partner inventory detail can be fetched in single
disk seek.
• Updates and inserts are faster.
• Each row can have 2 billion cells per partition
CQL3
Key space
Create keyspace zymecrp with { 'class' : 'SimpleStrategy', 'replication_factor' : 3 };

Use zymecrp;

CREATE TABLE inventory_tracking(


zymeid varchar,
partnercode varchar,
locid varchar,
total number,
PRIMARY KEY(zymeid, partnercode, locid));
Spring Cassandra
@Table (“inventory_tracking”)
public class InventoryTracking {
@PrimaryKey
private InventoryKey id;

}
@PrimaryClass
Public class InventoryKey {
@PrimaryKeyColumn(name=“zyme_id”)
private String zymeId;
@PrimaryKeyColumn(name=“partnerCode”)
private String partnerCode;
}
Insert using Spring Cassandra
Insert data using annotation
cassandraOperations.insert(new InventoryTracking("123123123", “34545", “39”));

Insert data using sql


String cql = "insert into inventory_tracking(zymeid, partnercode, locid) values ('123123123', ‘34566',’39’)";
cassandraOperations.execute(cql);
Thank you!!!

Вам также может понравиться