SlideShare a Scribd company logo
1 of 33
Download to read offline
©2014 DataStax Confidential. Do not distribute without consent.
@rstml
Rustam Aliyev
Solution Architect 
Deep dive into CQL
andCQLimprovementsinCassandra2.1
1
What is CQL?
* Cassandra Query Language (CQL)
* SQL-like language for communicating with Cassandra
* Simpler than the Thrift API
* An abstraction layer that hides implementation details
This is what we want to understand
Use Case
* Messaging Application
* Group Conversations
* Attachments
Simple CQL Table
CREATE TABLE messages (
conversation_id uuid,
message_id timeuuid,
content text,
sender text,
PRIMARY KEY (conversation_id, message_id)
);
TimeUUID
* Also known as a Version 1 UUID
* Sortable
Timestamp to Microsecond +	 UUID	 =	 TimeUUID	
04d580b0-9412-11e3-baa8-0800200c9a66	 12 February 2014 13:18:06 GMT	
http://www.famkruithof.net/uuid/uuidgen"
=
Primary Key
CREATE TABLE messages (
conversation_id uuid,
message_id timeuuid,
content text,
sender uuid,
PRIMARY KEY (conversation_id, message_id)
);
Partition Key Clustering Column
* Also Primary Index
Partition Key
conversation_id: 04d580b0-9412-…9a66
Replica
* Determines partition (and replicas)
* Remaining columns are stored on the
determined partition
RF=3
Clustering Column
Merged, Sorted and Stored Sequentially
04d580b0-9412-…9a66
2013-04-03 07:01:00
content: Hi!
sender: ali@example.tr
2013-04-03 07:03:20
content: Hello!
Sender: tom@example…
2013-04-03 07:04:52
content: Where are you?
sender: ali@example.tr
2013-04-03 07:05:01
content: in Istanbul
sender: tom@example…
2013-04-03 07:06:32
content: wow! how come
sender: ali@example.tr
* Data on disk is ordered based on Clustering Column
* Efficient retrieval with range queries (slice)
SELECT * FROM messages
WHERE conversation_id = '04d580b0-9412-…9a66'
AND message_id > minTimeuuid('2013-04-03 07:04:00')
AND message_id < maxTimeuuid('2013-04-03 07:10:00');
Data on Disk
Partition Key (Row Key)
Column Name 1 Column Value 1
Column Name 2 Column Value 2
Column Name 3 Column Value 3
...
Column Name N Column Value N
Data on Disk
04d580b0-9412-3a00-93d1-46196ee79a66
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:content Hi!
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:sender ali@example.tr
2f3feb0f-9c24-11e2-7f7f-7f7f7f7f7f7f:
2f3feb0f-9c24-11e2-7f7f-7f7f7f7f7f7f:content Hello!
2f3feb0f-9c24-11e2-7f7f-7f7f7f7f7f7f:sender tom@example.com
...
Clustering Column (message_id) Column Name Column Value
Partition Key (conversation_id)
	
  INSERT	
  INTO	
  messages	
  (conversation_id,	
  message_id,	
  content,	
  sender)	
  VALUES	
  
	
  	
  (04d580b0-­‐9412-­‐3a00-­‐93d1-­‐46196ee79a66,	
  2f3feb0f-­‐9c24-­‐11e2-­‐7f7f-­‐7f7f7f7f7f7f,	
  
	
  	
  	
  	
  'Hello!',	
  'tom@example.com');	
  
