SlideShare uma empresa Scribd logo
1 de 28
DataStax Java Driver Unleashed!
CQL The new face of Cassandra
* CQL3
* Simpler Data Model using Denormalized Tables
* SQL-like Query Language
* Schema Definition
* CQL Native Protocol
* Introduced in Cassandra 1.2
* Designed for CQL3
* Thrift will keep being supported by Cassandra
* Cassandra lives closer to users and application
* Data model expresses your application intent
* Not made for generalizable queries
* Key to a successful project
CQL Data Model Overview
CQL3 Data Model
Data duplicated over several tables
CQL3 Query Language
comes with a new Data
Model abstraction
made of denormalized,
statically defined tables
CQL3 Data Model
gmason
user_id
1735
tweet_id
phenry
author
Give me liberty or give me death
body
Partition
Key
gmason 1742 gwashington I chopped down the cherry tree
ahamilton 1767 jadams A government of laws, not men
ahamilton 1794 gwashington I chopped down the cherry tree
Clustering
Key
Timeline Table
CQL3 Data Model
gmason
user_id
1735
tweet_id
phenry
author
Give me liberty or give me death
body
Partition
Key
gmason 1742 gwashington I chopped down the cherry tree
ahamilton 1767 jadams A government of laws, not men
ahamilton 1794 gwashington I chopped down the cherry tree
Clustering
Key
Timeline Table
CREATE TABLE timeline (
user_id varchar,
tweet_id timeuuid,
author varchar,
body varchar,
PRIMARY KEY (user_id, tweet_id));
CQL
DB API
CQL Native Protocol
CQL API OO API
Next Generation Driver
New Driver Architecture
* Reference Implementation
* Asynchronous architecture based on Netty
* Prepared Statements Support
* Automatic Fail-over
* Node Discovery
* Cassandra Tracing Support
* Tunable Policies
Java Driver Overview
Client
Without
Request Pipelining
Cassandra
Client Cassandra
With
Request Pipelining
Request Pipelining
Client
Without
Notifications
With
Notifications
Node
Node
Node
Client
Node
Node
Node
Notifications
Client
Thread
Node
Node
Node
Client
Thread
Client
Thread
Node
Driver
Asynchronous Architecture
1
2
3
4
5
6
Client
Thread
Node
Node
Node
Client
Thread
Client
Thread
Node
Driver
Asynchronous Architecture
contactPoints = {“10.0.0.1”,”10.0.0.2”}
keyspace = “videodb”
public VideoDbBasicImpl(List<String> contactPoints, String keyspace) {
cluster = Cluster
.builder()
.addContactPoints(
! contactPoints.toArray(new String[contactPoints.size()]))
.build();
session = cluster.connect(keyspace);
}
Creating a Basic Connection
public void setUserByUsingString(User user) {
StringBuffer userInsert = new StringBuffer(
"INSERT INTO users (username, firstname, lastname, email, password, created_date) VALUES (");
userInsert.append("'" + user.getUsername() + "'");
userInsert.append("'" + user.getFirstname() + "'");
userInsert.append("'" + user.getLastname() + "'");
userInsert.append("'" + user.getEmail() + "'");
userInsert.append("'" + user.getPassword() + "'");
userInsert.append("'" + user.getCreated_date().toString() + "'");
userInsert.append(")");
session.execute(userInsert.toString());
}
Basic write using insert
! public User getUserByUsernameUsingString(String username) {
! ! User user = new User();
! ! ResultSet rs = session.execute("SELECT * FROM users WHERE username = '"
! ! ! ! + username + "'");
! ! // A result set has Rows which can be iterated over
! ! for (Row row : rs) {
! ! ! user.setUsername(username);
! ! ! user.setFirstname(row.getString("firstname"));
! ! ! user.setLastname(row.getString("lastname"));
! ! ! user.setEmail(row.getString("email"));
! ! ! user.setPassword(row.getString("Password"));
! ! ! user.setCreated_date(row.getDate("created_date"));
! ! }
! ! return user;
! }
Basic Read using Select
public void setUserByPreparedStatement(User user) {
BoundStatement bs = setUser.bind();
bs.setString("username", user.getUsername());
bs.setString("firstname", user.getFirstname());
bs.setString("lastname", user.getLastname());
bs.setString("email", user.getEmail());
bs.setString("password", user.getPassword());
bs.setDate("created_date", user.getCreated_date());
! !
session.execute(bs);
}
Writing with Prepared Statements
public List<Video> getVideosByUsernameUsingAsyncRead(String username) {
BoundStatement bs = getVideosByUsernamePreparedStatement.bind();
List<ResultSetFuture> futures = new ArrayList<ResultSetFuture>();
List<Video> videos = new ArrayList<Video>();
bs.setString("username", username);
for (Row row : session.execute(bs)) {
futures.add(session.executeAsync(getVideoByIDPreparedStatement
.bind(row.getUUID("videoid"))));
}
for (ResultSetFuture future : futures) {
for (Row row : future.getUninterruptibly()) {
Video video = new Video();
video.setVideoid(row.getUUID("videoid"));
videos.add(video);
}
}
return videos;
}
Asynchronous Read
for (String tag : tags) {
BoundStatement bs = getVideosByTagPreparedStatement.bind(tag);
final ResultSetFuture future = session.executeAsync(bs);
future.addListener(new Runnable() {
public void run() {
for (Row row : future.getUninterruptibly()) {
UUID videoId = row.getUUID("videoid");
if (videoIds.putIfAbsent(videoId, PRESENT) == null) {
videoFutures.add(session
.executeAsync(getVideoByIDPreparedStatement
.bind(videoId)));
}
}
}
}, executor);
}
Performing a Read with a Listener
public Video getVideoByIdUsingQueryBuilder(String videoId) {
Video video = new Video();
Query query = select().all().from("videodb", "videos")
.where(eq("videoId", videoId)).limit(10);
query.setConsistencyLevel(ConsistencyLevel.ONE);
ResultSet rs = session.execute(query);
for (Row row : rs) {
video.setVideoid(row.getUUID("videoid"));
video.setVideoname(row.getString("videoName"));
video.setUsername(row.getString("username"));
video.setDescription(row.getString("description"));
}
return video;
}
Using the Query Builder
Load
Balancing
Policy
Node
Node
Node
Health
Monitor
Load Balancing and Failover
ReconnectionNotifications
Client
Retry
Policy
Response
Dispatcher
1 3
2
4
5
6
Node
Node
NodeClient
Datacenter B
Node
Node
Node
Client
Client
Client
Client
Client
Datacenter A
Local nodes are queried
first, if non are available,
the request will be sent
to a remote node.
Multi Datacenter Load Balancing
Multi Datacenter Load Balancing
Node
Node
Replica
Node
Client Node
NodeReplica
Replica
Nodes that own a
Replica of the data
being read or written
by the query will be
contacted first.
contactPoints = {“10.0.0.1”,”10.0.0.2”}
keyspace = “videodb”
public VideoDbBasicImpl(List<String> contactPoints, String keyspace) {
cluster = Cluster
.builder()
.addContactPoints(
! contactPoints.toArray(new String[contactPoints.size()]))
.withLoadBalancingPolicy(Policies.defaultLoadBalancingPolicy())
.build();
session = cluster.connect(keyspace);
}
Create your own policy!
Add a Load Balancing Policy
Client
If the requested
Consistency Level
cannot be reached
(QUORUM here), a
second request with a
lower CL is sent
automatically.
Node
Node Replica
Replica
Node
Replica
Downgrading Retry Policy
contactPoints = {“10.0.0.1”,”10.0.0.2”}
keyspace = “videodb”
public VideoDbBasicImpl(List<String> contactPoints, String keyspace) {
cluster = Cluster
.builder()
.addContactPoints(
! contactPoints.toArray(new String[contactPoints.size()]))
.withLoadBalancingPolicy(Policies.defaultLoadBalancingPolicy())
.withRetryPolicy(Policies.defaultRetryPolicy())
.build();
session = cluster.connect(keyspace);
}
Create your own policy!
Specify a Retry Policy
public enum Gender {
	 @EnumValue("m")
	 MALE,
	
