SlideShare ist ein Scribd-Unternehmen logo
1 von 75
Downloaden Sie, um offline zu lesen
The CQL3/Cassandra 
Mapping 
John Berryman 
OpenSource Connections 
OpenSource Connections
Outline 
• What Problem does CQL Solve? 
• The Cassandra Data Model 
• Pain Points of “Old” Cassandra 
• Introducing CQL 
• Understanding the CQL/Cassandra Mapping 
• CQL for Sets, Lists, and Maps 
• Putting it All Together 
OpenSource Connections
What Problem does CQL Solve? 
• The Awesomeness that is Cassandra: 
o Distributed columnar data store 
o No single point of failure 
o Optimized for availability (though “Tunably” consistent) 
o Optimized for writes 
o Easily maintainable 
o Almost infinitely scalable 
. 
OpenSource Connections
What Problem does CQL Solve? 
• The Awesomeness that is Cassandra: 
o Distributed columnar data store 
o No single point of failure 
o Optimized for availability (though “Tunably” consistent) 
o Optimized for writes 
o Easily maintainable 
o Almost infinitely scalable 
• Cassandra’s usability challenges 
o NoSQL – “Where are my JOINS? No Schema? De-normalize!?” 
o BigTable – “Tables with millions of columns!?” 
. 
OpenSource Connections
What Problem does CQL Solve? 
• The Awesomeness that is Cassandra: 
o Distributed columnar data store 
o No single point of failure 
o Optimized for availability (though “Tunably” consistent) 
o Optimized for writes 
o Easily maintainable 
o Almost infinitely scalable 
• Cassandra’s usability challenges 
o NoSQL – “Where are my JOINS? No Schema? De-normalize!?” 
o BigTable – “Tables with millions of columns!?” 
• CQL saves the day! 
o A best-practices interface to Cassandra 
o Uses familiar SQL-like language 
OpenSource Connections
C* Data Model 
OpenSource Connections 
Keyspace
C* Data Model 
Keyspace 
Column Family Column Family 
OpenSource Connections
C* Data Model 
Keyspace 
Column Family Column Family 
OpenSource Connections
C* Data Model 
Keyspace 
Column Family Column Family 
OpenSource Connections
C* Data Model 
OpenSource Connections 
Row Key
C* Data Model 
OpenSource Connections 
Row Key 
Column 
Column Name 
Column Value 
(or Tombstone) 
Timestamp 
Time-to-live
C* Data Model 
● Row Key, Column Name, Column 
OpenSource Connections 
Value have types 
● Column Name has comparator 
● RowKey has partitioner 
● Rows can have any number of 
columns - even in same column family 
● Rows can have many columns 
● Column Values can be omitted 
● Time-to-live is useful! 
● Tombstones 
Row Key 
Column 
Column Name 
Column Value 
(or Tombstone) 
Timestamp 
Time-to-live
C* Data Model: Writes 
SSTable 
SSTable 
SSTable 
OpenSource Connections 
Mem 
Table 
CommitLog 
Row 
Cache 
● Insert into 
MemTable 
● Dump to 
CommitLog 
● No read 
● Very Fast! 
● Blocks on CPU 
before O/I! 
Key 
Cache 
SSTable 
Key 
Cache 
Key 
Cache 
Key 
Cache 
Bloom 
Filter
C* Data Model: Writes 
SSTable 
SSTable 
SSTable 
OpenSource Connections 
Mem 
Table 
CommitLog 
Row 
Cache 
● Insert into 
MemTable 
● Dump to 
CommitLog 
● No read 
● Very Fast! 
● Blocks on CPU 
before O/I! 
Key 
Cache 
SSTable 
Key 
Cache 
Key 
Cache 
Key 
Cache 
Bloom 
Filter
C* Data Model: Writes 
SSTable 
SSTable 
SSTable 
OpenSource Connections 
Mem 
Table 
CommitLog 
Row 
Cache 
● Insert into 
MemTable 
● Dump to 
CommitLog 
● No read 
● Very Fast! 
● Blocks on CPU 
before O/I! 
Key 
Cache 
SSTable 
Key 
Cache 
Key 
Cache 
Key 
Cache 
Bloom 
Filter
SSTable 
SSTable 
SSTable 
OpenSource Connections 
Mem 
Table 
CommitLog 
Row 
Cache 
Key 
Cache 
SSTable 
Key 
Cache 
Key 
Cache 
Key 
Cache 
Bloom 
Filter 
● Get values from Memtable 
● Get values from row 
cache if present 
● Otherwise check bloom 
filter to find appropriate 
SSTables 
● Check Key Cache for fast 
SSTable Search 
● Get values from SSTables 
● Repopulate Row Cache 
● Super Fast Col. retrieval 
● Fast row slicing 
C* Data Model: 
Reads
SSTable 
SSTable 
SSTable 
OpenSource Connections 
Mem 
Table 
CommitLog 
Row 
Cache 
Key 
Cache 
SSTable 
Key 
Cache 
Key 
Cache 
Key 
Cache 
Bloom 
Filter 
● Get values from Memtable 
● Get values from row 
cache if present 
● Otherwise check bloom 
filter to find appropriate 
SSTables 
● Check Key Cache for fast 
SSTable Search 
● Get values from SSTables 
● Repopulate Row Cache 
● Super Fast Col. retrieval 
● Fast row slicing 
C* Data Model: 
Reads
SSTable 
SSTable 
SSTable 
OpenSource Connections 
Mem 
Table 
CommitLog 
Row 
Cache 
Key 
Cache 
SSTable 
Key 
Cache 
Key 
Cache 
Key 
Cache 
Bloom 
Filter 
● Get values from Memtable 
● Get values from row 
cache if present 
● Otherwise check bloom 
filter to find appropriate 
SSTables 
● Check Key Cache for fast 
SSTable Search 
● Get values from SSTables 
● Repopulate Row Cache 
● Super Fast Col. retrieval 
● Fast row slicing 
C* Data Model: 
Reads
SSTable 
SSTable 
SSTable 
OpenSource Connections 
Mem 
Table 
CommitLog 
Row 
Cache 
Key 
Cache 
SSTable 
Key 
Cache 
Key 
Cache 
Key 
Cache 
Bloom 
Filter 
● Get values from Memtable 
● Get values from row 
cache if present 
● Otherwise check bloom 
filter to find appropriate 
SSTables 
● Check Key Cache for fast 
SSTable Search 
● Get values from SSTables 
● Repopulate Row Cache 
● Super Fast Col. retrieval 
● Fast row slicing 
C* Data Model: 
Reads
SSTable 
SSTable 
SSTable 
OpenSource Connections 
Mem 
Table 
CommitLog 
Row 
Cache 
Key 
Cache 
SSTable 
Key 
Cache 
Key 
Cache 
Key 
Cache 
Bloom 
Filter 
● Get values from Memtable 
● Get values from row 
cache if present 
● Otherwise check bloom 
filter to find appropriate 
SSTables 
● Check Key Cache for fast 
SSTable Search 
● Get values from SSTables 
● Repopulate Row Cache 
● Super Fast Col. retrieval 
● Fast row slicing 
C* Data Model: 
Reads
SSTable 
SSTable 
SSTable 
OpenSource Connections 
Mem 
Table 
CommitLog 
Row 
Cache 
Key 
Cache 
SSTable 
Key 
Cache 
Key 
Cache 
Key 
Cache 
Bloom 
Filter 
● Get values from Memtable 
● Get values from row 
cache if present 
● Otherwise check bloom 
filter to find appropriate 
SSTables 
● Check Key Cache for fast 
SSTable Search 
● Get values from SSTables 
● Repopulate Row Cache 
● Super Fast Col. retrieval 
● Fast row slicing 
C* Data Model: 
Reads
Cassandra Pain Points 
• Twitter Example 
• My tweets 
o SET tweets[JnBrymn][2013-07-19 T 09:20] = 
“Wonderful morning. This coffee is great.”! 
o SET tweets[JnBrymn][2013-07-19 T 09:21] = 
“Oops, smoke is coming out of the SQL server!”! 
o SET tweets[JnBrymn][2013-07-19 T 09:51] = “Now 
my coffee is cold :-(” 
• Get John’s tweets 
o GET tweets[JnBrymn] (output is as expected) 
OpenSource Connections
Cassandra Pain Points 
• Twitter Example 
• My tweets 
o SET tweets[JnBrymn][2013-07-19 T 09:20] = 
“Wonderful morning. This coffee is great.”! 
o SET tweets[JnBrymn][2013-07-19 T 09:21] = 
“Oops, smoke is coming out of the SQL server!”! 
o SET tweets[JnBrymn][2013-07-19 T 09:51] = “Now 
my coffee is cold :-(” 
• Get John’s tweets 
o GET tweets[JnBrymn] (output is as expected) 
• Pain-point: schema-less means that you have to 
read code to understand data model 
OpenSource Connections
Cassandra Pain Points 
• My timeline (other’s tweets) 
• More complicated – must store corresponding user 
names 
• Bad Option 1: keep multiple column families 
o SET timeline_from[JnBrymn][2013-07-19 T 09:20] 
= “softwaredoug”! 
o SET timeline_text[JnBrymn][2013-07-19 T 09:20] 
= “Hey John I posted on reddit, upvote me!” 
• Get John’s timeline 
o GET timeline_from[JnBrymn]! 
o GET timeline_text[JnBrymn]! 
OpenSource Connections
Cassandra Pain Points 
• My timeline (other’s tweets) 
• More complicated – must store corresponding user 
names 
• Bad Option 1: keep multiple column families 
o SET timeline_from[JnBrymn][2013-07-19 T 09:20] 
= “softwaredoug”! 
o SET timeline_text[JnBrymn][2013-07-19 T 09:20] 
= “Hey John I posted on reddit, upvote me!” 
• Get John’s timeline 
o GET timeline_from[JnBrymn]! 
o GET timeline_text[JnBrymn]! 
• Pain-point: Multiple queries required. 
OpenSource Connections
Cassandra Pain Points 
• My timeline 
• Bad Option 2: shove into single column value 
o SET timeline[JnBrymn][2013-07-19 T 09:20] = 
{from:”softwaredoug”, text: “Hey John I posted 
on reddit, upvote me!” 
• Get John’s timeline 
o GET timeline[JnBrymn] (…not too bad.)! 
OpenSource Connections
Cassandra Pain Points 
• My timeline 
• Bad Option 2: shove into single column value 
o SET timeline[JnBrymn][2013-07-19 T 09:20] = 
{from:”softwaredoug”, text: “Hey John I posted 
on reddit, upvote me!” 
• Get John’s timeline 
o GET timeline[JnBrymn] (…not too bad.)! 
• Pain-point: Updates require a read-then-modify 
OpenSource Connections
Cassandra Pain Points 
• My timeline 
• Best Option: composite column names 
o SET timeline[JnBrymn][2013-07-19 T 09:20|from] 
= ”softwaredoug”! 
o SET timeline[JnBrymn][2013-07-19 T 09:20|text] 
= “Hey John, I posted on reddit, upvote me!” 
• Get John’s timeline 
o GET timeline[JnBrymn] (extract from and text in client) 
• Resolves prior pain points! Scales well!! 
OpenSource Connections
Cassandra Pain Points 
• My timeline 
• Best Option: composite column names 
o SET timeline[JnBrymn][2013-07-19 T 09:20|from] 
= ”softwaredoug”! 
o SET timeline[JnBrymn][2013-07-19 T 09:20|text] 
= “Hey John, I posted on reddit, upvote me!” 
• Get John’s timeline 
o GET timeline[JnBrymn] (extract from and text in client) 
• Resolves prior pain points! Scales well!! 
• Pain-point: Even more code reading to understand 
data model! 
OpenSource Connections
Cassandra Pain Points 
• Justin Bieber’s timeline (e.g. many tweets) 
• Previous solution fails if number of columns > 2Billion 
• Best Option: composite row names 
o SET timeline[bieber|2013-07][19 T 09:20|from] = 
”softwaredoug”! 
o SET timeline[bieber|2013-07][19 T 09:20|text] = 
“Justin Bieber, you complete me.” 
• Get Justin’s timeline 
o GET timeline[bieber|2013-07] (get other months too) 
OpenSource Connections
Cassandra Pain Points 
• Justin Bieber’s timeline (e.g. many tweets) 
• Previous solution fails if number of columns > 2Billion 
• Best Option: composite row names 
o SET timeline[bieber|2013-07][19 T 09:20|from] = 
”softwaredoug”! 
o SET timeline[bieber|2013-07][19 T 09:20|text] = 
“Justin Bieber, you complete me.” 
• Get Justin’s timeline 
o GET timeline[bieber|2013-07] (get other months too) 
• Pain-point: Even more code reading to understand 
data model! 
OpenSource Connections
Introducing CQL 
• CQL is a reintroduction of schema so that you don’t 
have to read code to understand the data model. 
• CQL creates a common language so that details of 
the data model can be easily communicated. 
• CQL is a best-practices Cassandra interface and 
hides the messy details. 
OpenSource Connections
Introducing CQL 
• CQL is a reintroduction of schema so that you don’t 
have to read code to understand the data model. 
• CQL creates a common language so that details of 
the data model can be easily communicated. 
• CQL is a best-practices Cassandra interface and 
hides the messy details. 
OpenSource Connections 
Let’s see it!
Introducing CQL 
CREATE TABLE users ( 
id timeuuid PRIMARY KEY,! 
lastname varchar,! 
firstname varchar,! 
dateOfBirth timestamp );! 
! 
! 
! 
OpenSource Connections
Introducing CQL 
CREATE TABLE users ( 
id timeuuid PRIMARY KEY,! 
lastname varchar,! 
firstname varchar,! 
dateOfBirth timestamp );! 
! 
INSERT INTO users (id,lastname, firstname, dateofbirth) 
VALUES (now(),'Berryman',’John','1975-09-15');! 
!! 
OpenSource Connections
Introducing CQL 
CREATE TABLE users ( 
id timeuuid PRIMARY KEY,! 
lastname varchar,! 
firstname varchar,! 
dateOfBirth timestamp );! 
! 
INSERT INTO users (id,lastname, firstname, dateofbirth) 
VALUES (now(),’Berryman’,’John’,’1975-09-15’);! 
! 
UPDATE users SET firstname = ’John’ 
WHERE id = f74c0b20-0862-11e3-8cf6-b74c10b01fc6;! 
! 
OpenSource Connections
Introducing CQL 
CREATE TABLE users ( 
id timeuuid PRIMARY KEY,! 
lastname varchar,! 
firstname varchar,! 
dateOfBirth timestamp );! 
! 
INSERT INTO users (id,lastname, firstname, dateofbirth) 
VALUES (now(),'Berryman',’John','1975-09-15');! 
! 
UPDATE users SET firstname = 'John’ 
WHERE id = f74c0b20-0862-11e3-8cf6-b74c10b01fc6;! 
! 
SELECT dateofbirth,firstname,lastname FROM users ;! 
! 
dateofbirth | firstname | lastname! 
--------------------------+-----------+----------! 
1975-09-15 00:00:00-0400 | John | Berryman! 
OpenSource Connections
Introducing CQL 
“Hey sweet! It’s exactly the same as MySQL!” 
OpenSource Connections
Introducing CQL 
“Hey sweet! It’s exactly the same as MySQL!” 
Hold your horses. There are some 
important differences. 
OpenSource Connections
Introducing CQL 
“Hey sweet! It’s exactly the same as MySQL!” 
Hold your horses. There are some 
important differences. 
“Wait? What happened to the 
Cassandra’s wide rows?” 
OpenSource Connections
Introducing CQL 
“Hey sweet! It’s exactly the same as MySQL!” 
Hold your horses. There are some 
important differences. 
“Wait? What happened to the 
Cassandra’s wide rows?” 
There’s still there. Understanding 
the mapping is crucial! 
OpenSource Connections
Introducing CQL 
“Hey sweet! It’s exactly the same as MySQL!” 
Hold your horses. There are some 
important differences. 
“Wait? What happened to the 
Cassandra’s wide rows?” 
There’s still there. Understanding 
the mapping is crucial! 
OpenSource Connections 
Remember this: 
• Cassandra finds rows fast 
• Cassandra scans columns fast 
• Cassandra does not scan rows
The CQL/Cassandra Mapping 
CREATE TABLE employees (! 
name text PRIMARY KEY,! 
age int,! 
role text! 
);! 
! 
OpenSource Connections
The CQL/Cassandra Mapping 
CREATE TABLE employees (! 
name text PRIMARY KEY,! 
age int,! 
role text! 
);! 
! 
name | age | role! 
-----+-----+-----! 
john | 37 | dev! 
eric | 38 | ceo! 
! 
OpenSource Connections
The CQL/Cassandra Mapping 
CREATE TABLE employees (! 
name text PRIMARY KEY,! 
age int,! 
role text! 
);! 
! 
name | age | role! 
-----+-----+-----! 
john | 37 | dev! 
eric | 38 | ceo! 
! 
OpenSource Connections 
age! role! 
john! 37! dev! 
age! role! 
eric! 38! ceo!
The CQL/Cassandra Mapping 
CREATE TABLE employees (! 
company text,! 
name text,! 
age int,! 
role text,! 
PRIMARY KEY (company,name)! 
);! 
! 
OpenSource Connections
The CQL/Cassandra Mapping 
CREATE TABLE employees (! 
company text,! 
name text,! 
age int,! 
role text,! 
PRIMARY KEY (company,name)! 
);! 
! 
company | name | age | role! 
--------+------+-----+-----! 
OSC | eric | 38 | ceo! 
OSC | john | 37 | dev! 
RKG | anya | 29 | lead! 
RKG | ben | 27 | dev! 
RKG | chad | 35 | ops! 
OpenSource Connections
The CQL/Cassandra Mapping 
CREATE TABLE employees (! 
company text,! 
name text,! 
age int,! 
role text,! 
PRIMARY KEY (company,name)! 
);! 
! 
company | name | age | role! 
--------+------+-----+-----! 
OSC | eric | 38 | ceo! 
OSC | john | 37 | dev! 
RKG | anya | 29 | lead! 
RKG | ben | 27 | dev! 
RKG | chad | 35 | ops! 
! eric:age! eric:role! john:age! john:role! 
OSC! 38! dev! 37! dev! 
anya:age! anya:role! ben:age! ben:role! chad:age! chad:role! 
RKG! 29! lead! 27! dev! 35! ops! 
OpenSource Connections
The CQL/Cassandra Mapping 
CREATE TABLE example (! 
A text,! 
B text,! 
C text,! 
D text,! 
E text,! 
F text,! 
PRIMARY KEY ((A,B),C,D)! 
);! 
OpenSource Connections
The CQL/Cassandra Mapping 
CREATE TABLE example (! 
A text,! 
B text,! 
C text,! 
D text,! 
E text,! 
F text,! 
PRIMARY KEY ((A,B),C,D)! 
);! 
A | B | C | D | E | F ! 
--+---+---+---+---+---! 
a | b | c | d | e | f! 
a | b | c | g | h | i! 
a | b | j | k | l | m! 
a | n | o | p | q | r! 
s | t | u | v | w | x! 
OpenSource Connections
The CQL/Cassandra Mapping 
CREATE TABLE example (! 
A text,! 
B text,! 
C text,! 
D text,! 
E text,! 
F text,! 
PRIMARY KEY ((A,B),C,D)! 
);! 
A | B | C | D | E | F ! 
--+---+---+---+---+---! 
a | b | c | d | e | f! 
a | b | c | g | h | i! 
a | b | j | k | l | m! 
a | n | o | p | q | r! 
s | t | u | v | w | x! 
! c:d:E! c:d:F! c:g:E! c:g:F! j:k:E! j:k:F! 
a:b! e! f! h! i! l! m! 
OpenSource Connections 
! o:p:E! o:p:F! 
a:n! q! r! 
! u:v:E! u:v:F! 
s:t! w! x!
CQL for Sets, Lists, and Maps 
• Collection Semantics 
o Sets hold list of unique elements 
o Lists hold ordered, possibly repeating elements 
o Maps hold a list of key-value pairs 
• Uses same old Cassandra data structure 
OpenSource Connections
CQL for Sets, Lists, and Maps 
• Collection Semantics 
o Sets hold list of unique elements 
o Lists hold ordered, possibly repeating elements 
o Maps hold a list of key-value pairs 
• Uses same old Cassandra data structure 
• Declaring 
OpenSource Connections 
CREATE TABLE mytable(! 
X text,! 
Y text,! 
myset set<text>,! 
mylist list<int>,! 
mymap map<text, text>,! 
PRIMARY KEY (X,Y)! 
);!
CQL for Sets, Lists, and Maps 
• Collection Semantics 
o Sets hold list of unique elements 
o Lists hold ordered, possibly repeating elements 
o Maps hold a list of key-value pairs 
• Uses same old Cassandra data structure 
• Declaring 
OpenSource Connections 
CREATE TABLE mytable(! 
X text,! 
Y text,! 
myset set<text>,! 
mylist list<int>,! 
mymap map<text, text>,! 
PRIMARY KEY (X,Y)! 
);! 
Collection fields 
can not be used 
in primary keys
CQL for Sets, Lists, and Maps 
• Inserting 
! 
INSERT INTO mytable (row, myset) 
VALUES (123, { ‘apple’, ‘banana’}); 
OpenSource Connections
CQL for Sets, Lists, and Maps 
• Inserting 
! 
INSERT INTO mytable (row, myset) 
VALUES (123, { ‘apple’, ‘banana’}); 
INSERT INTO mytable (row, mylist) 
VALUES (123, [‘apple’,’banana’,’apple’]); 
OpenSource Connections
CQL for Sets, Lists, and Maps 
• Inserting 
! 
INSERT INTO mytable (row, myset) 
VALUES (123, { ‘apple’, ‘banana’}); 
INSERT INTO mytable (row, mylist) 
VALUES (123, [‘apple’,’banana’,’apple’]); 
INSERT INTO mytable (row, mymap) 
VALUES (123, {1:’apple’,2:’banana’}) 
OpenSource Connections
CQL for Sets, Lists, and Maps 
• Updating 
UPDATE mytable SET myset = myset + {‘apple’,‘banana’} 
WHERE row = 123; 
UPDATE mytable SET myset = myset - { ‘apple’ } 
WHERE row = 123;! 
OpenSource Connections
CQL for Sets, Lists, and Maps 
• Updating 
UPDATE mytable SET myset = myset + {‘apple’,‘banana’} 
WHERE row = 123; 
UPDATE mytable SET myset = myset - { ‘apple’ } 
WHERE row = 123;! 
UPDATE mytable SET mylist = mylist + [‘apple’,‘banana’] 
WHERE row = 123; 
UPDATE mytable SET mylist = [‘banana’] + mylist 
WHERE row = 123;! 
OpenSource Connections
CQL for Sets, Lists, and Maps 
• Updating 
UPDATE mytable SET myset = myset + {‘apple’,‘banana’} 
WHERE row = 123; 
UPDATE mytable SET myset = myset - { ‘apple’ } 
WHERE row = 123;! 
UPDATE mytable SET mylist = mylist + [‘apple’,‘banana’] 
WHERE row = 123; 
UPDATE mytable SET mylist = [‘banana’] + mylist 
WHERE row = 123;! 
UPDATE mytable SET mymap[‘fruit’] = ‘apple’ 
WHERE row = 123 
UPDATE mytable SET mymap = mymap + { ‘fruit’:‘apple’} 
WHERE row = 123! 
OpenSource Connections
CQL for Sets, Lists, and Maps 
SETS 
! 
CREATE TABLE mytable(! 
X text,! 
Y text,! 
myset set<int>,! 
PRIMARY KEY (X,Y)! 
);! 
! 
OpenSource Connections
CQL for Sets, Lists, and Maps 
SETS 
! 
CREATE TABLE mytable(! 
X text,! 
Y text,! 
myset set<int>,! 
PRIMARY KEY (X,Y)! 
);! 
! 
X | Y | myset ! 
---+---+------------! 
a | b | {1,2}! 
a | c | {3,4,5}! 
OpenSource Connections
CQL for Sets, Lists, and Maps 
SETS 
! 
CREATE TABLE mytable(! 
X text,! 
Y text,! 
myset set<int>,! 
PRIMARY KEY (X,Y)! 
);! 
! 
X | Y | myset ! 
---+---+------------! 
a | b | {1,2}! 
a | c | {3,4,5}! 
! b:myset:1! b:myset:2! c:myset:3! c:myset:4! c:myset:5! 
a! 
OpenSource Connections
CQL for Sets, Lists, and Maps 
OpenSource Connections 
LISTS 
! 
CREATE TABLE mytable(! 
X text,! 
Y text,! 
mylist list<int>,! 
PRIMARY KEY (X,Y)! 
);! 
!
CQL for Sets, Lists, and Maps 
X | Y | mylist ! 
---+---+------------! 
a | b | [1,2]! 
OpenSource Connections 
LISTS 
! 
CREATE TABLE mytable(! 
X text,! 
Y text,! 
mylist list<int>,! 
PRIMARY KEY (X,Y)! 
);! 
!
CQL for Sets, Lists, and Maps 
X | Y | mylist ! 
---+---+------------! 
a | b | [1,2]! 
! b:mylist:f7e5450039..8d! b:mylist:f7e5450139..8d! 
a! 1! 2! 
OpenSource Connections 
LISTS 
! 
CREATE TABLE mytable(! 
X text,! 
Y text,! 
mylist list<int>,! 
PRIMARY KEY (X,Y)! 
);! 
!
CQL for Sets, Lists, and Maps 
X | Y | mylist ! 
---+---+------------! 
a | b | [1,2]! 
! b:mylist:f7e5450039..8d! b:mylist:f7e5450139..8d! 
a! 1! 2! 
OpenSource Connections 
LISTS 
! 
CREATE TABLE mytable(! 
X text,! 
Y text,! 
mylist list<int>,! 
PRIMARY KEY (X,Y)! 
);! 
!
CQL for Sets, Lists, and Maps 
MAPS 
! 
CREATE TABLE mytable(! 
X text,! 
Y text,! 
mymap map<text,int>,! 
PRIMARY KEY (X,Y)! 
);! 
! 
OpenSource Connections
CQL for Sets, Lists, and Maps 
MAPS 
! 
CREATE TABLE mytable(! 
X text,! 
Y text,! 
mymap map<text,int>,! 
PRIMARY KEY (X,Y)! 
);! 
! 
X | Y | mymap ! 
---+---+------------! 
a | b | {m:1,n:2}! 
a | c |{n:3,p:4,q:5}! 
OpenSource Connections
CQL for Sets, Lists, and Maps 
MAPS 
! 
CREATE TABLE mytable(! 
X text,! 
Y text,! 
mymap map<text,int>,! 
PRIMARY KEY (X,Y)! 
);! 
! 
X | Y | mymap ! 
---+---+------------! 
a | b | {m:1,n:2}! 
a | c |{n:3,p:4,q:5}! 
! b:mymap:m! b:mymap:n! c:mymap:n! c:mymap:p! c:mymap:q! 
a! 1! 2! 3! 4! 5! 
OpenSource Connections
Peek Behind the Scenes! Do it! 
(in cqlsh) 
CREATE KEYSPACE test WITH replication = ! 
{'class': 'SimpleStrategy', 'replication_factor': 1};! 
USE test;! 
CREATE TABLE stuff ( a int, b int, myset set<int>,! 
mylist list<int>, mymap map<int,int>, PRIMARY KEY (a,b));! 
UPDATE stuff SET myset = {1,2}, mylist = [3,4,5], mymap = 
{6:7,8:9} WHERE a = 0 AND b = 1;! 
SELECT * FROM stuff;! 
! 
(in cassandra-cli) 
use test;! 
list stuff ;! 
! 
(in cqlsh) 
SELECT key_aliases,column_aliases from 
system.schema_columnfamilies WHERE keyspace_name = 'test' AND 
columnfamily_name = 'stuff';! 
OpenSource Connections
Putting it All Together 
…you already know 
• CQL is a reintroduction of schema 
• CQL creates a common data modeling language 
• CQL is a best-practices Cassandra interface 
. 
OpenSource Connections
Putting it All Together 
…you already know 
• CQL is a reintroduction of schema 
• CQL creates a common data modeling language 
• CQL is a best-practices Cassandra interface 
…now you know 
• CQL let’s you take advantage of the C* Data structure 
. 
OpenSource Connections
Putting it All Together 
…you already know 
• CQL is a reintroduction of schema 
• CQL creates a common data modeling language 
• CQL is a best-practices Cassandra interface 
…now you know 
• CQL let’s you take advantage of the C* Data structure 
…but also 
• CQL protocol is binary and therefore interoperable with 
any language 
• CQL is asynchronous and fast (Thrift transport layer is 
synchronous) 
• CQL allows the possibility for prepared statements 
OpenSource Connections
Thanks! 
Follow me on Twitter @JnBrymn 
Check out the OpenSource Connection Blog 
http://www.opensourceconnections.com/blog/ 
OpenSource Connections

Weitere ähnliche Inhalte

Andere mochten auch

Introduction to Cassandra Basics
Introduction to Cassandra BasicsIntroduction to Cassandra Basics
Introduction to Cassandra Basicsnickmbailey
 
Cassandra By Example: Data Modelling with CQL3
Cassandra By Example: Data Modelling with CQL3Cassandra By Example: Data Modelling with CQL3
Cassandra By Example: Data Modelling with CQL3Eric Evans
 
Cassandra Explained
Cassandra ExplainedCassandra Explained
Cassandra ExplainedEric Evans
 
An Overview of Apache Cassandra
An Overview of Apache CassandraAn Overview of Apache Cassandra
An Overview of Apache CassandraDataStax
 
Cassandra Introduction & Features
Cassandra Introduction & FeaturesCassandra Introduction & Features
Cassandra Introduction & FeaturesDataStax Academy
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcachedJurriaan Persyn
 

Andere mochten auch (7)

Introduction to Cassandra Basics
Introduction to Cassandra BasicsIntroduction to Cassandra Basics
Introduction to Cassandra Basics
 
Cassandra By Example: Data Modelling with CQL3
Cassandra By Example: Data Modelling with CQL3Cassandra By Example: Data Modelling with CQL3
Cassandra By Example: Data Modelling with CQL3
 
Cassandra Explained
Cassandra ExplainedCassandra Explained
Cassandra Explained
 
An Overview of Apache Cassandra
An Overview of Apache CassandraAn Overview of Apache Cassandra
An Overview of Apache Cassandra
 
Cassandra Introduction & Features
Cassandra Introduction & FeaturesCassandra Introduction & Features
Cassandra Introduction & Features
 
Introduction to memcached
Introduction to memcachedIntroduction to memcached
Introduction to memcached
 
Cassandra NoSQL Tutorial
Cassandra NoSQL TutorialCassandra NoSQL Tutorial
Cassandra NoSQL Tutorial
 

Ähnlich wie Cassandra Summit 2014: Understanding CQL3 Inside and Out

Apache Cassandra Developer Training Slide Deck
Apache Cassandra Developer Training Slide DeckApache Cassandra Developer Training Slide Deck
Apache Cassandra Developer Training Slide DeckDataStax Academy
 
Cassandra Basics, Counters and Time Series Modeling
Cassandra Basics, Counters and Time Series ModelingCassandra Basics, Counters and Time Series Modeling
Cassandra Basics, Counters and Time Series ModelingVassilis Bekiaris
 
Cassandra: Open Source Bigtable + Dynamo
Cassandra: Open Source Bigtable + DynamoCassandra: Open Source Bigtable + Dynamo
Cassandra: Open Source Bigtable + Dynamojbellis
 
Deep Dive into Cassandra
Deep Dive into CassandraDeep Dive into Cassandra
Deep Dive into CassandraBrent Theisen
 
Managing Data and Operation Distribution In MongoDB
Managing Data and Operation Distribution In MongoDBManaging Data and Operation Distribution In MongoDB
Managing Data and Operation Distribution In MongoDBJason Terpko
 
MariaDB 10.3 Optimizer - where does it stand
MariaDB 10.3 Optimizer - where does it standMariaDB 10.3 Optimizer - where does it stand
MariaDB 10.3 Optimizer - where does it standSergey Petrunya
 
Managing data and operation distribution in MongoDB
Managing data and operation distribution in MongoDBManaging data and operation distribution in MongoDB
Managing data and operation distribution in MongoDBAntonios Giannopoulos
 
VSSML16 L5. Basic Data Transformations
VSSML16 L5. Basic Data TransformationsVSSML16 L5. Basic Data Transformations
VSSML16 L5. Basic Data TransformationsBigML, Inc
 
Deploying MLlib for Scoring in Structured Streaming with Joseph Bradley
Deploying MLlib for Scoring in Structured Streaming with Joseph BradleyDeploying MLlib for Scoring in Structured Streaming with Joseph Bradley
Deploying MLlib for Scoring in Structured Streaming with Joseph BradleyDatabricks
 
141115 dev opsdays_jso_ntosql
141115 dev opsdays_jso_ntosql141115 dev opsdays_jso_ntosql
141115 dev opsdays_jso_ntosqlChristopher Hogue
 
Delta: Building Merge on Read
Delta: Building Merge on ReadDelta: Building Merge on Read
Delta: Building Merge on ReadDatabricks
 
Cassandra
CassandraCassandra
Cassandrarobjk
 
NOSQL and Cassandra
NOSQL and CassandraNOSQL and Cassandra
NOSQL and Cassandrarantav
 
FP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit HoleFP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit HoleChristophe Grand
 
Spark and cassandra (Hulu Talk)
Spark and cassandra (Hulu Talk)Spark and cassandra (Hulu Talk)
Spark and cassandra (Hulu Talk)Jon Haddad
 
Cassandra introduction apache con 2014 budapest
Cassandra introduction apache con 2014 budapestCassandra introduction apache con 2014 budapest
Cassandra introduction apache con 2014 budapestDuyhai Doan
 
Low Level CPU Performance Profiling Examples
Low Level CPU Performance Profiling ExamplesLow Level CPU Performance Profiling Examples
Low Level CPU Performance Profiling ExamplesTanel Poder
 
Patterns of the Lambda Architecture -- 2015 April - Hadoop Summit, Europe
Patterns of the Lambda Architecture -- 2015 April - Hadoop Summit, EuropePatterns of the Lambda Architecture -- 2015 April - Hadoop Summit, Europe
Patterns of the Lambda Architecture -- 2015 April - Hadoop Summit, EuropeFlip Kromer
 

Ähnlich wie Cassandra Summit 2014: Understanding CQL3 Inside and Out (20)

Apache Cassandra Developer Training Slide Deck
Apache Cassandra Developer Training Slide DeckApache Cassandra Developer Training Slide Deck
Apache Cassandra Developer Training Slide Deck
 
Cassandra Basics, Counters and Time Series Modeling
Cassandra Basics, Counters and Time Series ModelingCassandra Basics, Counters and Time Series Modeling
Cassandra Basics, Counters and Time Series Modeling
 
Intro to Cassandra
Intro to CassandraIntro to Cassandra
Intro to Cassandra
 
Cassandra
CassandraCassandra
Cassandra
 
Cassandra: Open Source Bigtable + Dynamo
Cassandra: Open Source Bigtable + DynamoCassandra: Open Source Bigtable + Dynamo
Cassandra: Open Source Bigtable + Dynamo
 
Deep Dive into Cassandra
Deep Dive into CassandraDeep Dive into Cassandra
Deep Dive into Cassandra
 
Managing Data and Operation Distribution In MongoDB
Managing Data and Operation Distribution In MongoDBManaging Data and Operation Distribution In MongoDB
Managing Data and Operation Distribution In MongoDB
 
MariaDB 10.3 Optimizer - where does it stand
MariaDB 10.3 Optimizer - where does it standMariaDB 10.3 Optimizer - where does it stand
MariaDB 10.3 Optimizer - where does it stand
 
Managing data and operation distribution in MongoDB
Managing data and operation distribution in MongoDBManaging data and operation distribution in MongoDB
Managing data and operation distribution in MongoDB
 
VSSML16 L5. Basic Data Transformations
VSSML16 L5. Basic Data TransformationsVSSML16 L5. Basic Data Transformations
VSSML16 L5. Basic Data Transformations
 
Deploying MLlib for Scoring in Structured Streaming with Joseph Bradley
Deploying MLlib for Scoring in Structured Streaming with Joseph BradleyDeploying MLlib for Scoring in Structured Streaming with Joseph Bradley
Deploying MLlib for Scoring in Structured Streaming with Joseph Bradley
 
141115 dev opsdays_jso_ntosql
141115 dev opsdays_jso_ntosql141115 dev opsdays_jso_ntosql
141115 dev opsdays_jso_ntosql
 
Delta: Building Merge on Read
Delta: Building Merge on ReadDelta: Building Merge on Read
Delta: Building Merge on Read
 
Cassandra
CassandraCassandra
Cassandra
 
NOSQL and Cassandra
NOSQL and CassandraNOSQL and Cassandra
NOSQL and Cassandra
 
FP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit HoleFP Days: Down the Clojure Rabbit Hole
FP Days: Down the Clojure Rabbit Hole
 
Spark and cassandra (Hulu Talk)
Spark and cassandra (Hulu Talk)Spark and cassandra (Hulu Talk)
Spark and cassandra (Hulu Talk)
 
Cassandra introduction apache con 2014 budapest
Cassandra introduction apache con 2014 budapestCassandra introduction apache con 2014 budapest
Cassandra introduction apache con 2014 budapest
 
Low Level CPU Performance Profiling Examples
Low Level CPU Performance Profiling ExamplesLow Level CPU Performance Profiling Examples
Low Level CPU Performance Profiling Examples
 
Patterns of the Lambda Architecture -- 2015 April - Hadoop Summit, Europe
Patterns of the Lambda Architecture -- 2015 April - Hadoop Summit, EuropePatterns of the Lambda Architecture -- 2015 April - Hadoop Summit, Europe
Patterns of the Lambda Architecture -- 2015 April - Hadoop Summit, Europe
 

Mehr von DataStax Academy

Forrester CXNYC 2017 - Delivering great real-time cx is a true craft
Forrester CXNYC 2017 - Delivering great real-time cx is a true craftForrester CXNYC 2017 - Delivering great real-time cx is a true craft
Forrester CXNYC 2017 - Delivering great real-time cx is a true craftDataStax Academy
 
Introduction to DataStax Enterprise Graph Database
Introduction to DataStax Enterprise Graph DatabaseIntroduction to DataStax Enterprise Graph Database
Introduction to DataStax Enterprise Graph DatabaseDataStax Academy
 
Introduction to DataStax Enterprise Advanced Replication with Apache Cassandra
Introduction to DataStax Enterprise Advanced Replication with Apache CassandraIntroduction to DataStax Enterprise Advanced Replication with Apache Cassandra
Introduction to DataStax Enterprise Advanced Replication with Apache CassandraDataStax Academy
 
Cassandra on Docker @ Walmart Labs
Cassandra on Docker @ Walmart LabsCassandra on Docker @ Walmart Labs
Cassandra on Docker @ Walmart LabsDataStax Academy
 
Cassandra 3.0 Data Modeling
Cassandra 3.0 Data ModelingCassandra 3.0 Data Modeling
Cassandra 3.0 Data ModelingDataStax Academy
 
Cassandra Adoption on Cisco UCS & Open stack
Cassandra Adoption on Cisco UCS & Open stackCassandra Adoption on Cisco UCS & Open stack
Cassandra Adoption on Cisco UCS & Open stackDataStax Academy
 
Data Modeling for Apache Cassandra
Data Modeling for Apache CassandraData Modeling for Apache Cassandra
Data Modeling for Apache CassandraDataStax Academy
 
Production Ready Cassandra
Production Ready CassandraProduction Ready Cassandra
Production Ready CassandraDataStax Academy
 
Cassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & Python
Cassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & PythonCassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & Python
Cassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & PythonDataStax Academy
 
Cassandra @ Sony: The good, the bad, and the ugly part 1
Cassandra @ Sony: The good, the bad, and the ugly part 1Cassandra @ Sony: The good, the bad, and the ugly part 1
Cassandra @ Sony: The good, the bad, and the ugly part 1DataStax Academy
 
Cassandra @ Sony: The good, the bad, and the ugly part 2
Cassandra @ Sony: The good, the bad, and the ugly part 2Cassandra @ Sony: The good, the bad, and the ugly part 2
Cassandra @ Sony: The good, the bad, and the ugly part 2DataStax Academy
 
Standing Up Your First Cluster
Standing Up Your First ClusterStanding Up Your First Cluster
Standing Up Your First ClusterDataStax Academy
 
Real Time Analytics with Dse
Real Time Analytics with DseReal Time Analytics with Dse
Real Time Analytics with DseDataStax Academy
 
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
 
Enabling Search in your Cassandra Application with DataStax Enterprise
Enabling Search in your Cassandra Application with DataStax EnterpriseEnabling Search in your Cassandra Application with DataStax Enterprise
Enabling Search in your Cassandra Application with DataStax EnterpriseDataStax Academy
 
Advanced Data Modeling with Apache Cassandra
Advanced Data Modeling with Apache CassandraAdvanced Data Modeling with Apache Cassandra
Advanced Data Modeling with Apache CassandraDataStax Academy
 

Mehr von DataStax Academy (20)

Forrester CXNYC 2017 - Delivering great real-time cx is a true craft
Forrester CXNYC 2017 - Delivering great real-time cx is a true craftForrester CXNYC 2017 - Delivering great real-time cx is a true craft
Forrester CXNYC 2017 - Delivering great real-time cx is a true craft
 
Introduction to DataStax Enterprise Graph Database
Introduction to DataStax Enterprise Graph DatabaseIntroduction to DataStax Enterprise Graph Database
Introduction to DataStax Enterprise Graph Database
 
Introduction to DataStax Enterprise Advanced Replication with Apache Cassandra
Introduction to DataStax Enterprise Advanced Replication with Apache CassandraIntroduction to DataStax Enterprise Advanced Replication with Apache Cassandra
Introduction to DataStax Enterprise Advanced Replication with Apache Cassandra
 
Cassandra on Docker @ Walmart Labs
Cassandra on Docker @ Walmart LabsCassandra on Docker @ Walmart Labs
Cassandra on Docker @ Walmart Labs
 
Cassandra 3.0 Data Modeling
Cassandra 3.0 Data ModelingCassandra 3.0 Data Modeling
Cassandra 3.0 Data Modeling
 
Cassandra Adoption on Cisco UCS & Open stack
Cassandra Adoption on Cisco UCS & Open stackCassandra Adoption on Cisco UCS & Open stack
Cassandra Adoption on Cisco UCS & Open stack
 
Data Modeling for Apache Cassandra
Data Modeling for Apache CassandraData Modeling for Apache Cassandra
Data Modeling for Apache Cassandra
 
Coursera Cassandra Driver
Coursera Cassandra DriverCoursera Cassandra Driver
Coursera Cassandra Driver
 
Production Ready Cassandra
Production Ready CassandraProduction Ready Cassandra
Production Ready Cassandra
 
Cassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & Python
Cassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & PythonCassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & Python
Cassandra @ Netflix: Monitoring C* at Scale, Gossip and Tickler & Python
 
Cassandra @ Sony: The good, the bad, and the ugly part 1
Cassandra @ Sony: The good, the bad, and the ugly part 1Cassandra @ Sony: The good, the bad, and the ugly part 1
Cassandra @ Sony: The good, the bad, and the ugly part 1
 
Cassandra @ Sony: The good, the bad, and the ugly part 2
Cassandra @ Sony: The good, the bad, and the ugly part 2Cassandra @ Sony: The good, the bad, and the ugly part 2
Cassandra @ Sony: The good, the bad, and the ugly part 2
 
Standing Up Your First Cluster
Standing Up Your First ClusterStanding Up Your First Cluster
Standing Up Your First Cluster
 
Real Time Analytics with Dse
Real Time Analytics with DseReal Time Analytics with Dse
Real Time Analytics with Dse
 
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
 
Cassandra Core Concepts
Cassandra Core ConceptsCassandra Core Concepts
Cassandra Core Concepts
 
Enabling Search in your Cassandra Application with DataStax Enterprise
Enabling Search in your Cassandra Application with DataStax EnterpriseEnabling Search in your Cassandra Application with DataStax Enterprise
Enabling Search in your Cassandra Application with DataStax Enterprise
 
Bad Habits Die Hard
Bad Habits Die Hard Bad Habits Die Hard
Bad Habits Die Hard
 
Advanced Data Modeling with Apache Cassandra
Advanced Data Modeling with Apache CassandraAdvanced Data Modeling with Apache Cassandra
Advanced Data Modeling with Apache Cassandra
 
Advanced Cassandra
Advanced CassandraAdvanced Cassandra
Advanced Cassandra
 

Kürzlich hochgeladen

FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 

Kürzlich hochgeladen (20)

FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 

Cassandra Summit 2014: Understanding CQL3 Inside and Out

  • 1. The CQL3/Cassandra Mapping John Berryman OpenSource Connections OpenSource Connections
  • 2. Outline • What Problem does CQL Solve? • The Cassandra Data Model • Pain Points of “Old” Cassandra • Introducing CQL • Understanding the CQL/Cassandra Mapping • CQL for Sets, Lists, and Maps • Putting it All Together OpenSource Connections
  • 3. What Problem does CQL Solve? • The Awesomeness that is Cassandra: o Distributed columnar data store o No single point of failure o Optimized for availability (though “Tunably” consistent) o Optimized for writes o Easily maintainable o Almost infinitely scalable . OpenSource Connections
  • 4. What Problem does CQL Solve? • The Awesomeness that is Cassandra: o Distributed columnar data store o No single point of failure o Optimized for availability (though “Tunably” consistent) o Optimized for writes o Easily maintainable o Almost infinitely scalable • Cassandra’s usability challenges o NoSQL – “Where are my JOINS? No Schema? De-normalize!?” o BigTable – “Tables with millions of columns!?” . OpenSource Connections
  • 5. What Problem does CQL Solve? • The Awesomeness that is Cassandra: o Distributed columnar data store o No single point of failure o Optimized for availability (though “Tunably” consistent) o Optimized for writes o Easily maintainable o Almost infinitely scalable • Cassandra’s usability challenges o NoSQL – “Where are my JOINS? No Schema? De-normalize!?” o BigTable – “Tables with millions of columns!?” • CQL saves the day! o A best-practices interface to Cassandra o Uses familiar SQL-like language OpenSource Connections
  • 6. C* Data Model OpenSource Connections Keyspace
  • 7. C* Data Model Keyspace Column Family Column Family OpenSource Connections
  • 8. C* Data Model Keyspace Column Family Column Family OpenSource Connections
  • 9. C* Data Model Keyspace Column Family Column Family OpenSource Connections
  • 10. C* Data Model OpenSource Connections Row Key
  • 11. C* Data Model OpenSource Connections Row Key Column Column Name Column Value (or Tombstone) Timestamp Time-to-live
  • 12. C* Data Model ● Row Key, Column Name, Column OpenSource Connections Value have types ● Column Name has comparator ● RowKey has partitioner ● Rows can have any number of columns - even in same column family ● Rows can have many columns ● Column Values can be omitted ● Time-to-live is useful! ● Tombstones Row Key Column Column Name Column Value (or Tombstone) Timestamp Time-to-live
  • 13. C* Data Model: Writes SSTable SSTable SSTable OpenSource Connections Mem Table CommitLog Row Cache ● Insert into MemTable ● Dump to CommitLog ● No read ● Very Fast! ● Blocks on CPU before O/I! Key Cache SSTable Key Cache Key Cache Key Cache Bloom Filter
  • 14. C* Data Model: Writes SSTable SSTable SSTable OpenSource Connections Mem Table CommitLog Row Cache ● Insert into MemTable ● Dump to CommitLog ● No read ● Very Fast! ● Blocks on CPU before O/I! Key Cache SSTable Key Cache Key Cache Key Cache Bloom Filter
  • 15. C* Data Model: Writes SSTable SSTable SSTable OpenSource Connections Mem Table CommitLog Row Cache ● Insert into MemTable ● Dump to CommitLog ● No read ● Very Fast! ● Blocks on CPU before O/I! Key Cache SSTable Key Cache Key Cache Key Cache Bloom Filter
  • 16. SSTable SSTable SSTable OpenSource Connections Mem Table CommitLog Row Cache Key Cache SSTable Key Cache Key Cache Key Cache Bloom Filter ● Get values from Memtable ● Get values from row cache if present ● Otherwise check bloom filter to find appropriate SSTables ● Check Key Cache for fast SSTable Search ● Get values from SSTables ● Repopulate Row Cache ● Super Fast Col. retrieval ● Fast row slicing C* Data Model: Reads
  • 17. SSTable SSTable SSTable OpenSource Connections Mem Table CommitLog Row Cache Key Cache SSTable Key Cache Key Cache Key Cache Bloom Filter ● Get values from Memtable ● Get values from row cache if present ● Otherwise check bloom filter to find appropriate SSTables ● Check Key Cache for fast SSTable Search ● Get values from SSTables ● Repopulate Row Cache ● Super Fast Col. retrieval ● Fast row slicing C* Data Model: Reads
  • 18. SSTable SSTable SSTable OpenSource Connections Mem Table CommitLog Row Cache Key Cache SSTable Key Cache Key Cache Key Cache Bloom Filter ● Get values from Memtable ● Get values from row cache if present ● Otherwise check bloom filter to find appropriate SSTables ● Check Key Cache for fast SSTable Search ● Get values from SSTables ● Repopulate Row Cache ● Super Fast Col. retrieval ● Fast row slicing C* Data Model: Reads
  • 19. SSTable SSTable SSTable OpenSource Connections Mem Table CommitLog Row Cache Key Cache SSTable Key Cache Key Cache Key Cache Bloom Filter ● Get values from Memtable ● Get values from row cache if present ● Otherwise check bloom filter to find appropriate SSTables ● Check Key Cache for fast SSTable Search ● Get values from SSTables ● Repopulate Row Cache ● Super Fast Col. retrieval ● Fast row slicing C* Data Model: Reads
  • 20. SSTable SSTable SSTable OpenSource Connections Mem Table CommitLog Row Cache Key Cache SSTable Key Cache Key Cache Key Cache Bloom Filter ● Get values from Memtable ● Get values from row cache if present ● Otherwise check bloom filter to find appropriate SSTables ● Check Key Cache for fast SSTable Search ● Get values from SSTables ● Repopulate Row Cache ● Super Fast Col. retrieval ● Fast row slicing C* Data Model: Reads
  • 21. SSTable SSTable SSTable OpenSource Connections Mem Table CommitLog Row Cache Key Cache SSTable Key Cache Key Cache Key Cache Bloom Filter ● Get values from Memtable ● Get values from row cache if present ● Otherwise check bloom filter to find appropriate SSTables ● Check Key Cache for fast SSTable Search ● Get values from SSTables ● Repopulate Row Cache ● Super Fast Col. retrieval ● Fast row slicing C* Data Model: Reads
  • 22. Cassandra Pain Points • Twitter Example • My tweets o SET tweets[JnBrymn][2013-07-19 T 09:20] = “Wonderful morning. This coffee is great.”! o SET tweets[JnBrymn][2013-07-19 T 09:21] = “Oops, smoke is coming out of the SQL server!”! o SET tweets[JnBrymn][2013-07-19 T 09:51] = “Now my coffee is cold :-(” • Get John’s tweets o GET tweets[JnBrymn] (output is as expected) OpenSource Connections
  • 23. Cassandra Pain Points • Twitter Example • My tweets o SET tweets[JnBrymn][2013-07-19 T 09:20] = “Wonderful morning. This coffee is great.”! o SET tweets[JnBrymn][2013-07-19 T 09:21] = “Oops, smoke is coming out of the SQL server!”! o SET tweets[JnBrymn][2013-07-19 T 09:51] = “Now my coffee is cold :-(” • Get John’s tweets o GET tweets[JnBrymn] (output is as expected) • Pain-point: schema-less means that you have to read code to understand data model OpenSource Connections
  • 24. Cassandra Pain Points • My timeline (other’s tweets) • More complicated – must store corresponding user names • Bad Option 1: keep multiple column families o SET timeline_from[JnBrymn][2013-07-19 T 09:20] = “softwaredoug”! o SET timeline_text[JnBrymn][2013-07-19 T 09:20] = “Hey John I posted on reddit, upvote me!” • Get John’s timeline o GET timeline_from[JnBrymn]! o GET timeline_text[JnBrymn]! OpenSource Connections
  • 25. Cassandra Pain Points • My timeline (other’s tweets) • More complicated – must store corresponding user names • Bad Option 1: keep multiple column families o SET timeline_from[JnBrymn][2013-07-19 T 09:20] = “softwaredoug”! o SET timeline_text[JnBrymn][2013-07-19 T 09:20] = “Hey John I posted on reddit, upvote me!” • Get John’s timeline o GET timeline_from[JnBrymn]! o GET timeline_text[JnBrymn]! • Pain-point: Multiple queries required. OpenSource Connections
  • 26. Cassandra Pain Points • My timeline • Bad Option 2: shove into single column value o SET timeline[JnBrymn][2013-07-19 T 09:20] = {from:”softwaredoug”, text: “Hey John I posted on reddit, upvote me!” • Get John’s timeline o GET timeline[JnBrymn] (…not too bad.)! OpenSource Connections
  • 27. Cassandra Pain Points • My timeline • Bad Option 2: shove into single column value o SET timeline[JnBrymn][2013-07-19 T 09:20] = {from:”softwaredoug”, text: “Hey John I posted on reddit, upvote me!” • Get John’s timeline o GET timeline[JnBrymn] (…not too bad.)! • Pain-point: Updates require a read-then-modify OpenSource Connections
  • 28. Cassandra Pain Points • My timeline • Best Option: composite column names o SET timeline[JnBrymn][2013-07-19 T 09:20|from] = ”softwaredoug”! o SET timeline[JnBrymn][2013-07-19 T 09:20|text] = “Hey John, I posted on reddit, upvote me!” • Get John’s timeline o GET timeline[JnBrymn] (extract from and text in client) • Resolves prior pain points! Scales well!! OpenSource Connections
  • 29. Cassandra Pain Points • My timeline • Best Option: composite column names o SET timeline[JnBrymn][2013-07-19 T 09:20|from] = ”softwaredoug”! o SET timeline[JnBrymn][2013-07-19 T 09:20|text] = “Hey John, I posted on reddit, upvote me!” • Get John’s timeline o GET timeline[JnBrymn] (extract from and text in client) • Resolves prior pain points! Scales well!! • Pain-point: Even more code reading to understand data model! OpenSource Connections
  • 30. Cassandra Pain Points • Justin Bieber’s timeline (e.g. many tweets) • Previous solution fails if number of columns > 2Billion • Best Option: composite row names o SET timeline[bieber|2013-07][19 T 09:20|from] = ”softwaredoug”! o SET timeline[bieber|2013-07][19 T 09:20|text] = “Justin Bieber, you complete me.” • Get Justin’s timeline o GET timeline[bieber|2013-07] (get other months too) OpenSource Connections
  • 31. Cassandra Pain Points • Justin Bieber’s timeline (e.g. many tweets) • Previous solution fails if number of columns > 2Billion • Best Option: composite row names o SET timeline[bieber|2013-07][19 T 09:20|from] = ”softwaredoug”! o SET timeline[bieber|2013-07][19 T 09:20|text] = “Justin Bieber, you complete me.” • Get Justin’s timeline o GET timeline[bieber|2013-07] (get other months too) • Pain-point: Even more code reading to understand data model! OpenSource Connections
  • 32. Introducing CQL • CQL is a reintroduction of schema so that you don’t have to read code to understand the data model. • CQL creates a common language so that details of the data model can be easily communicated. • CQL is a best-practices Cassandra interface and hides the messy details. OpenSource Connections
  • 33. Introducing CQL • CQL is a reintroduction of schema so that you don’t have to read code to understand the data model. • CQL creates a common language so that details of the data model can be easily communicated. • CQL is a best-practices Cassandra interface and hides the messy details. OpenSource Connections Let’s see it!
  • 34. Introducing CQL CREATE TABLE users ( id timeuuid PRIMARY KEY,! lastname varchar,! firstname varchar,! dateOfBirth timestamp );! ! ! ! OpenSource Connections
  • 35. Introducing CQL CREATE TABLE users ( id timeuuid PRIMARY KEY,! lastname varchar,! firstname varchar,! dateOfBirth timestamp );! ! INSERT INTO users (id,lastname, firstname, dateofbirth) VALUES (now(),'Berryman',’John','1975-09-15');! !! OpenSource Connections
  • 36. Introducing CQL CREATE TABLE users ( id timeuuid PRIMARY KEY,! lastname varchar,! firstname varchar,! dateOfBirth timestamp );! ! INSERT INTO users (id,lastname, firstname, dateofbirth) VALUES (now(),’Berryman’,’John’,’1975-09-15’);! ! UPDATE users SET firstname = ’John’ WHERE id = f74c0b20-0862-11e3-8cf6-b74c10b01fc6;! ! OpenSource Connections
  • 37. Introducing CQL CREATE TABLE users ( id timeuuid PRIMARY KEY,! lastname varchar,! firstname varchar,! dateOfBirth timestamp );! ! INSERT INTO users (id,lastname, firstname, dateofbirth) VALUES (now(),'Berryman',’John','1975-09-15');! ! UPDATE users SET firstname = 'John’ WHERE id = f74c0b20-0862-11e3-8cf6-b74c10b01fc6;! ! SELECT dateofbirth,firstname,lastname FROM users ;! ! dateofbirth | firstname | lastname! --------------------------+-----------+----------! 1975-09-15 00:00:00-0400 | John | Berryman! OpenSource Connections
  • 38. Introducing CQL “Hey sweet! It’s exactly the same as MySQL!” OpenSource Connections
  • 39. Introducing CQL “Hey sweet! It’s exactly the same as MySQL!” Hold your horses. There are some important differences. OpenSource Connections
  • 40. Introducing CQL “Hey sweet! It’s exactly the same as MySQL!” Hold your horses. There are some important differences. “Wait? What happened to the Cassandra’s wide rows?” OpenSource Connections
  • 41. Introducing CQL “Hey sweet! It’s exactly the same as MySQL!” Hold your horses. There are some important differences. “Wait? What happened to the Cassandra’s wide rows?” There’s still there. Understanding the mapping is crucial! OpenSource Connections
  • 42. Introducing CQL “Hey sweet! It’s exactly the same as MySQL!” Hold your horses. There are some important differences. “Wait? What happened to the Cassandra’s wide rows?” There’s still there. Understanding the mapping is crucial! OpenSource Connections Remember this: • Cassandra finds rows fast • Cassandra scans columns fast • Cassandra does not scan rows
  • 43. The CQL/Cassandra Mapping CREATE TABLE employees (! name text PRIMARY KEY,! age int,! role text! );! ! OpenSource Connections
  • 44. The CQL/Cassandra Mapping CREATE TABLE employees (! name text PRIMARY KEY,! age int,! role text! );! ! name | age | role! -----+-----+-----! john | 37 | dev! eric | 38 | ceo! ! OpenSource Connections
  • 45. The CQL/Cassandra Mapping CREATE TABLE employees (! name text PRIMARY KEY,! age int,! role text! );! ! name | age | role! -----+-----+-----! john | 37 | dev! eric | 38 | ceo! ! OpenSource Connections age! role! john! 37! dev! age! role! eric! 38! ceo!
  • 46. The CQL/Cassandra Mapping CREATE TABLE employees (! company text,! name text,! age int,! role text,! PRIMARY KEY (company,name)! );! ! OpenSource Connections
  • 47. The CQL/Cassandra Mapping CREATE TABLE employees (! company text,! name text,! age int,! role text,! PRIMARY KEY (company,name)! );! ! company | name | age | role! --------+------+-----+-----! OSC | eric | 38 | ceo! OSC | john | 37 | dev! RKG | anya | 29 | lead! RKG | ben | 27 | dev! RKG | chad | 35 | ops! OpenSource Connections
  • 48. The CQL/Cassandra Mapping CREATE TABLE employees (! company text,! name text,! age int,! role text,! PRIMARY KEY (company,name)! );! ! company | name | age | role! --------+------+-----+-----! OSC | eric | 38 | ceo! OSC | john | 37 | dev! RKG | anya | 29 | lead! RKG | ben | 27 | dev! RKG | chad | 35 | ops! ! eric:age! eric:role! john:age! john:role! OSC! 38! dev! 37! dev! anya:age! anya:role! ben:age! ben:role! chad:age! chad:role! RKG! 29! lead! 27! dev! 35! ops! OpenSource Connections
  • 49. The CQL/Cassandra Mapping CREATE TABLE example (! A text,! B text,! C text,! D text,! E text,! F text,! PRIMARY KEY ((A,B),C,D)! );! OpenSource Connections
  • 50. The CQL/Cassandra Mapping CREATE TABLE example (! A text,! B text,! C text,! D text,! E text,! F text,! PRIMARY KEY ((A,B),C,D)! );! A | B | C | D | E | F ! --+---+---+---+---+---! a | b | c | d | e | f! a | b | c | g | h | i! a | b | j | k | l | m! a | n | o | p | q | r! s | t | u | v | w | x! OpenSource Connections
  • 51. The CQL/Cassandra Mapping CREATE TABLE example (! A text,! B text,! C text,! D text,! E text,! F text,! PRIMARY KEY ((A,B),C,D)! );! A | B | C | D | E | F ! --+---+---+---+---+---! a | b | c | d | e | f! a | b | c | g | h | i! a | b | j | k | l | m! a | n | o | p | q | r! s | t | u | v | w | x! ! c:d:E! c:d:F! c:g:E! c:g:F! j:k:E! j:k:F! a:b! e! f! h! i! l! m! OpenSource Connections ! o:p:E! o:p:F! a:n! q! r! ! u:v:E! u:v:F! s:t! w! x!
  • 52. CQL for Sets, Lists, and Maps • Collection Semantics o Sets hold list of unique elements o Lists hold ordered, possibly repeating elements o Maps hold a list of key-value pairs • Uses same old Cassandra data structure OpenSource Connections
  • 53. CQL for Sets, Lists, and Maps • Collection Semantics o Sets hold list of unique elements o Lists hold ordered, possibly repeating elements o Maps hold a list of key-value pairs • Uses same old Cassandra data structure • Declaring OpenSource Connections CREATE TABLE mytable(! X text,! Y text,! myset set<text>,! mylist list<int>,! mymap map<text, text>,! PRIMARY KEY (X,Y)! );!
  • 54. CQL for Sets, Lists, and Maps • Collection Semantics o Sets hold list of unique elements o Lists hold ordered, possibly repeating elements o Maps hold a list of key-value pairs • Uses same old Cassandra data structure • Declaring OpenSource Connections CREATE TABLE mytable(! X text,! Y text,! myset set<text>,! mylist list<int>,! mymap map<text, text>,! PRIMARY KEY (X,Y)! );! Collection fields can not be used in primary keys
  • 55. CQL for Sets, Lists, and Maps • Inserting ! INSERT INTO mytable (row, myset) VALUES (123, { ‘apple’, ‘banana’}); OpenSource Connections
  • 56. CQL for Sets, Lists, and Maps • Inserting ! INSERT INTO mytable (row, myset) VALUES (123, { ‘apple’, ‘banana’}); INSERT INTO mytable (row, mylist) VALUES (123, [‘apple’,’banana’,’apple’]); OpenSource Connections
  • 57. CQL for Sets, Lists, and Maps • Inserting ! INSERT INTO mytable (row, myset) VALUES (123, { ‘apple’, ‘banana’}); INSERT INTO mytable (row, mylist) VALUES (123, [‘apple’,’banana’,’apple’]); INSERT INTO mytable (row, mymap) VALUES (123, {1:’apple’,2:’banana’}) OpenSource Connections
  • 58. CQL for Sets, Lists, and Maps • Updating UPDATE mytable SET myset = myset + {‘apple’,‘banana’} WHERE row = 123; UPDATE mytable SET myset = myset - { ‘apple’ } WHERE row = 123;! OpenSource Connections
  • 59. CQL for Sets, Lists, and Maps • Updating UPDATE mytable SET myset = myset + {‘apple’,‘banana’} WHERE row = 123; UPDATE mytable SET myset = myset - { ‘apple’ } WHERE row = 123;! UPDATE mytable SET mylist = mylist + [‘apple’,‘banana’] WHERE row = 123; UPDATE mytable SET mylist = [‘banana’] + mylist WHERE row = 123;! OpenSource Connections
  • 60. CQL for Sets, Lists, and Maps • Updating UPDATE mytable SET myset = myset + {‘apple’,‘banana’} WHERE row = 123; UPDATE mytable SET myset = myset - { ‘apple’ } WHERE row = 123;! UPDATE mytable SET mylist = mylist + [‘apple’,‘banana’] WHERE row = 123; UPDATE mytable SET mylist = [‘banana’] + mylist WHERE row = 123;! UPDATE mytable SET mymap[‘fruit’] = ‘apple’ WHERE row = 123 UPDATE mytable SET mymap = mymap + { ‘fruit’:‘apple’} WHERE row = 123! OpenSource Connections
  • 61. CQL for Sets, Lists, and Maps SETS ! CREATE TABLE mytable(! X text,! Y text,! myset set<int>,! PRIMARY KEY (X,Y)! );! ! OpenSource Connections
  • 62. CQL for Sets, Lists, and Maps SETS ! CREATE TABLE mytable(! X text,! Y text,! myset set<int>,! PRIMARY KEY (X,Y)! );! ! X | Y | myset ! ---+---+------------! a | b | {1,2}! a | c | {3,4,5}! OpenSource Connections
  • 63. CQL for Sets, Lists, and Maps SETS ! CREATE TABLE mytable(! X text,! Y text,! myset set<int>,! PRIMARY KEY (X,Y)! );! ! X | Y | myset ! ---+---+------------! a | b | {1,2}! a | c | {3,4,5}! ! b:myset:1! b:myset:2! c:myset:3! c:myset:4! c:myset:5! a! OpenSource Connections
  • 64. CQL for Sets, Lists, and Maps OpenSource Connections LISTS ! CREATE TABLE mytable(! X text,! Y text,! mylist list<int>,! PRIMARY KEY (X,Y)! );! !
  • 65. CQL for Sets, Lists, and Maps X | Y | mylist ! ---+---+------------! a | b | [1,2]! OpenSource Connections LISTS ! CREATE TABLE mytable(! X text,! Y text,! mylist list<int>,! PRIMARY KEY (X,Y)! );! !
  • 66. CQL for Sets, Lists, and Maps X | Y | mylist ! ---+---+------------! a | b | [1,2]! ! b:mylist:f7e5450039..8d! b:mylist:f7e5450139..8d! a! 1! 2! OpenSource Connections LISTS ! CREATE TABLE mytable(! X text,! Y text,! mylist list<int>,! PRIMARY KEY (X,Y)! );! !
  • 67. CQL for Sets, Lists, and Maps X | Y | mylist ! ---+---+------------! a | b | [1,2]! ! b:mylist:f7e5450039..8d! b:mylist:f7e5450139..8d! a! 1! 2! OpenSource Connections LISTS ! CREATE TABLE mytable(! X text,! Y text,! mylist list<int>,! PRIMARY KEY (X,Y)! );! !
  • 68. CQL for Sets, Lists, and Maps MAPS ! CREATE TABLE mytable(! X text,! Y text,! mymap map<text,int>,! PRIMARY KEY (X,Y)! );! ! OpenSource Connections
  • 69. CQL for Sets, Lists, and Maps MAPS ! CREATE TABLE mytable(! X text,! Y text,! mymap map<text,int>,! PRIMARY KEY (X,Y)! );! ! X | Y | mymap ! ---+---+------------! a | b | {m:1,n:2}! a | c |{n:3,p:4,q:5}! OpenSource Connections
  • 70. CQL for Sets, Lists, and Maps MAPS ! CREATE TABLE mytable(! X text,! Y text,! mymap map<text,int>,! PRIMARY KEY (X,Y)! );! ! X | Y | mymap ! ---+---+------------! a | b | {m:1,n:2}! a | c |{n:3,p:4,q:5}! ! b:mymap:m! b:mymap:n! c:mymap:n! c:mymap:p! c:mymap:q! a! 1! 2! 3! 4! 5! OpenSource Connections
  • 71. Peek Behind the Scenes! Do it! (in cqlsh) CREATE KEYSPACE test WITH replication = ! {'class': 'SimpleStrategy', 'replication_factor': 1};! USE test;! CREATE TABLE stuff ( a int, b int, myset set<int>,! mylist list<int>, mymap map<int,int>, PRIMARY KEY (a,b));! UPDATE stuff SET myset = {1,2}, mylist = [3,4,5], mymap = {6:7,8:9} WHERE a = 0 AND b = 1;! SELECT * FROM stuff;! ! (in cassandra-cli) use test;! list stuff ;! ! (in cqlsh) SELECT key_aliases,column_aliases from system.schema_columnfamilies WHERE keyspace_name = 'test' AND columnfamily_name = 'stuff';! OpenSource Connections
  • 72. Putting it All Together …you already know • CQL is a reintroduction of schema • CQL creates a common data modeling language • CQL is a best-practices Cassandra interface . OpenSource Connections
  • 73. Putting it All Together …you already know • CQL is a reintroduction of schema • CQL creates a common data modeling language • CQL is a best-practices Cassandra interface …now you know • CQL let’s you take advantage of the C* Data structure . OpenSource Connections
  • 74. Putting it All Together …you already know • CQL is a reintroduction of schema • CQL creates a common data modeling language • CQL is a best-practices Cassandra interface …now you know • CQL let’s you take advantage of the C* Data structure …but also • CQL protocol is binary and therefore interoperable with any language • CQL is asynchronous and fast (Thrift transport layer is synchronous) • CQL allows the possibility for prepared statements OpenSource Connections
  • 75. Thanks! Follow me on Twitter @JnBrymn Check out the OpenSource Connection Blog http://www.opensourceconnections.com/blog/ OpenSource Connections