Order of Clustering Keys
CREATE TABLE messages (
conversation_id uuid,
message_id timeuuid,
content text,
sender text,
PRIMARY KEY (conversation_id, message_id)
)
WITH CLUSTERING ORDER BY (message_id DESC);
* We need only most recent N messages
* Storing messages in reverse TimeUUID order will speedup queries
Static Columns
CREATE TABLE messages (
conversation_id uuid,
conversation_owner text STATIC,
message_id timeuuid,
content text,
sender text,
PRIMARY KEY (conversation_id, message_id)
);
* Let’s add conversation owner (admin)
* Owner is related to conversation (Partition Key) not message (Clustering Key)
Static Columns
UPDATE messages SET
conversation_owner = 'ali@example.tr'
WHERE
conversation_id = 04d580b0-9412-3a00-93d1-46196ee79a66;
* Same UPDATE with non-static field will fail
Static Columns on Disk
04d580b0-9412-3a00-93d1-46196ee79a66
:null:conversation_owner ali@example.tr
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:content Hi!
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:sender ali@example.tr
2f3feb0f-9c24-11e2-7f7f-7f7f7f7f7f7f:
2f3feb0f-9c24-11e2-7f7f-7f7f7f7f7f7f:content Hello!
2f3feb0f-9c24-11e2-7f7f-7f7f7f7f7f7f:sender tom@example.com
...
Static Column
Collections: Set
CREATE TABLE messages (
conversation_id uuid,
conversation_owner text STATIC,
message_id timeuuid,
content text,
sender text,
recipients set<text>,
PRIMARY KEY (conversation_id, message_id)
);
* We want to keep message recipients
* List of recipients may vary as people join and leave conversation
Collections: Set
UPDATE messages SET
recipients = {'ali@example.tr', 'tom@example.com'}
WHERE
conversation_id = 04d580b0-9412-3a00-93d1-46196ee79a66 AND
message_id = dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f;
Set on Disk
04d580b0-9412-3a00-93d1-46196ee79a66
:null:conversation_owner ali@example.tr
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:content Hi!
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:sender ali@example.tr
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:recipient:ali@example.tr
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:recipient:tom@example.com
2f3feb0f-9c24-11e2-7f7f-7f7f7f7f7f7f:
...
Set
Collections: Map
CREATE TABLE messages (
conversation_id uuid,
conversation_owner text STATIC,
message_id timeuuid,
content text,
sender text,
recipients set<text>,
attachments map<text,text>,
PRIMARY KEY (conversation_id, message_id)
);
* Let’s add attachments to message
* Each attachment would have name and location (URI)
Collections: Map
UPDATE messages SET
attachments = {'picture.png':'http://cdn.exmpl.com/1234.png',
'audio.wav':'http://cdn.exmpl.com/5678.wav'}
WHERE
conversation_id = 04d580b0-9412-3a00-93d1-46196ee79a66 AND
message_id = dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f;
Map on Disk
04d580b0-9412-3a00-93d1-46196ee79a66
:null:conversation_owner ali@example.tr
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:content Hi!
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:sender ali@example.tr
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:recipient:ali@example.tr
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:recipient:tom@example.com
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:attachments:picture.png http://cdn.exmpl.com/1234.png
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:attachments:audio.wav http://cdn.exmpl.com/5678.wav
2f3feb0f-9c24-11e2-7f7f-7f7f7f7f7f7f:
...
Map Name Key Value
Collections: List
CREATE TABLE messages (
conversation_id uuid,
conversation_owner text STATIC,
message_id timeuuid,
content text,
sender text,
recipients set<text>,
attachments map<text,text>,
seen_by list<text>,
PRIMARY KEY (conversation_id, message_id)
);
* We want to know which participants have seen message and preserve order
Collections: List
UPDATE messages SET
seen_by = ['adam@example.tr', 'tom@example.com']
WHERE
conversation_id = 04d580b0-9412-3a00-93d1-46196ee79a66 AND
message_id = dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f;
List on Disk
04d580b0-9412-3a00-93d1-46196ee79a66
:null:conversation_owner ali@example.tr
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:content Hi!
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:sender ali@example.tr
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:recipient:ali@example.tr
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:recipient:tom@example.com
dbcd9d0f-...-7f7f-7f7f7f7f7f7f:seen_by:26017c10-f487-11e2-801f-df9895e5d0f8 adam@example.tr
dbcd9d0f-...-7f7f-7f7f7f7f7f7f:seen_by:26017c11-f487-11e2-801f-df9895e5d0f8 tom@example.com
2f3feb0f-9c24-11e2-7f7f-7f7f7f7f7f7f:
...
List Name Element ID (TimeUUID) Value
User Defined Types (UDT)
CREATE TABLE messages (
conversation_id uuid,
conversation_owner text STATIC,
message_id timeuuid,
content text,
sender text,
recipients set<text>,
seen_by list<text>,
attachments map<text,attachment>,
PRIMARY KEY (conversation_id, message_id)
);
* New in Cassandra 2.1
* Let’s add more attributes to attachments
CREATE TYPE attachment (
size int,
mime text,
uri text
);
User Defined Types
UPDATE messages SET
attachments = attachments
+ { 'picture.png': { size: 10240,
mime: 'image/png',
uri: 'http://cdn.exmpl.com/1234.png' }}
WHERE
conversation_id = 04d580b0-9412-3a00-93d1-46196ee79a66 AND
message_id = dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f;
UDT on Disk
04d580b0-9412-3a00-93d1-46196ee79a66
:null:conversation_owner ali@example.tr
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:content Hi!
dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:sender ali@example.tr
dbcd9d0f-...-7f7f7f7f7f7f:recipient:ali@example.tr
dbcd9d0f-...-7f7f7f7f7f7f:recipient:tom@example.com
dbcd9d0f-...-7f7f7f7f7f7f:attachments:picture.png
10240:'image/png':'http://cdn.exmpl.com/
1234.png'
2f3feb0f-9c24-11e2-7f7f-7f7f7f7f7f7f:
...
Map Key UDT Value
Secondary Indexes
CREATE TABLE messages (
conversation_id uuid,
conversation_owner text STATIC,
message_id timeuuid,
content text,
sender text,
recipients set<text>,
seen_by list<text>,
attachments map<text,text>,
PRIMARY KEY (conversation_id, message_id)
);
* What if we want to lookup messages by sender?
CREATE INDEX sender_idx ON messages(sender); "
Secondary Indexes
Secondary Indexes Internally
sender_idx
{
"ali@example.tr"
{
54bbfd0f-9c02-11e2-7f7f-7f7f7f7f7f7f : null,
df04610f-9c02-11e2-7f7f-7f7f7f7f7f7f : null
},
"tom@exmaple.com"
{
a82e4b0f-9c02-11e2-7f7f-7f7f7f7f7f7f : null
}
}
* Each node will keep reverse index for local data only
Indexes on Collections
CREATE TABLE messages (
conversation_id uuid,
conversation_owner text STATIC,
message_id timeuuid,
content text,
sender text,
recipients set<text>,
seen_by list<text>,
attachments map<text,text>,
PRIMARY KEY (conversation_id, message_id)
);
* New in Cassandra 2.1
CREATE INDEX recipients_idx ON messages(recipients); "
Indexes on Collections
Way more information
• 5 minute interviews
• Use cases
• Free training!
www.planetcassandra.org
Questions?