	 @EnumValue("f")
	 FEMALE;
}
@Table(name = "user")
public class User {
	
	 @PartitionKey
	 @Column(name = "user_id")
	 private String userId;
	
	 private String name;
	
	 private String email;
	
	 private Gender gender;
}
Object Mapping
DevCenter an IDE for Developers
Questions ?

Mais conteúdo relacionado

Mais procurados

Php user groupmemcached
Php user groupmemcachedPhp user groupmemcached
Php user groupmemcached
Jason Anderson
 
Easy Scaling with Open Source Data Structures, by Talip Ozturk
Easy Scaling with Open Source Data Structures, by Talip OzturkEasy Scaling with Open Source Data Structures, by Talip Ozturk
Easy Scaling with Open Source Data Structures, by Talip Ozturk
ZeroTurnaround
 
Tokyo cassandra conference 2014
Tokyo cassandra conference 2014Tokyo cassandra conference 2014
Tokyo cassandra conference 2014
jbellis
 
Cassandra Summit 2013 Keynote
Cassandra Summit 2013 KeynoteCassandra Summit 2013 Keynote
Cassandra Summit 2013 Keynote
jbellis
 
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
 

Mais procurados (20)

Php user groupmemcached
Php user groupmemcachedPhp user groupmemcached
Php user groupmemcached
 
Ice mini guide
Ice mini guideIce mini guide
Ice mini guide
 
Apache ZooKeeper
Apache ZooKeeperApache ZooKeeper
Apache ZooKeeper
 
Easy Scaling with Open Source Data Structures, by Talip Ozturk
Easy Scaling with Open Source Data Structures, by Talip OzturkEasy Scaling with Open Source Data Structures, by Talip Ozturk
Easy Scaling with Open Source Data Structures, by Talip Ozturk
 
