18. Statements!
@doanduyhai
18
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)’;
19. Statements!
@doanduyhai
19
Parameterized statements
• same as plain statement
• pass bound values as bytes ☞ avoid ser/deser of values
INSERT INTO user(login, name, age) VALUES(?, ?, ?)’;
20. Java Driver!
@doanduyhai
20
Reference implementation
Base on asynchronous Netty library
Configurable policies
Query tracing support
Client-node compression & SSL
21. Maven dependency!
Available on Maven Central
@doanduyhai
21
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-core</artifactId>
<version>2.1.3</version>
</dependency>
depends on Netty, Guava, Metrics
22. Connect and Write!
@doanduyhai
22
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’)");
28. Old manual paging!
@doanduyhai
28
Some time you need to fetch all table content
Manual paging:
SELECT * FROM users WHERE token(login) >= token(<last_fetched_login>)
LIMIT 100;
36. Cassandra Unit!
@doanduyhai
36
• start an embedded Cassandra server
• useful for unit testing
• mature project, created at August 5th 2011
• designed around Thrift & Hector
• propose a JUnit rule for CQL
44. Achilles!
@doanduyhai
44
Why ?
• started in late 2012, when mapper module did not exists
• more involved and more features than the mapper module
• different annotations set (may converge)
46. Dirty Checking!
@doanduyhai
46
Dirty checking, why is it important ?
• 1 user ≈ 8 mutable fields
• × n denormalizations = n update combinations
• and not even counting multiple fields updates …
47. Dirty Checking!
@doanduyhai
47
• Are you going to manually generate n prepared statements for all
possible updates ?
• Or just use dynamic plain string statements and get some perf
penalty ?
54. RoadMap!
@doanduyhai
54
C* 2.1 user defined types (UDT)
Query-templates à-la Spring Data
Reactive ? (RxJava)
ElasticSearch integration (@olivierbourgain)