SlideShare una empresa de Scribd logo
1 de 20
Descargar para leer sin conexión
The State of CQL

Sylvain Lebresne (DataStax)
A short CQL primer
New in Cassandra 2.0
Native protocol
What's next?

2/20
A better API for Cassandra
Thrift is not satisfactory:

· Not user friendly, hard to use.
· Low level, very little abstraction.
· Hard to evolve (in a backward compatible way).
· Unreadable without driver abstraction.
Cassandra has often been regarded as hard to develop against.
It doesn't have to be that way!

3/20
Quick historical notes
· CQL1 first introduced in Cassandra 0.8, became CQL2 in Cassandra 1.0
· "These aren't the CQL you are looking for"
· CQL3 (CQL for short thereafter) introduced in Cassandra 1.2
· Semantically, CQL1/CQL2 are closer to the Thrift API than to CQL3.
· CQL3 is the version that's here to stay: no plan for a CQL4 any time soon.

4/20
A short CQL primer
The Cassandra Query Language
· Syntactically, a subset of SQL (with a few extensions)
CET TBEues(
RAE AL sr
ue_dui,
sri ud
nm tx,
ae et
pswr tx,
asod et
ealtx,
mi et
pcuepoiebo,
itr_rfl lb
PIAYKY(sri)
RMR E ue_d
)

· INSERT and UPDATE are both upserts
· No joins, no sub-queries, no aggregation, ...
· Denormalization is the norm: do the work at write time, not read time
6/20

CL
Q
Denormalization: Cassandra modeling 101
Efficient queries in Cassandra are based on 2 principles:

· the data queried is collocated on one replica set
· the data queried is collocated on disk on those replicas
Denormalization is the technique that allows to achieve this in practice.
But this means CQL exposes:

· how to collocate data on the same replica set
· how to collocate data on disk (for a given replica)

7/20
This is done in CQL through the primary key
CET TBEibxs(
RAE AL noe

CL
Q

ue_dui,
sri ud
eali tmui,
mi_d ieud
sne tx,
edr et
rcpet sttx>
eiins e<et,
sbettx,
ujc et
i_edboen
sra ola,
P I A Y K Y (u e _ d, e a l i
RMR E
sri
m i _ d)
)

CQL distinguishes 2 sub-parts in the PRIMARY KEY:
partition key: decides the node on which the data is stored
clustering columns: within the same partition key, (CQL3) rows are
physically ordered following the clustering columns

·
·

This is important, because CQL only allow queries for which an explicit index
exists:
- Gtls 5 eal i ue 5b2-b ibx
- e at 0 mis n sr 1-3a8 no
8/20

SLC *FO ibxsWEEue_d5b2-b ODRB eali DS LMT5;
EET
RM noe HR sri=1-3a8 RE Y mi_d EC II 0

CL
Q
CQL main features

· Collections (set, map and list)
· Secondary indexes
· Convenience functions (timeuuid, type conversions, ...)
· ...
For more details:

· http://cassandra.apache.org/doc/cql3/CQL.html
· http://www.datastax.com/documentation/cql/3.1/webhelp/index.html

9/20
New in Cassandra 2.0
New in Cassandra 2.0
Lightweight transactions:
ISR IT ts (d nm)VLE (2 'o' I NTEIT;
NET NO et i, ae AUS 4, Tm) F O XSS

CL
Q

UDT ts STpswr=nwas WEEi=2I pswr=odas;
PAE et E asod'eps' HR d4 F asod'lps'

Triggers:
CET TIGRmTigrO ts UIG'ytigrCas;
RAE RGE yrge N et SN m.rge.ls'

CL
Q

ALTER DROP:
CET TBEts ( itPIAYKY po1it po2tx,po3fot;
RAE AL et k n RMR E, rp n, rp et rp la)

CL
Q

ATRTBEts DO po3
LE AL et RP rp;

Preparing TIMESTAMP, TTL and LIMIT:
SLC *FO mTbeLMT?
EET
RM yal II ;
UDT mTbeUIGTL?STv=2WEEk='o'
PAE yal SN T
E
HR
fo;

11/20

CL
Q
New in Cassandra 2.0
Conditional DDL:
CET TBEI NTEIT ts ( itPIAYKY;
RAE AL F O XSS et k n RMR E)

CL
Q