Cassandra summit keynote 2014
Cassandra summit keynote 2014Cassandra summit keynote 2014
Cassandra summit keynote 2014
 
Cassandra Summit 2015
Cassandra Summit 2015Cassandra Summit 2015
Cassandra Summit 2015
 
Cassandra 2.0 better, faster, stronger
Cassandra 2.0   better, faster, strongerCassandra 2.0   better, faster, stronger
Cassandra 2.0 better, faster, stronger
 
Hazelcast
HazelcastHazelcast
Hazelcast
 
DataStax NYC Java Meetup: Cassandra with Java
DataStax NYC Java Meetup: Cassandra with JavaDataStax NYC Java Meetup: Cassandra with Java
DataStax NYC Java Meetup: Cassandra with Java
 
Zookeeper
ZookeeperZookeeper
Zookeeper
 
Tokyo cassandra conference 2014
Tokyo cassandra conference 2014Tokyo cassandra conference 2014
Tokyo cassandra conference 2014
 
Cassandra Summit 2013 Keynote
Cassandra Summit 2013 KeynoteCassandra Summit 2013 Keynote
Cassandra Summit 2013 Keynote
 
Hazelcast
HazelcastHazelcast
Hazelcast
 
Cassandra Day NY 2014: Getting Started with the DataStax C# Driver
Cassandra Day NY 2014: Getting Started with the DataStax C# DriverCassandra Day NY 2014: Getting Started with the DataStax C# Driver
Cassandra Day NY 2014: Getting Started with the DataStax C# Driver
 
Clustering your Application with Hazelcast
Clustering your Application with HazelcastClustering your Application with Hazelcast
Clustering your Application with Hazelcast
 
Async servers and clients in Rest.li
Async servers and clients in Rest.liAsync servers and clients in Rest.li
Async servers and clients in Rest.li
 
Advanced Data Modeling with Apache Cassandra
Advanced Data Modeling with Apache CassandraAdvanced Data Modeling with Apache Cassandra
Advanced Data Modeling with Apache Cassandra
 
Cassandra 3.0 advanced preview
Cassandra 3.0 advanced previewCassandra 3.0 advanced preview
Cassandra 3.0 advanced preview
 
Hadoop Puzzlers
Hadoop PuzzlersHadoop Puzzlers
Hadoop Puzzlers
 
Apache Cassandra Lesson: Data Modelling and CQL3
Apache Cassandra Lesson: Data Modelling and CQL3Apache Cassandra Lesson: Data Modelling and CQL3
Apache Cassandra Lesson: Data Modelling and CQL3
 

Destaque (14)

Visual Essay with Soundtrack
Visual Essay with SoundtrackVisual Essay with Soundtrack
Visual Essay with Soundtrack
 
La règle du carmel
La règle du carmelLa règle du carmel
La règle du carmel
 
Jean de la Croix et Jonathan le Goéland
Jean de la Croix et Jonathan le GoélandJean de la Croix et Jonathan le Goéland
Jean de la Croix et Jonathan le Goéland
 
Jean de la croix, maître de prière
Jean de la croix, maître de prièreJean de la croix, maître de prière
Jean de la croix, maître de prière
 
Digital abstract
Digital abstractDigital abstract
Digital abstract
 
P5 ram instillation
P5 ram instillationP5 ram instillation
P5 ram instillation
 
Photoshop 网页教程实例讲解
Photoshop 网页教程实例讲解Photoshop 网页教程实例讲解
Photoshop 网页教程实例讲解
 
Software Performance Engineering-01
Software Performance Engineering-01Software Performance Engineering-01
Software Performance Engineering-01
 
Gustos Musicales
Gustos MusicalesGustos Musicales
Gustos Musicales
 
Final Version of the Poster
Final Version of the PosterFinal Version of the Poster
Final Version of the Poster
 
Profile
ProfileProfile
Profile
 
Cannistra carmel-aujourd'hui
Cannistra carmel-aujourd'huiCannistra carmel-aujourd'hui
Cannistra carmel-aujourd'hui
 
Report (Electromagnetic Password Door Lock System)
Report (Electromagnetic Password Door Lock System)Report (Electromagnetic Password Door Lock System)
Report (Electromagnetic Password Door Lock System)
 
Umesh Resume
Umesh ResumeUmesh Resume
Umesh Resume
 

Semelhante a Cassandra summit 2013 - DataStax Java Driver Unleashed!

Ipc: aidl sexy, not a curse
Ipc: aidl sexy, not a curseIpc: aidl sexy, not a curse
Ipc: aidl sexy, not a curse
Yonatan Levin
 
! Modernizr v2.0.6 httpwww.modernizr.com Copyri.docx
!  Modernizr v2.0.6  httpwww.modernizr.com   Copyri.docx!  Modernizr v2.0.6  httpwww.modernizr.com   Copyri.docx
! Modernizr v2.0.6 httpwww.modernizr.com Copyri.docx
MARRY7
 
