17. Statements!
@doanduyhai
17
Prepared statements
• avoid parsing overhead
• query structure should be known ahead of time
• bound values
• named parameters
INSERT INTO user(login, name, age) VALUES(?, ?, ?)’;
INSERT INTO user(login, name, age) VALUES(:login, :name, :age)’;
18. Statements!
@doanduyhai
18
Parameterized statements
• same as plain statement
• pass bound values as bytes ☞ avoid ser/deser of values
INSERT INTO user(login, name, age) VALUES(?, ?, ?)’;
19. Java Driver!
@doanduyhai
19
Reference implementation
Base on asynchronous Netty library
Configurable policies
Query tracing support
Client-node compression & SSL
20. Maven dependency!
Available on Maven Central
@doanduyhai
20
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>2.1.1</version>
</dependency>
depends on Netty, Guava, Metrics
21. Connect and Write!
@doanduyhai
21
Cluster cluster = Cluster.builder()
.addContactPoints("127.0.0.1", “another-host").build();
seed nodes (IP or DNS name)
Session session = cluster.connect("my_keyspace");
session.execute("INSERT INTO user (user_id, name, email)
VALUES (12345, 'johndoe', 'john_doe@fiction.com’)");
32. Old manual paging!
@doanduyhai
32
Some time you need to fetch all table content
Manual paging:
SELECT * FROM users WHERE token(login) >= token(<last_fetched_login>)
LIMIT 100;
40. Training Day | December 3rd
Beginner Track
• Introduction to Cassandra
• Introduction to Spark, Shark, Scala and
Cassandra
Advanced Track
• Data Modeling
• Performance Tuning
Conference Day | December 4th
Cassandra Summit Europe 2014 will be the single
largest gathering of Cassandra users in Europe.
Learn how the world's most successful companies are
transforming their businesses and growing faster than
ever using Apache Cassandra.
http://bit.ly/cassandrasummit2014
@doanduyhai Company Confidential 40