DO KYPC I EIT k;
RP ESAE F XSS s

Secondary indexes everywhere (almost):
CET TBEtmln (
RAE AL ieie

CL
Q

eeti ui,
vn_d ud
cetda tmui,
rae_t ieud
cnetbo,
otn lb
PIAYKY(vn_d cetda)
RMR E eeti, rae_t
)
;
CET IDXO tmln (rae_t;
RAE NE N ieie cetda)

SELECT aliases:
SLC eeti,
EET vn_d
dtO(rae_t A ceto_ae
aefcetda) S raindt,
12/20

FO tmln;
RM ieie

CL
Q
Coming in Cassandra 2.0.2
Named bind variables:
L
S L C * F O t m l n W E E c e t d a > : l w A D c e t d a < : h g A D k y = Q;
EET
RM ieie HR rae_t
t o N r a e _ t = t i h N e Ck
:

Prepared IN:
SLC *FO uesWEEue_dI ?
EET
RM sr HR sri N ;

CL
Q

Limited SELECT DISTINCT:
CET TBEts (
RAE AL et
eeti it
vn_d n,
cetda tmsap
rae_t ietm,
cnetbo,
otn lb
PIAYKY(vn_d cetda)
RMR E eeti, rae_t
)
;
SLC DSIC eeti FO ts;
EET ITNT vn_d RM et

13/20