Ebooktiketkapal
EbooktiketkapalEbooktiketkapal
Ebooktiketkapal
dhi her
 

Semelhante a Cassandra summit 2013 - DataStax Java Driver Unleashed! (20)

C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter
C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter
C* Summit EU 2013: Cassandra Made Simple with CQL Drivers and DevCenter
 
Java Configuration Deep Dive with Spring
Java Configuration Deep Dive with SpringJava Configuration Deep Dive with Spring
Java Configuration Deep Dive with Spring
 
Слава Бобик «NancyFx для самых маленьких»
Слава Бобик «NancyFx для самых маленьких»Слава Бобик «NancyFx для самых маленьких»
Слава Бобик «NancyFx для самых маленьких»
 
Hey Relational Developer, Let's Go Crazy (Patrick McFadin, DataStax) | Cassan...
Hey Relational Developer, Let's Go Crazy (Patrick McFadin, DataStax) | Cassan...Hey Relational Developer, Let's Go Crazy (Patrick McFadin, DataStax) | Cassan...
Hey Relational Developer, Let's Go Crazy (Patrick McFadin, DataStax) | Cassan...
 
GraphTour - Utilizing Powerful Extensions for Analytics & Operations
GraphTour - Utilizing Powerful Extensions for Analytics & OperationsGraphTour - Utilizing Powerful Extensions for Analytics & Operations
GraphTour - Utilizing Powerful Extensions for Analytics & Operations
 
Cassandra Summit 2014: Highly Scalable Web Application in the Cloud with Cass...
Cassandra Summit 2014: Highly Scalable Web Application in the Cloud with Cass...Cassandra Summit 2014: Highly Scalable Web Application in the Cloud with Cass...
Cassandra Summit 2014: Highly Scalable Web Application in the Cloud with Cass...
 
Utilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsUtilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and Operations
 
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and OperationsNeo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
Neo4j GraphTour: Utilizing Powerful Extensions for Analytics and Operations
 
Utilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and OperationsUtilizing Powerful Extensions for Analytics and Operations
Utilizing Powerful Extensions for Analytics and Operations
 
create-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdfcreate-netflix-clone-04-server-continued.pdf
create-netflix-clone-04-server-continued.pdf
 
API 통신, Retrofit 대신 Ktor 어떠신가요.pdf
API 통신, Retrofit 대신 Ktor 어떠신가요.pdfAPI 통신, Retrofit 대신 Ktor 어떠신가요.pdf
API 통신, Retrofit 대신 Ktor 어떠신가요.pdf
 
IPC: AIDL is sexy, not a curse
IPC: AIDL is sexy, not a curseIPC: AIDL is sexy, not a curse
IPC: AIDL is sexy, not a curse
 
Ipc: aidl sexy, not a curse
Ipc: aidl sexy, not a curseIpc: aidl sexy, not a curse
Ipc: aidl sexy, not a curse
 
Jersey Guice AOP
Jersey Guice AOPJersey Guice AOP
Jersey Guice AOP
 
Play 2.0
Play 2.0Play 2.0
Play 2.0
 
Protractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applicationsProtractor framework – how to make stable e2e tests for Angular applications
Protractor framework – how to make stable e2e tests for Angular applications
 
! Modernizr v2.0.6 httpwww.modernizr.com Copyri.docx
!  Modernizr v2.0.6  httpwww.modernizr.com   Copyri.docx!  Modernizr v2.0.6  httpwww.modernizr.com   Copyri.docx
! Modernizr v2.0.6 httpwww.modernizr.com Copyri.docx
 
Getting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NETGetting started with Elasticsearch and .NET
Getting started with Elasticsearch and .NET
 
Backbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVCBackbone.js — Introduction to client-side JavaScript MVC
Backbone.js — Introduction to client-side JavaScript MVC
 
Ebooktiketkapal
EbooktiketkapalEbooktiketkapal
Ebooktiketkapal
 

Mais de Michaël Figuière

NYC* Tech Day - New Cassandra Drivers in Depth
NYC* Tech Day - New Cassandra Drivers in DepthNYC* Tech Day - New Cassandra Drivers in Depth
NYC* Tech Day - New Cassandra Drivers in Depth
Michaël Figuière
 
Paris Cassandra Meetup - Overview of New Cassandra Drivers
Paris Cassandra Meetup - Overview of New Cassandra DriversParis Cassandra Meetup - Overview of New Cassandra Drivers
Paris Cassandra Meetup - Overview of New Cassandra Drivers
Michaël Figuière
 
ApacheCon Europe 2012 - Real Time Big Data in practice with Cassandra
ApacheCon Europe 2012 - Real Time Big Data in practice with CassandraApacheCon Europe 2012 - Real Time Big Data in practice with Cassandra
ApacheCon Europe 2012 - Real Time Big Data in practice with Cassandra
Michaël Figuière
 