More Related Content

Viewers also liked

2014 Dallas Sept VMware User Group Conference - Datacenter Automation
2014 Dallas Sept VMware User Group Conference - Datacenter Automation2014 Dallas Sept VMware User Group Conference - Datacenter Automation
2014 Dallas Sept VMware User Group Conference - Datacenter AutomationTommy Trogden
 
Journey to end user computing dallas vmug may 2013
Journey to end user computing   dallas vmug may 2013Journey to end user computing   dallas vmug may 2013
Journey to end user computing dallas vmug may 2013Tommy Trogden
 
2016 April Austin VMUG User Conference - lunch keynote
2016 April Austin VMUG User Conference - lunch keynote 2016 April Austin VMUG User Conference - lunch keynote
2016 April Austin VMUG User Conference - lunch keynote Tommy Trogden
 
2015 apr - vmug conference - Datacenter Automation - Disruption
2015 apr - vmug conference - Datacenter Automation - Disruption2015 apr - vmug conference - Datacenter Automation - Disruption
2015 apr - vmug conference - Datacenter Automation - DisruptionTommy Trogden
 
EMC World 2016 12 Factor Apps FTW
EMC World 2016 12 Factor Apps FTWEMC World 2016 12 Factor Apps FTW
EMC World 2016 12 Factor Apps FTWTommy Trogden
 
Unlock your VMWare Investment with Pivotal Cloud Foundry (VMworld 2014)
Unlock your VMWare Investment with Pivotal Cloud Foundry (VMworld 2014)Unlock your VMWare Investment with Pivotal Cloud Foundry (VMworld 2014)
Unlock your VMWare Investment with Pivotal Cloud Foundry (VMworld 2014)VMware Tanzu
 
Network Functions Virtualization and CloudStack
Network Functions Virtualization and CloudStackNetwork Functions Virtualization and CloudStack
Network Functions Virtualization and CloudStackChiradeep Vittal
 
Cassandra and DataStax Enterprise on PCF
Cassandra and DataStax Enterprise on PCFCassandra and DataStax Enterprise on PCF
Cassandra and DataStax Enterprise on PCFVMware Tanzu
 
How DataStax Enterprise and Azure Make Your Apps Scale from Day 1
How DataStax Enterprise and Azure Make Your Apps Scale from Day 1How DataStax Enterprise and Azure Make Your Apps Scale from Day 1
How DataStax Enterprise and Azure Make Your Apps Scale from Day 1DataStax
 