CL
Q
The native protocol
A binary transport protocol for CQL
Native protocol
· Binary transport protocol for CQL
· Query execution, prepared statements, authentication, compression, ...
· Asynchronous (allows multiple concurrent queries per connection)
· Server notifications (Only generic cluster events currently)
· Existing drivers for Java, C#, Python, C++, Golang, ...
Example usage of the Java driver (https://github.com/datastax/java-driver):
Cutrcutr=Cutrbidr)adotcPit"2...".ul(;
lse lse
lse.ule(.dCnaton(17001)bid)
Ssinssin=cutrcnet"yesae)
eso eso
lse.onc(mKypc";
fr(o rw:ssineeue"EET*FO mTbe)
o Rw o
eso.xct(SLC
RM yal")
/ D smtig..
/ o oehn .

15/20

JV
AA
New in Cassandra 2.0: native protocol 2
Cursors:
fr(o rw:ssineeue"EET*FO mTbe)
o Rw o
eso.xct(SLC
RM yal")

JV
AA

/ D smtig..
/ o oehn .

Batching prepared statements:
P e a e S a e e t p = s s i n p e a e " N E T I T m T b e ( 1 p ) V L E ( , ?A ;
rprdttmn s
eso.rpr(ISR NO yal p, 1 AUS ? J V
))
"A
Bthttmn b =nwBthttmn(;
acSaeet s
e acSaeet)
b.d(sbn(,"1);
sadp.id0 v")
b.d(sbn(,"2);
sadp.id1 v")
b.d(sbn(,"3);
sadp.id2 v")
ssineeueb)
eso.xct(s;

One-shot prepare and execute:
s s i n e e u e " N E T I T u e s ( d p o o V L E ( , ? " s m I , p o o y eJ V
e s o . x c t ( I S R N O s r i , h t ) A U S ? ) , o e d h t B t sA A
)
;

SASL for authentication

16/20
What's next?
Cassandra 2.1 and beyond
CQL: some ideas
· Storage engine optimizations for CQL
· Secondary index for collections
· Server side functions
· User defined types
· ...

18/20
User defined types
CET TP ades(
RAE YE drs
sre tx,
tet et
zpcd it
i_oe n,
saetx,
tt et
poe sttx>
hns e<et
)
;
CET TBEues(
RAE AL sr
i ui PIAYKY
d ud RMR E,
nm tx,
ae et
adessmptx,ades
drse a<et drs>
)
;
ISR IT ues(d nm)VLE (3-a71 "yvi Lben";
NET NO sr i, ae AUS 244-6, Slan erse)
UDT uesSTadess"ok]={
PAE sr E drse[wr"
sre:'7 Mrnr Iln Bv #1'
tet 77 aies sad ld 50,
zpcd:944
i_oe 40,
sae 'A,
tt: C'
19/20

poe:{603960 }
hns
5-8-00
}WEEi =244-6;
HR d
3-a71

CL
Q
Thank You!
(Questions?)

Más contenido relacionado

Similar a C* Summit EU 2013: The State of CQL

Similar a C* Summit EU 2013: The State of CQL (20)

Wien2k getting started
Wien2k getting startedWien2k getting started
Wien2k getting started
 
Improving Software Reliability via Mining Software Engineering Data
Improving Software Reliability via Mining Software Engineering DataImproving Software Reliability via Mining Software Engineering Data
Improving Software Reliability via Mining Software Engineering Data
 
JavaFX, because you're worth it
JavaFX, because you're worth itJavaFX, because you're worth it
JavaFX, because you're worth it
 
OptimizingARM
OptimizingARMOptimizingARM
OptimizingARM
 
191010 opie2
191010 opie2191010 opie2
191010 opie2
 
Embedded JavaScript
Embedded JavaScriptEmbedded JavaScript
Embedded JavaScript
 
1st and 2nd Semester M Tech: Computer Science and Engineering (Dec-2015; Jan-...
1st and 2nd Semester M Tech: Computer Science and Engineering (Dec-2015; Jan-...1st and 2nd Semester M Tech: Computer Science and Engineering (Dec-2015; Jan-...
1st and 2nd Semester M Tech: Computer Science and Engineering (Dec-2015; Jan-...
 
Code GPU with CUDA - Identifying performance limiters
Code GPU with CUDA - Identifying performance limitersCode GPU with CUDA - Identifying performance limiters
Code GPU with CUDA - Identifying performance limiters
 
224698998 moshell-commands
224698998 moshell-commands224698998 moshell-commands
224698998 moshell-commands
 
Constructing Distributed Doubly Linked Lists without Distributed Locking
Constructing Distributed Doubly Linked Lists without Distributed LockingConstructing Distributed Doubly Linked Lists without Distributed Locking
Constructing Distributed Doubly Linked Lists without Distributed Locking
 
QR Factorizations and SVDs for Tall-and-skinny Matrices in MapReduce Architec...
QR Factorizations and SVDs for Tall-and-skinny Matrices in MapReduce Architec...QR Factorizations and SVDs for Tall-and-skinny Matrices in MapReduce Architec...
QR Factorizations and SVDs for Tall-and-skinny Matrices in MapReduce Architec...
 
Assembler Numerical in system programming
Assembler Numerical in system programmingAssembler Numerical in system programming
Assembler Numerical in system programming
 
Formal Semantics of SQL and Cypher
Formal Semantics of SQL and CypherFormal Semantics of SQL and Cypher
Formal Semantics of SQL and Cypher
 
Introduction to Compiler Development
Introduction to Compiler DevelopmentIntroduction to Compiler Development
Introduction to Compiler Development
 
3.ASSEMBLERS.pptx
3.ASSEMBLERS.pptx3.ASSEMBLERS.pptx
3.ASSEMBLERS.pptx
 
Arquillian - extensions which you have to take with you to a deserted island
Arquillian - extensions which you have to take with you to a deserted islandArquillian - extensions which you have to take with you to a deserted island
Arquillian - extensions which you have to take with you to a deserted island
 
T-S Fuzzy Observer and Controller of Doubly-Fed Induction Generator
T-S Fuzzy Observer and Controller of Doubly-Fed Induction GeneratorT-S Fuzzy Observer and Controller of Doubly-Fed Induction Generator
T-S Fuzzy Observer and Controller of Doubly-Fed Induction Generator
 
#include LPC17xx.h#include Lights.h#include traffic_fo.docx
#include LPC17xx.h#include Lights.h#include traffic_fo.docx#include LPC17xx.h#include Lights.h#include traffic_fo.docx
#include LPC17xx.h#include Lights.h#include traffic_fo.docx
 
An Example MIPS
An Example  MIPSAn Example  MIPS
An Example MIPS
 
NLP@ICLR2019
NLP@ICLR2019NLP@ICLR2019
NLP@ICLR2019
 

Más de DataStax Academy

Cassandra on Docker @ Walmart Labs
Cassandra on Docker @ Walmart LabsCassandra on Docker @ Walmart Labs
Cassandra on Docker @ Walmart Labs
DataStax 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 stack
DataStax 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 & Python
DataStax Academy
 
Standing Up Your First Cluster
Standing Up Your First ClusterStanding Up Your First Cluster
Standing Up Your First Cluster
DataStax Academy
 
Real Time Analytics with Dse
Real Time Analytics with DseReal Time Analytics with Dse
Real Time Analytics with Dse
DataStax 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 Cassandra
DataStax 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 Enterprise
DataStax Academy
 
Advanced Data Modeling with Apache Cassandra
Advanced Data Modeling with Apache CassandraAdvanced Data Modeling with Apache Cassandra
Advanced Data Modeling with Apache Cassandra
DataStax Academy
 

Más de 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
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

C* Summit EU 2013: The State of CQL

  • 1. The State of CQL Sylvain Lebresne (DataStax)
  • 2. A short CQL primer New in Cassandra 2.0 Native protocol What's next? 2/20
  • 3. A better API for Cassandra Thrift is not satisfactory: · Not user friendly, hard to use. · Low level, very little abstraction. · Hard to evolve (in a backward compatible way). · Unreadable without driver abstraction. Cassandra has often been regarded as hard to develop against. It doesn't have to be that way! 3/20
  • 4. Quick historical notes · CQL1 first introduced in Cassandra 0.8, became CQL2 in Cassandra 1.0 · "These aren't the CQL you are looking for" · CQL3 (CQL for short thereafter) introduced in Cassandra 1.2 · Semantically, CQL1/CQL2 are closer to the Thrift API than to CQL3. · CQL3 is the version that's here to stay: no plan for a CQL4 any time soon. 4/20
  • 5. A short CQL primer
  • 6. The Cassandra Query Language · Syntactically, a subset of SQL (with a few extensions) CET TBEues( RAE AL sr ue_dui, sri ud nm tx, ae et pswr tx, asod et ealtx, mi et pcuepoiebo, itr_rfl lb PIAYKY(sri) RMR E ue_d ) · INSERT and UPDATE are both upserts · No joins, no sub-queries, no aggregation, ... · Denormalization is the norm: do the work at write time, not read time 6/20 CL Q
  • 7. Denormalization: Cassandra modeling 101 Efficient queries in Cassandra are based on 2 principles: · the data queried is collocated on one replica set · the data queried is collocated on disk on those replicas Denormalization is the technique that allows to achieve this in practice. But this means CQL exposes: · how to collocate data on the same replica set · how to collocate data on disk (for a given replica) 7/20
  • 8. This is done in CQL through the primary key CET TBEibxs( RAE AL noe CL Q ue_dui, sri ud eali tmui, mi_d ieud sne tx, edr et rcpet sttx> eiins e<et, sbettx, ujc et i_edboen sra ola, P I A Y K Y (u e _ d, e a l i RMR E sri m i _ d) ) CQL distinguishes 2 sub-parts in the PRIMARY KEY: partition key: decides the node on which the data is stored clustering columns: within the same partition key, (CQL3) rows are physically ordered following the clustering columns · · This is important, because CQL only allow queries for which an explicit index exists: - Gtls 5 eal i ue 5b2-b ibx - e at 0 mis n sr 1-3a8 no 8/20 SLC *FO ibxsWEEue_d5b2-b ODRB eali DS LMT5; EET RM noe HR sri=1-3a8 RE Y mi_d EC II 0 CL Q
  • 9. CQL main features · Collections (set, map and list) · Secondary indexes · Convenience functions (timeuuid, type conversions, ...) · ... For more details: · http://cassandra.apache.org/doc/cql3/CQL.html · http://www.datastax.com/documentation/cql/3.1/webhelp/index.html 9/20
  • 11. New in Cassandra 2.0 Lightweight transactions: ISR IT ts (d nm)VLE (2 'o' I NTEIT; NET NO et i, ae AUS 4, Tm) F O XSS CL Q UDT ts STpswr=nwas WEEi=2I pswr=odas; PAE et E asod'eps' HR d4 F asod'lps' Triggers: CET TIGRmTigrO ts UIG'ytigrCas; RAE RGE yrge N et SN m.rge.ls' CL Q ALTER DROP: CET TBEts ( itPIAYKY po1it po2tx,po3fot; RAE AL et k n RMR E, rp n, rp et rp la) CL Q ATRTBEts DO po3 LE AL et RP rp; Preparing TIMESTAMP, TTL and LIMIT: SLC *FO mTbeLMT? EET RM yal II ; UDT mTbeUIGTL?STv=2WEEk='o' PAE yal SN T E HR fo; 11/20 CL Q
  • 12. New in Cassandra 2.0 Conditional DDL: CET TBEI NTEIT ts ( itPIAYKY; RAE AL F O XSS et k n RMR E) CL Q DO KYPC I EIT k; RP ESAE F XSS s Secondary indexes everywhere (almost): CET TBEtmln ( RAE AL ieie CL Q eeti ui, vn_d ud cetda tmui, rae_t ieud cnetbo, otn lb PIAYKY(vn_d cetda) RMR E eeti, rae_t ) ; CET IDXO tmln (rae_t; RAE NE N ieie cetda) SELECT aliases: SLC eeti, EET vn_d dtO(rae_t A ceto_ae aefcetda) S raindt, 12/20 FO tmln; RM ieie CL Q
  • 13. Coming in Cassandra 2.0.2 Named bind variables: L S L C * F O t m l n W E E c e t d a > : l w A D c e t d a < : h g A D k y = Q; EET RM ieie HR rae_t t o N r a e _ t = t i h N e Ck : Prepared IN: SLC *FO uesWEEue_dI ? EET RM sr HR sri N ; CL Q Limited SELECT DISTINCT: CET TBEts ( RAE AL et eeti it vn_d n, cetda tmsap rae_t ietm, cnetbo, otn lb PIAYKY(vn_d cetda) RMR E eeti, rae_t ) ; SLC DSIC eeti FO ts; EET ITNT vn_d RM et 13/20 CL Q
  • 14. The native protocol A binary transport protocol for CQL
  • 15. Native protocol · Binary transport protocol for CQL · Query execution, prepared statements, authentication, compression, ... · Asynchronous (allows multiple concurrent queries per connection) · Server notifications (Only generic cluster events currently) · Existing drivers for Java, C#, Python, C++, Golang, ... Example usage of the Java driver (https://github.com/datastax/java-driver): Cutrcutr=Cutrbidr)adotcPit"2...".ul(; lse lse lse.ule(.dCnaton(17001)bid) Ssinssin=cutrcnet"yesae) eso eso lse.onc(mKypc"; fr(o rw:ssineeue"EET*FO mTbe) o Rw o eso.xct(SLC RM yal") / D smtig.. / o oehn . 15/20 JV AA
  • 16. New in Cassandra 2.0: native protocol 2 Cursors: fr(o rw:ssineeue"EET*FO mTbe) o Rw o eso.xct(SLC RM yal") JV AA / D smtig.. / o oehn . Batching prepared statements: P e a e S a e e t p = s s i n p e a e " N E T I T m T b e ( 1 p ) V L E ( , ?A ; rprdttmn s eso.rpr(ISR NO yal p, 1 AUS ? J V )) "A Bthttmn b =nwBthttmn(; acSaeet s e acSaeet) b.d(sbn(,"1); sadp.id0 v") b.d(sbn(,"2); sadp.id1 v") b.d(sbn(,"3); sadp.id2 v") ssineeueb) eso.xct(s; One-shot prepare and execute: s s i n e e u e " N E T I T u e s ( d p o o V L E ( , ? " s m I , p o o y eJ V e s o . x c t ( I S R N O s r i , h t ) A U S ? ) , o e d h t B t sA A ) ; SASL for authentication 16/20
  • 18. CQL: some ideas · Storage engine optimizations for CQL · Secondary index for collections · Server side functions · User defined types · ... 18/20
  • 19. User defined types CET TP ades( RAE YE drs sre tx, tet et zpcd it i_oe n, saetx, tt et poe sttx> hns e<et ) ; CET TBEues( RAE AL sr i ui PIAYKY d ud RMR E, nm tx, ae et adessmptx,ades drse a<et drs> ) ; ISR IT ues(d nm)VLE (3-a71 "yvi Lben"; NET NO sr i, ae AUS 244-6, Slan erse) UDT uesSTadess"ok]={ PAE sr E drse[wr" sre:'7 Mrnr Iln Bv #1' tet 77 aies sad ld 50, zpcd:944 i_oe 40, sae 'A, tt: C' 19/20 poe:{603960 } hns 5-8-00 }WEEi =244-6; HR d 3-a71 CL Q