NoSQL Matters 2012 - Real Time Big Data in practice with Cassandra
NoSQL Matters 2012 - Real Time Big Data in practice with CassandraNoSQL Matters 2012 - Real Time Big Data in practice with Cassandra
NoSQL Matters 2012 - Real Time Big Data in practice with Cassandra
Michaël Figuière
 
GTUG Nantes (Dec 2011) - BigTable et NoSQL
GTUG Nantes (Dec 2011) - BigTable et NoSQLGTUG Nantes (Dec 2011) - BigTable et NoSQL
GTUG Nantes (Dec 2011) - BigTable et NoSQL
Michaël Figuière
 
Duchess France (Nov 2011) - Atelier Apache Mahout
Duchess France (Nov 2011) - Atelier Apache MahoutDuchess France (Nov 2011) - Atelier Apache Mahout
Duchess France (Nov 2011) - Atelier Apache Mahout
Michaël Figuière
 
JUG Summer Camp (Sep 2011) - Les applications et architectures d’entreprise d...
JUG Summer Camp (Sep 2011) - Les applications et architectures d’entreprise d...JUG Summer Camp (Sep 2011) - Les applications et architectures d’entreprise d...
JUG Summer Camp (Sep 2011) - Les applications et architectures d’entreprise d...
Michaël Figuière
 
BreizhCamp (Jun 2011) - Haute disponibilité et élasticité avec Cassandra
BreizhCamp (Jun 2011) - Haute disponibilité et élasticité avec CassandraBreizhCamp (Jun 2011) - Haute disponibilité et élasticité avec Cassandra
BreizhCamp (Jun 2011) - Haute disponibilité et élasticité avec Cassandra
Michaël Figuière
 
Mix-IT (Apr 2011) - Intelligence Collective avec Apache Mahout
Mix-IT (Apr 2011) - Intelligence Collective avec Apache MahoutMix-IT (Apr 2011) - Intelligence Collective avec Apache Mahout
Mix-IT (Apr 2011) - Intelligence Collective avec Apache Mahout
Michaël Figuière
 
Xebia Knowledge Exchange (mars 2011) - Machine Learning with Apache Mahout
Xebia Knowledge Exchange (mars 2011) - Machine Learning with Apache MahoutXebia Knowledge Exchange (mars 2011) - Machine Learning with Apache Mahout
Xebia Knowledge Exchange (mars 2011) - Machine Learning with Apache Mahout
Michaël Figuière
 
Breizh JUG (mar 2011) - NoSQL : Des Grands du Web aux Entreprises
Breizh JUG (mar 2011) - NoSQL : Des Grands du Web aux EntreprisesBreizh JUG (mar 2011) - NoSQL : Des Grands du Web aux Entreprises
Breizh JUG (mar 2011) - NoSQL : Des Grands du Web aux Entreprises
Michaël Figuière
 
FOSDEM (feb 2011) - A real-time search engine with Lucene and S4
FOSDEM (feb 2011) -  A real-time search engine with Lucene and S4FOSDEM (feb 2011) -  A real-time search engine with Lucene and S4
FOSDEM (feb 2011) - A real-time search engine with Lucene and S4
Michaël Figuière
 
Xebia Knowledge Exchange (feb 2011) - Large Scale Web Development
Xebia Knowledge Exchange (feb 2011) - Large Scale Web DevelopmentXebia Knowledge Exchange (feb 2011) - Large Scale Web Development
Xebia Knowledge Exchange (feb 2011) - Large Scale Web Development
Michaël Figuière
 
Xebia Knowledge Exchange (jan 2011) - Trends in Enterprise Applications Archi...
Xebia Knowledge Exchange (jan 2011) - Trends in Enterprise Applications Archi...Xebia Knowledge Exchange (jan 2011) - Trends in Enterprise Applications Archi...
Xebia Knowledge Exchange (jan 2011) - Trends in Enterprise Applications Archi...
Michaël Figuière
 
Lorraine JUG (dec 2010) - NoSQL, des grands du Web aux entreprises
Lorraine JUG (dec 2010) - NoSQL, des grands du Web aux entreprisesLorraine JUG (dec 2010) - NoSQL, des grands du Web aux entreprises
Lorraine JUG (dec 2010) - NoSQL, des grands du Web aux entreprises
Michaël Figuière
 
Tours JUG (oct 2010) - NoSQL, des grands du Web aux entreprises
Tours JUG (oct 2010) - NoSQL, des grands du Web aux entreprisesTours JUG (oct 2010) - NoSQL, des grands du Web aux entreprises
Tours JUG (oct 2010) - NoSQL, des grands du Web aux entreprises
Michaël Figuière
 
Paris JUG (sept 2010) - NoSQL : Des concepts à la réalité
Paris JUG (sept 2010) - NoSQL : Des concepts à la réalitéParis JUG (sept 2010) - NoSQL : Des concepts à la réalité
Paris JUG (sept 2010) - NoSQL : Des concepts à la réalité
Michaël Figuière
 