DataStax | DSE Production-Certified Cassandra on Pivotal Cloud Foundry (Ben L...
DataStax | DSE Production-Certified Cassandra on Pivotal Cloud Foundry (Ben L...DataStax | DSE Production-Certified Cassandra on Pivotal Cloud Foundry (Ben L...
DataStax | DSE Production-Certified Cassandra on Pivotal Cloud Foundry (Ben L...DataStax
 
Zen and the Art of Platform
Zen and the Art of PlatformZen and the Art of Platform
Zen and the Art of PlatformVMware Tanzu
 
LIVE DEMO: Pivotal Cloud Foundry
LIVE DEMO: Pivotal Cloud FoundryLIVE DEMO: Pivotal Cloud Foundry
LIVE DEMO: Pivotal Cloud FoundryVMware Tanzu
 
Part 2: Architecture and the Operator Experience (Pivotal Cloud Platform Road...
Part 2: Architecture and the Operator Experience (Pivotal Cloud Platform Road...Part 2: Architecture and the Operator Experience (Pivotal Cloud Platform Road...
Part 2: Architecture and the Operator Experience (Pivotal Cloud Platform Road...VMware Tanzu
 
Cassandra vs. Redis
Cassandra vs. RedisCassandra vs. Redis
Cassandra vs. RedisTim Lossen
 
Using Pivotal Cloud Foundry with Google’s BigQuery and Cloud Vision API
Using Pivotal Cloud Foundry with Google’s BigQuery and Cloud Vision APIUsing Pivotal Cloud Foundry with Google’s BigQuery and Cloud Vision API
Using Pivotal Cloud Foundry with Google’s BigQuery and Cloud Vision APIVMware Tanzu
 
Breaking the Monolith
Breaking the MonolithBreaking the Monolith
Breaking the MonolithVMware Tanzu
 
Pivotal Cloud Foundry: A Technical Overview
Pivotal Cloud Foundry: A Technical OverviewPivotal Cloud Foundry: A Technical Overview
Pivotal Cloud Foundry: A Technical OverviewVMware Tanzu
 
Cloud Foundry Compared With Other PaaSes (Cloud Foundry Summit 2014)
Cloud Foundry Compared With Other PaaSes (Cloud Foundry Summit 2014)Cloud Foundry Compared With Other PaaSes (Cloud Foundry Summit 2014)
Cloud Foundry Compared With Other PaaSes (Cloud Foundry Summit 2014)VMware Tanzu
 
Understand the What, Why & How of Digital Transformation Featuring 451 Research
Understand the What, Why & How of Digital Transformation Featuring 451 ResearchUnderstand the What, Why & How of Digital Transformation Featuring 451 Research
Understand the What, Why & How of Digital Transformation Featuring 451 ResearchVMware Tanzu
 
AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...
AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...
AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...Lucas Jellema
 

Viewers also liked (20)

2014 Dallas Sept VMware User Group Conference - Datacenter Automation
2014 Dallas Sept VMware User Group Conference - Datacenter Automation2014 Dallas Sept VMware User Group Conference - Datacenter Automation
2014 Dallas Sept VMware User Group Conference - Datacenter Automation
 
Journey to end user computing dallas vmug may 2013
Journey to end user computing   dallas vmug may 2013Journey to end user computing   dallas vmug may 2013
Journey to end user computing dallas vmug may 2013
 
2016 April Austin VMUG User Conference - lunch keynote
2016 April Austin VMUG User Conference - lunch keynote 2016 April Austin VMUG User Conference - lunch keynote
2016 April Austin VMUG User Conference - lunch keynote
 
2015 apr - vmug conference - Datacenter Automation - Disruption
2015 apr - vmug conference - Datacenter Automation - Disruption2015 apr - vmug conference - Datacenter Automation - Disruption
2015 apr - vmug conference - Datacenter Automation - Disruption
 
EMC World 2016 12 Factor Apps FTW
EMC World 2016 12 Factor Apps FTWEMC World 2016 12 Factor Apps FTW
EMC World 2016 12 Factor Apps FTW
 
Unlock your VMWare Investment with Pivotal Cloud Foundry (VMworld 2014)
Unlock your VMWare Investment with Pivotal Cloud Foundry (VMworld 2014)Unlock your VMWare Investment with Pivotal Cloud Foundry (VMworld 2014)
Unlock your VMWare Investment with Pivotal Cloud Foundry (VMworld 2014)
 
Network Functions Virtualization and CloudStack
Network Functions Virtualization and CloudStackNetwork Functions Virtualization and CloudStack
Network Functions Virtualization and CloudStack
 
Cassandra and DataStax Enterprise on PCF
Cassandra and DataStax Enterprise on PCFCassandra and DataStax Enterprise on PCF
Cassandra and DataStax Enterprise on PCF
 
How DataStax Enterprise and Azure Make Your Apps Scale from Day 1
How DataStax Enterprise and Azure Make Your Apps Scale from Day 1How DataStax Enterprise and Azure Make Your Apps Scale from Day 1
How DataStax Enterprise and Azure Make Your Apps Scale from Day 1
 
DataStax | DSE Production-Certified Cassandra on Pivotal Cloud Foundry (Ben L...
DataStax | DSE Production-Certified Cassandra on Pivotal Cloud Foundry (Ben L...DataStax | DSE Production-Certified Cassandra on Pivotal Cloud Foundry (Ben L...
DataStax | DSE Production-Certified Cassandra on Pivotal Cloud Foundry (Ben L...
 
Zen and the Art of Platform
Zen and the Art of PlatformZen and the Art of Platform
Zen and the Art of Platform
 
LIVE DEMO: Pivotal Cloud Foundry
LIVE DEMO: Pivotal Cloud FoundryLIVE DEMO: Pivotal Cloud Foundry
LIVE DEMO: Pivotal Cloud Foundry
 
Part 2: Architecture and the Operator Experience (Pivotal Cloud Platform Road...
Part 2: Architecture and the Operator Experience (Pivotal Cloud Platform Road...Part 2: Architecture and the Operator Experience (Pivotal Cloud Platform Road...
Part 2: Architecture and the Operator Experience (Pivotal Cloud Platform Road...
 
Cassandra vs. Redis
Cassandra vs. RedisCassandra vs. Redis
Cassandra vs. Redis
 
Using Pivotal Cloud Foundry with Google’s BigQuery and Cloud Vision API
Using Pivotal Cloud Foundry with Google’s BigQuery and Cloud Vision APIUsing Pivotal Cloud Foundry with Google’s BigQuery and Cloud Vision API
Using Pivotal Cloud Foundry with Google’s BigQuery and Cloud Vision API
 
Breaking the Monolith
Breaking the MonolithBreaking the Monolith
Breaking the Monolith
 
Pivotal Cloud Foundry: A Technical Overview
Pivotal Cloud Foundry: A Technical OverviewPivotal Cloud Foundry: A Technical Overview
Pivotal Cloud Foundry: A Technical Overview
 
Cloud Foundry Compared With Other PaaSes (Cloud Foundry Summit 2014)
Cloud Foundry Compared With Other PaaSes (Cloud Foundry Summit 2014)Cloud Foundry Compared With Other PaaSes (Cloud Foundry Summit 2014)
Cloud Foundry Compared With Other PaaSes (Cloud Foundry Summit 2014)
 
Understand the What, Why & How of Digital Transformation Featuring 451 Research
Understand the What, Why & How of Digital Transformation Featuring 451 ResearchUnderstand the What, Why & How of Digital Transformation Featuring 451 Research
Understand the What, Why & How of Digital Transformation Featuring 451 Research
 
AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...
AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...
AMIS SIG - Introducing Apache Kafka - Scalable, reliable Event Bus & Message ...
 

Similar to Deep dive into CQL

Oracle to Cassandra Core Concepts Guide Pt. 2
Oracle to Cassandra Core Concepts Guide Pt. 2Oracle to Cassandra Core Concepts Guide Pt. 2
Oracle to Cassandra Core Concepts Guide Pt. 2DataStax Academy
 
Dublin Meetup: Cassandra anti patterns
Dublin Meetup: Cassandra anti patternsDublin Meetup: Cassandra anti patterns
Dublin Meetup: Cassandra anti patternsChristopher Batey
 
Paul Dix [InfluxData] The Journey of InfluxDB | InfluxDays 2022
Paul Dix [InfluxData] The Journey of InfluxDB | InfluxDays 2022Paul Dix [InfluxData] The Journey of InfluxDB | InfluxDays 2022
Paul Dix [InfluxData] The Journey of InfluxDB | InfluxDays 2022InfluxData
 
Introduction to Dating Modeling for Cassandra
Introduction to Dating Modeling for CassandraIntroduction to Dating Modeling for Cassandra
Introduction to Dating Modeling for CassandraDataStax Academy
 
It Depends - Database admin for developers - Rev 20151205
It Depends - Database admin for developers - Rev 20151205It Depends - Database admin for developers - Rev 20151205
It Depends - Database admin for developers - Rev 20151205Maggie Pint
 
User Defined Partitioning on PlazmaDB
User Defined Partitioning on PlazmaDBUser Defined Partitioning on PlazmaDB
User Defined Partitioning on PlazmaDBKai Sasaki
 
Sqlxml vs xquery
Sqlxml vs xquerySqlxml vs xquery
Sqlxml vs xqueryAmol Pujari
 
Cassandra lesson learned - extended
Cassandra   lesson learned  - extendedCassandra   lesson learned  - extended
Cassandra lesson learned - extendedAndrzej Ludwikowski
 
MySQL Database System Hiep Dinh
MySQL Database System Hiep DinhMySQL Database System Hiep Dinh
MySQL Database System Hiep Dinhwebhostingguy
 
Store and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraDeependra Ariyadewa
 
Introduction to Data Modeling with Apache Cassandra
Introduction to Data Modeling with Apache CassandraIntroduction to Data Modeling with Apache Cassandra
Introduction to Data Modeling with Apache CassandraDataStax Academy
 
Dns protocol design attacks and security
Dns protocol design attacks and securityDns protocol design attacks and security
Dns protocol design attacks and securityMichael Earls
 
Polyglot ClickHouse -- ClickHouse SF Meetup Sept 10
Polyglot ClickHouse -- ClickHouse SF Meetup Sept 10Polyglot ClickHouse -- ClickHouse SF Meetup Sept 10
Polyglot ClickHouse -- ClickHouse SF Meetup Sept 10Altinity Ltd
 

Similar to Deep dive into CQL (20)

Sql analytic queries tips
Sql analytic queries tipsSql analytic queries tips
Sql analytic queries tips
 
Oracle to Cassandra Core Concepts Guide Pt. 2
Oracle to Cassandra Core Concepts Guide Pt. 2Oracle to Cassandra Core Concepts Guide Pt. 2
Oracle to Cassandra Core Concepts Guide Pt. 2
 
Dublin Meetup: Cassandra anti patterns
Dublin Meetup: Cassandra anti patternsDublin Meetup: Cassandra anti patterns
Dublin Meetup: Cassandra anti patterns
 
It Depends
It DependsIt Depends
It Depends
 
Paul Dix [InfluxData] The Journey of InfluxDB | InfluxDays 2022
Paul Dix [InfluxData] The Journey of InfluxDB | InfluxDays 2022Paul Dix [InfluxData] The Journey of InfluxDB | InfluxDays 2022
Paul Dix [InfluxData] The Journey of InfluxDB | InfluxDays 2022
 
Introduction to Dating Modeling for Cassandra
Introduction to Dating Modeling for CassandraIntroduction to Dating Modeling for Cassandra
Introduction to Dating Modeling for Cassandra
 
It Depends - Database admin for developers - Rev 20151205
It Depends - Database admin for developers - Rev 20151205It Depends - Database admin for developers - Rev 20151205
It Depends - Database admin for developers - Rev 20151205
 
Sql
SqlSql
Sql
 
PHP tips by a MYSQL DBA
PHP tips by a MYSQL DBAPHP tips by a MYSQL DBA
PHP tips by a MYSQL DBA
 
Cassandra - lesson learned
Cassandra  - lesson learnedCassandra  - lesson learned
Cassandra - lesson learned
 
User Defined Partitioning on PlazmaDB
User Defined Partitioning on PlazmaDBUser Defined Partitioning on PlazmaDB
User Defined Partitioning on PlazmaDB
 
Sqlxml vs xquery
Sqlxml vs xquerySqlxml vs xquery
Sqlxml vs xquery
 
Cassandra lesson learned - extended
Cassandra   lesson learned  - extendedCassandra   lesson learned  - extended
Cassandra lesson learned - extended
 
Redis for your boss
Redis for your bossRedis for your boss
Redis for your boss
 
MySQL Database System Hiep Dinh
MySQL Database System Hiep DinhMySQL Database System Hiep Dinh
MySQL Database System Hiep Dinh
 
mysqlHiep.ppt
mysqlHiep.pptmysqlHiep.ppt
mysqlHiep.ppt
 
Store and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and CassandraStore and Process Big Data with Hadoop and Cassandra
Store and Process Big Data with Hadoop and Cassandra
 
Introduction to Data Modeling with Apache Cassandra
Introduction to Data Modeling with Apache CassandraIntroduction to Data Modeling with Apache Cassandra
Introduction to Data Modeling with Apache Cassandra
 
Dns protocol design attacks and security
Dns protocol design attacks and securityDns protocol design attacks and security
Dns protocol design attacks and security
 
Polyglot ClickHouse -- ClickHouse SF Meetup Sept 10
Polyglot ClickHouse -- ClickHouse SF Meetup Sept 10Polyglot ClickHouse -- ClickHouse SF Meetup Sept 10
Polyglot ClickHouse -- ClickHouse SF Meetup Sept 10
 

Recently uploaded

Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 

Recently uploaded (20)

Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 

Deep dive into CQL

  • 1. ©2014 DataStax Confidential. Do not distribute without consent. @rstml Rustam Aliyev Solution Architect Deep dive into CQL andCQLimprovementsinCassandra2.1 1
  • 2. What is CQL? * Cassandra Query Language (CQL) * SQL-like language for communicating with Cassandra * Simpler than the Thrift API * An abstraction layer that hides implementation details This is what we want to understand
  • 3. Use Case * Messaging Application * Group Conversations * Attachments
  • 4. Simple CQL Table CREATE TABLE messages ( conversation_id uuid, message_id timeuuid, content text, sender text, PRIMARY KEY (conversation_id, message_id) );
  • 5. TimeUUID * Also known as a Version 1 UUID * Sortable Timestamp to Microsecond + UUID = TimeUUID 04d580b0-9412-11e3-baa8-0800200c9a66 12 February 2014 13:18:06 GMT http://www.famkruithof.net/uuid/uuidgen" =
  • 6. Primary Key CREATE TABLE messages ( conversation_id uuid, message_id timeuuid, content text, sender uuid, PRIMARY KEY (conversation_id, message_id) ); Partition Key Clustering Column * Also Primary Index
  • 7. Partition Key conversation_id: 04d580b0-9412-…9a66 Replica * Determines partition (and replicas) * Remaining columns are stored on the determined partition RF=3
  • 8. Clustering Column Merged, Sorted and Stored Sequentially 04d580b0-9412-…9a66 2013-04-03 07:01:00 content: Hi! sender: ali@example.tr 2013-04-03 07:03:20 content: Hello! Sender: tom@example… 2013-04-03 07:04:52 content: Where are you? sender: ali@example.tr 2013-04-03 07:05:01 content: in Istanbul sender: tom@example… 2013-04-03 07:06:32 content: wow! how come sender: ali@example.tr * Data on disk is ordered based on Clustering Column * Efficient retrieval with range queries (slice) SELECT * FROM messages WHERE conversation_id = '04d580b0-9412-…9a66' AND message_id > minTimeuuid('2013-04-03 07:04:00') AND message_id < maxTimeuuid('2013-04-03 07:10:00');
  • 9. Data on Disk Partition Key (Row Key) Column Name 1 Column Value 1 Column Name 2 Column Value 2 Column Name 3 Column Value 3 ... Column Name N Column Value N
  • 10. Data on Disk 04d580b0-9412-3a00-93d1-46196ee79a66 dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f: dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:content Hi! dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:sender ali@example.tr 2f3feb0f-9c24-11e2-7f7f-7f7f7f7f7f7f: 2f3feb0f-9c24-11e2-7f7f-7f7f7f7f7f7f:content Hello! 2f3feb0f-9c24-11e2-7f7f-7f7f7f7f7f7f:sender tom@example.com ... Clustering Column (message_id) Column Name Column Value Partition Key (conversation_id)  INSERT  INTO  messages  (conversation_id,  message_id,  content,  sender)  VALUES      (04d580b0-­‐9412-­‐3a00-­‐93d1-­‐46196ee79a66,  2f3feb0f-­‐9c24-­‐11e2-­‐7f7f-­‐7f7f7f7f7f7f,          'Hello!',  'tom@example.com');  
  • 11. Order of Clustering Keys CREATE TABLE messages ( conversation_id uuid, message_id timeuuid, content text, sender text, PRIMARY KEY (conversation_id, message_id) ) WITH CLUSTERING ORDER BY (message_id DESC); * We need only most recent N messages * Storing messages in reverse TimeUUID order will speedup queries
  • 12. Static Columns CREATE TABLE messages ( conversation_id uuid, conversation_owner text STATIC, message_id timeuuid, content text, sender text, PRIMARY KEY (conversation_id, message_id) ); * Let’s add conversation owner (admin) * Owner is related to conversation (Partition Key) not message (Clustering Key)
  • 13. Static Columns UPDATE messages SET conversation_owner = 'ali@example.tr' WHERE conversation_id = 04d580b0-9412-3a00-93d1-46196ee79a66; * Same UPDATE with non-static field will fail
  • 14. Static Columns on Disk 04d580b0-9412-3a00-93d1-46196ee79a66 :null:conversation_owner ali@example.tr dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f: dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:content Hi! dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:sender ali@example.tr 2f3feb0f-9c24-11e2-7f7f-7f7f7f7f7f7f: 2f3feb0f-9c24-11e2-7f7f-7f7f7f7f7f7f:content Hello! 2f3feb0f-9c24-11e2-7f7f-7f7f7f7f7f7f:sender tom@example.com ... Static Column
  • 15. Collections: Set CREATE TABLE messages ( conversation_id uuid, conversation_owner text STATIC, message_id timeuuid, content text, sender text, recipients set<text>, PRIMARY KEY (conversation_id, message_id) ); * We want to keep message recipients * List of recipients may vary as people join and leave conversation
  • 16. Collections: Set UPDATE messages SET recipients = {'ali@example.tr', 'tom@example.com'} WHERE conversation_id = 04d580b0-9412-3a00-93d1-46196ee79a66 AND message_id = dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f;
  • 17. Set on Disk 04d580b0-9412-3a00-93d1-46196ee79a66 :null:conversation_owner ali@example.tr dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f: dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:content Hi! dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:sender ali@example.tr dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:recipient:ali@example.tr dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:recipient:tom@example.com 2f3feb0f-9c24-11e2-7f7f-7f7f7f7f7f7f: ... Set
  • 18. Collections: Map CREATE TABLE messages ( conversation_id uuid, conversation_owner text STATIC, message_id timeuuid, content text, sender text, recipients set<text>, attachments map<text,text>, PRIMARY KEY (conversation_id, message_id) ); * Let’s add attachments to message * Each attachment would have name and location (URI)
  • 19. Collections: Map UPDATE messages SET attachments = {'picture.png':'http://cdn.exmpl.com/1234.png', 'audio.wav':'http://cdn.exmpl.com/5678.wav'} WHERE conversation_id = 04d580b0-9412-3a00-93d1-46196ee79a66 AND message_id = dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f;
  • 20. Map on Disk 04d580b0-9412-3a00-93d1-46196ee79a66 :null:conversation_owner ali@example.tr dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f: dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:content Hi! dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:sender ali@example.tr dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:recipient:ali@example.tr dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:recipient:tom@example.com dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:attachments:picture.png http://cdn.exmpl.com/1234.png dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:attachments:audio.wav http://cdn.exmpl.com/5678.wav 2f3feb0f-9c24-11e2-7f7f-7f7f7f7f7f7f: ... Map Name Key Value
  • 21. Collections: List CREATE TABLE messages ( conversation_id uuid, conversation_owner text STATIC, message_id timeuuid, content text, sender text, recipients set<text>, attachments map<text,text>, seen_by list<text>, PRIMARY KEY (conversation_id, message_id) ); * We want to know which participants have seen message and preserve order
  • 22. Collections: List UPDATE messages SET seen_by = ['adam@example.tr', 'tom@example.com'] WHERE conversation_id = 04d580b0-9412-3a00-93d1-46196ee79a66 AND message_id = dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f;
  • 23. List on Disk 04d580b0-9412-3a00-93d1-46196ee79a66 :null:conversation_owner ali@example.tr dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f: dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:content Hi! dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:sender ali@example.tr dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:recipient:ali@example.tr dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:recipient:tom@example.com dbcd9d0f-...-7f7f-7f7f7f7f7f7f:seen_by:26017c10-f487-11e2-801f-df9895e5d0f8 adam@example.tr dbcd9d0f-...-7f7f-7f7f7f7f7f7f:seen_by:26017c11-f487-11e2-801f-df9895e5d0f8 tom@example.com 2f3feb0f-9c24-11e2-7f7f-7f7f7f7f7f7f: ... List Name Element ID (TimeUUID) Value
  • 24. User Defined Types (UDT) CREATE TABLE messages ( conversation_id uuid, conversation_owner text STATIC, message_id timeuuid, content text, sender text, recipients set<text>, seen_by list<text>, attachments map<text,attachment>, PRIMARY KEY (conversation_id, message_id) ); * New in Cassandra 2.1 * Let’s add more attributes to attachments CREATE TYPE attachment ( size int, mime text, uri text );
  • 25. User Defined Types UPDATE messages SET attachments = attachments + { 'picture.png': { size: 10240, mime: 'image/png', uri: 'http://cdn.exmpl.com/1234.png' }} WHERE conversation_id = 04d580b0-9412-3a00-93d1-46196ee79a66 AND message_id = dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f;
  • 26. UDT on Disk 04d580b0-9412-3a00-93d1-46196ee79a66 :null:conversation_owner ali@example.tr dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f: dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:content Hi! dbcd9d0f-9c23-11e2-7f7f-7f7f7f7f7f7f:sender ali@example.tr dbcd9d0f-...-7f7f7f7f7f7f:recipient:ali@example.tr dbcd9d0f-...-7f7f7f7f7f7f:recipient:tom@example.com dbcd9d0f-...-7f7f7f7f7f7f:attachments:picture.png 10240:'image/png':'http://cdn.exmpl.com/ 1234.png' 2f3feb0f-9c24-11e2-7f7f-7f7f7f7f7f7f: ... Map Key UDT Value
  • 27. Secondary Indexes CREATE TABLE messages ( conversation_id uuid, conversation_owner text STATIC, message_id timeuuid, content text, sender text, recipients set<text>, seen_by list<text>, attachments map<text,text>, PRIMARY KEY (conversation_id, message_id) ); * What if we want to lookup messages by sender? CREATE INDEX sender_idx ON messages(sender); "
  • 29. Secondary Indexes Internally sender_idx { "ali@example.tr" { 54bbfd0f-9c02-11e2-7f7f-7f7f7f7f7f7f : null, df04610f-9c02-11e2-7f7f-7f7f7f7f7f7f : null }, "tom@exmaple.com" { a82e4b0f-9c02-11e2-7f7f-7f7f7f7f7f7f : null } } * Each node will keep reverse index for local data only
  • 30. Indexes on Collections CREATE TABLE messages ( conversation_id uuid, conversation_owner text STATIC, message_id timeuuid, content text, sender text, recipients set<text>, seen_by list<text>, attachments map<text,text>, PRIMARY KEY (conversation_id, message_id) ); * New in Cassandra 2.1 CREATE INDEX recipients_idx ON messages(recipients); "
  • 32. Way more information • 5 minute interviews • Use cases • Free training! www.planetcassandra.org