Xebia Knowledge Exchange (mars 2010) - Lucene : From theory to real world
Xebia Knowledge Exchange (mars 2010) - Lucene : From theory to real worldXebia Knowledge Exchange (mars 2010) - Lucene : From theory to real world
Xebia Knowledge Exchange (mars 2010) - Lucene : From theory to real world
Michaël Figuière
 
Xebia Knowledge Exchange (may 2010) - NoSQL : Using the right tool for the ri...
Xebia Knowledge Exchange (may 2010) - NoSQL : Using the right tool for the ri...Xebia Knowledge Exchange (may 2010) - NoSQL : Using the right tool for the ri...
Xebia Knowledge Exchange (may 2010) - NoSQL : Using the right tool for the ri...
Michaël Figuière
 

Mais de Michaël Figuière (20)

EclipseCon - Building an IDE for Apache Cassandra
EclipseCon - Building an IDE for Apache CassandraEclipseCon - Building an IDE for Apache Cassandra
EclipseCon - Building an IDE for Apache Cassandra
 
NYC* Tech Day - New Cassandra Drivers in Depth
NYC* Tech Day - New Cassandra Drivers in DepthNYC* Tech Day - New Cassandra Drivers in Depth
NYC* Tech Day - New Cassandra Drivers in Depth
 
Paris Cassandra Meetup - Overview of New Cassandra Drivers
Paris Cassandra Meetup - Overview of New Cassandra DriversParis Cassandra Meetup - Overview of New Cassandra Drivers
Paris Cassandra Meetup - Overview of New Cassandra Drivers
 
ApacheCon Europe 2012 - Real Time Big Data in practice with Cassandra
ApacheCon Europe 2012 - Real Time Big Data in practice with CassandraApacheCon Europe 2012 - Real Time Big Data in practice with Cassandra
ApacheCon Europe 2012 - Real Time Big Data in practice with Cassandra
 
NoSQL Matters 2012 - Real Time Big Data in practice with Cassandra
NoSQL Matters 2012 - Real Time Big Data in practice with CassandraNoSQL Matters 2012 - Real Time Big Data in practice with Cassandra
NoSQL Matters 2012 - Real Time Big Data in practice with Cassandra
 
GTUG Nantes (Dec 2011) - BigTable et NoSQL
GTUG Nantes (Dec 2011) - BigTable et NoSQLGTUG Nantes (Dec 2011) - BigTable et NoSQL
GTUG Nantes (Dec 2011) - BigTable et NoSQL
 
Duchess France (Nov 2011) - Atelier Apache Mahout
Duchess France (Nov 2011) - Atelier Apache MahoutDuchess France (Nov 2011) - Atelier Apache Mahout
Duchess France (Nov 2011) - Atelier Apache Mahout
 
JUG Summer Camp (Sep 2011) - Les applications et architectures d’entreprise d...
JUG Summer Camp (Sep 2011) - Les applications et architectures d’entreprise d...JUG Summer Camp (Sep 2011) - Les applications et architectures d’entreprise d...
JUG Summer Camp (Sep 2011) - Les applications et architectures d’entreprise d...
 
BreizhCamp (Jun 2011) - Haute disponibilité et élasticité avec Cassandra
BreizhCamp (Jun 2011) - Haute disponibilité et élasticité avec CassandraBreizhCamp (Jun 2011) - Haute disponibilité et élasticité avec Cassandra
BreizhCamp (Jun 2011) - Haute disponibilité et élasticité avec Cassandra
 
Mix-IT (Apr 2011) - Intelligence Collective avec Apache Mahout
Mix-IT (Apr 2011) - Intelligence Collective avec Apache MahoutMix-IT (Apr 2011) - Intelligence Collective avec Apache Mahout
Mix-IT (Apr 2011) - Intelligence Collective avec Apache Mahout
 
Xebia Knowledge Exchange (mars 2011) - Machine Learning with Apache Mahout
Xebia Knowledge Exchange (mars 2011) - Machine Learning with Apache MahoutXebia Knowledge Exchange (mars 2011) - Machine Learning with Apache Mahout
Xebia Knowledge Exchange (mars 2011) - Machine Learning with Apache Mahout
 
Breizh JUG (mar 2011) - NoSQL : Des Grands du Web aux Entreprises
Breizh JUG (mar 2011) - NoSQL : Des Grands du Web aux EntreprisesBreizh JUG (mar 2011) - NoSQL : Des Grands du Web aux Entreprises
Breizh JUG (mar 2011) - NoSQL : Des Grands du Web aux Entreprises
 
FOSDEM (feb 2011) - A real-time search engine with Lucene and S4
FOSDEM (feb 2011) -  A real-time search engine with Lucene and S4FOSDEM (feb 2011) -  A real-time search engine with Lucene and S4
FOSDEM (feb 2011) - A real-time search engine with Lucene and S4
 
Xebia Knowledge Exchange (feb 2011) - Large Scale Web Development
Xebia Knowledge Exchange (feb 2011) - Large Scale Web DevelopmentXebia Knowledge Exchange (feb 2011) - Large Scale Web Development
Xebia Knowledge Exchange (feb 2011) - Large Scale Web Development
 
Xebia Knowledge Exchange (jan 2011) - Trends in Enterprise Applications Archi...
Xebia Knowledge Exchange (jan 2011) - Trends in Enterprise Applications Archi...Xebia Knowledge Exchange (jan 2011) - Trends in Enterprise Applications Archi...
Xebia Knowledge Exchange (jan 2011) - Trends in Enterprise Applications Archi...
 
Lorraine JUG (dec 2010) - NoSQL, des grands du Web aux entreprises
Lorraine JUG (dec 2010) - NoSQL, des grands du Web aux entreprisesLorraine JUG (dec 2010) - NoSQL, des grands du Web aux entreprises
Lorraine JUG (dec 2010) - NoSQL, des grands du Web aux entreprises
 
Tours JUG (oct 2010) - NoSQL, des grands du Web aux entreprises
Tours JUG (oct 2010) - NoSQL, des grands du Web aux entreprisesTours JUG (oct 2010) - NoSQL, des grands du Web aux entreprises
Tours JUG (oct 2010) - NoSQL, des grands du Web aux entreprises
 
Paris JUG (sept 2010) - NoSQL : Des concepts à la réalité
Paris JUG (sept 2010) - NoSQL : Des concepts à la réalitéParis JUG (sept 2010) - NoSQL : Des concepts à la réalité
Paris JUG (sept 2010) - NoSQL : Des concepts à la réalité
 
Xebia Knowledge Exchange (mars 2010) - Lucene : From theory to real world
Xebia Knowledge Exchange (mars 2010) - Lucene : From theory to real worldXebia Knowledge Exchange (mars 2010) - Lucene : From theory to real world
Xebia Knowledge Exchange (mars 2010) - Lucene : From theory to real world
 
Xebia Knowledge Exchange (may 2010) - NoSQL : Using the right tool for the ri...
Xebia Knowledge Exchange (may 2010) - NoSQL : Using the right tool for the ri...Xebia Knowledge Exchange (may 2010) - NoSQL : Using the right tool for the ri...
Xebia Knowledge Exchange (may 2010) - NoSQL : Using the right tool for the ri...
 

Ú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
 

Último (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
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
 
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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 

Cassandra summit 2013 - DataStax Java Driver Unleashed!

  • 1. DataStax Java Driver Unleashed!
  • 2. CQL The new face of Cassandra * CQL3 * Simpler Data Model using Denormalized Tables * SQL-like Query Language * Schema Definition * CQL Native Protocol * Introduced in Cassandra 1.2 * Designed for CQL3 * Thrift will keep being supported by Cassandra
  • 3. * Cassandra lives closer to users and application * Data model expresses your application intent * Not made for generalizable queries * Key to a successful project CQL Data Model Overview
  • 4. CQL3 Data Model Data duplicated over several tables CQL3 Query Language comes with a new Data Model abstraction made of denormalized, statically defined tables
  • 5. CQL3 Data Model gmason user_id 1735 tweet_id phenry author Give me liberty or give me death body Partition Key gmason 1742 gwashington I chopped down the cherry tree ahamilton 1767 jadams A government of laws, not men ahamilton 1794 gwashington I chopped down the cherry tree Clustering Key Timeline Table
  • 6. CQL3 Data Model gmason user_id 1735 tweet_id phenry author Give me liberty or give me death body Partition Key gmason 1742 gwashington I chopped down the cherry tree ahamilton 1767 jadams A government of laws, not men ahamilton 1794 gwashington I chopped down the cherry tree Clustering Key Timeline Table CREATE TABLE timeline ( user_id varchar, tweet_id timeuuid, author varchar, body varchar, PRIMARY KEY (user_id, tweet_id)); CQL
  • 7. DB API CQL Native Protocol CQL API OO API Next Generation Driver New Driver Architecture
  • 8. * Reference Implementation * Asynchronous architecture based on Netty * Prepared Statements Support * Automatic Fail-over * Node Discovery * Cassandra Tracing Support * Tunable Policies Java Driver Overview
  • 13. contactPoints = {“10.0.0.1”,”10.0.0.2”} keyspace = “videodb” public VideoDbBasicImpl(List<String> contactPoints, String keyspace) { cluster = Cluster .builder() .addContactPoints( ! contactPoints.toArray(new String[contactPoints.size()])) .build(); session = cluster.connect(keyspace); } Creating a Basic Connection
  • 14. public void setUserByUsingString(User user) { StringBuffer userInsert = new StringBuffer( "INSERT INTO users (username, firstname, lastname, email, password, created_date) VALUES ("); userInsert.append("'" + user.getUsername() + "'"); userInsert.append("'" + user.getFirstname() + "'"); userInsert.append("'" + user.getLastname() + "'"); userInsert.append("'" + user.getEmail() + "'"); userInsert.append("'" + user.getPassword() + "'"); userInsert.append("'" + user.getCreated_date().toString() + "'"); userInsert.append(")"); session.execute(userInsert.toString()); } Basic write using insert
  • 15. ! public User getUserByUsernameUsingString(String username) { ! ! User user = new User(); ! ! ResultSet rs = session.execute("SELECT * FROM users WHERE username = '" ! ! ! ! + username + "'"); ! ! // A result set has Rows which can be iterated over ! ! for (Row row : rs) { ! ! ! user.setUsername(username); ! ! ! user.setFirstname(row.getString("firstname")); ! ! ! user.setLastname(row.getString("lastname")); ! ! ! user.setEmail(row.getString("email")); ! ! ! user.setPassword(row.getString("Password")); ! ! ! user.setCreated_date(row.getDate("created_date")); ! ! } ! ! return user; ! } Basic Read using Select
  • 16. public void setUserByPreparedStatement(User user) { BoundStatement bs = setUser.bind(); bs.setString("username", user.getUsername()); bs.setString("firstname", user.getFirstname()); bs.setString("lastname", user.getLastname()); bs.setString("email", user.getEmail()); bs.setString("password", user.getPassword()); bs.setDate("created_date", user.getCreated_date()); ! ! session.execute(bs); } Writing with Prepared Statements
  • 17. public List<Video> getVideosByUsernameUsingAsyncRead(String username) { BoundStatement bs = getVideosByUsernamePreparedStatement.bind(); List<ResultSetFuture> futures = new ArrayList<ResultSetFuture>(); List<Video> videos = new ArrayList<Video>(); bs.setString("username", username); for (Row row : session.execute(bs)) { futures.add(session.executeAsync(getVideoByIDPreparedStatement .bind(row.getUUID("videoid")))); } for (ResultSetFuture future : futures) { for (Row row : future.getUninterruptibly()) { Video video = new Video(); video.setVideoid(row.getUUID("videoid")); videos.add(video); } } return videos; } Asynchronous Read
  • 18. for (String tag : tags) { BoundStatement bs = getVideosByTagPreparedStatement.bind(tag); final ResultSetFuture future = session.executeAsync(bs); future.addListener(new Runnable() { public void run() { for (Row row : future.getUninterruptibly()) { UUID videoId = row.getUUID("videoid"); if (videoIds.putIfAbsent(videoId, PRESENT) == null) { videoFutures.add(session .executeAsync(getVideoByIDPreparedStatement .bind(videoId))); } } } }, executor); } Performing a Read with a Listener
  • 19. public Video getVideoByIdUsingQueryBuilder(String videoId) { Video video = new Video(); Query query = select().all().from("videodb", "videos") .where(eq("videoId", videoId)).limit(10); query.setConsistencyLevel(ConsistencyLevel.ONE); ResultSet rs = session.execute(query); for (Row row : rs) { video.setVideoid(row.getUUID("videoid")); video.setVideoname(row.getString("videoName")); video.setUsername(row.getString("username")); video.setDescription(row.getString("description")); } return video; } Using the Query Builder
  • 20. Load Balancing Policy Node Node Node Health Monitor Load Balancing and Failover ReconnectionNotifications Client Retry Policy Response Dispatcher 1 3 2 4 5 6
  • 21. Node Node NodeClient Datacenter B Node Node Node Client Client Client Client Client Datacenter A Local nodes are queried first, if non are available, the request will be sent to a remote node. Multi Datacenter Load Balancing
  • 22. Multi Datacenter Load Balancing Node Node Replica Node Client Node NodeReplica Replica Nodes that own a Replica of the data being read or written by the query will be contacted first.
  • 23. contactPoints = {“10.0.0.1”,”10.0.0.2”} keyspace = “videodb” public VideoDbBasicImpl(List<String> contactPoints, String keyspace) { cluster = Cluster .builder() .addContactPoints( ! contactPoints.toArray(new String[contactPoints.size()])) .withLoadBalancingPolicy(Policies.defaultLoadBalancingPolicy()) .build(); session = cluster.connect(keyspace); } Create your own policy! Add a Load Balancing Policy
  • 24. Client If the requested Consistency Level cannot be reached (QUORUM here), a second request with a lower CL is sent automatically. Node Node Replica Replica Node Replica Downgrading Retry Policy
  • 25. contactPoints = {“10.0.0.1”,”10.0.0.2”} keyspace = “videodb” public VideoDbBasicImpl(List<String> contactPoints, String keyspace) { cluster = Cluster .builder() .addContactPoints( ! contactPoints.toArray(new String[contactPoints.size()])) .withLoadBalancingPolicy(Policies.defaultLoadBalancingPolicy()) .withRetryPolicy(Policies.defaultRetryPolicy()) .build(); session = cluster.connect(keyspace); } Create your own policy! Specify a Retry Policy
  • 26. public enum Gender { @EnumValue("m") MALE, @EnumValue("f") FEMALE; } @Table(name = "user") public class User { @PartitionKey @Column(name = "user_id") private String userId; private String name; private String email; private Gender gender; } Object Mapping
  • 27. DevCenter an IDE for Developers