SlideShare a Scribd company logo
New Cassandra Drivers in
Depth

Michaël Figuière
@mfiguiere
Speaker

                 Michaël Figuière




                      @mfiguiere


©2012 DataStax                      2
CQL: the new face of Cassandra

     • CQL 3
           •     Simpler Data Model using denormalized Tables
           •     SQL-like query language
           •     Schema definition


     • CQL Binary Protocol
           •     Introduced in Cassandra 1.2 (CASSANDRA-2478)
           •     Designed for CQL 3
           •     Opens doors for Streaming, Notifications, ...
           •     Thrift will keep being supported by Cassandra
©2012 DataStax                                                   3
CQL3 Denormalized Model
           CQL3 Query Language comes with a new Data Model abstraction made of
                          denormalized, statically defined tables




                           Data duplicated over several tables

©2012 DataStax                                                                   4
CQL3 Data Model
    Timeline Table
         user_id     tweet_id       author                       body
         gmason        1735         phenry      Give me liberty or give me death
         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

       Partition     Clustering
         Key            Key




©2012 DataStax                                                                     5
CQL3 Data Model
    Timeline Table
         user_id     tweet_id     author                       body
         gmason        1735       phenry      Give me liberty or give me death
         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


    CQL
                   CREATE TABLE timeline (
                            user_id varchar,
                            tweet_id timeuuid,
                            author varchar,
                            body varchar,
                            PRIMARY KEY (user_id, tweet_id));


©2012 DataStax                                                                   6
CQL3 Data Model
    Timeline Table
         user_id         tweet_id        author                            body
         gmason            1735          phenry       Give me liberty or give me death
         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



Timeline Physical Layout
                 [1735, author]       [1735, body]        [1742, author]          [1742, body]
   gmason
                 gwashington      I chopped down the...      phenry        Give me liberty or give...
                 [1767, author]       [1767, body]        [1794, author]          [1794, body]
 ahamilton
                 gwashington      I chopped down the...      jadams        A government of laws...


©2012 DataStax                                                                                          7
Current Drivers Architecture


      CQL API             Thrift API             OO API                        DB API


                         Thrift RPC                                         Thrift RPC


                          Client Library                                      CQL Driver



 * This is a simplified view of drivers architecture. Details vary from one language to another.
©2012 DataStax                                                                                    8
New Drivers Architecture


                 DB API                   CQL API                    OO API


                                CQL Native Protocol


                                    Next Generation Driver



 * This is a simplified view of drivers architecture. Details vary from one language to another.
©2012 DataStax                                                                                    9
DataStax Java Driver
  • Reference Implementation
  • Asynchronous architecture based on Netty
  • Prepared Statements Support
  • Automatic Fail-over
  • Node Discovery
  • Cassandra Tracing Support
  • Tunable policies
           •     LoadBalancingPolicy
           •     ReconnectionPolicy
           •
©2012 DataStax
                 RetryPolicy
                                               10
Request Pipelining
                 Client   Cassandra




                                               Without
                                      Request Pipelining

                                                  With
                 Client   Cassandra   Request Pipelining




©2012 DataStax                                        11
Notifications
                                 Node

                 Client

                          Node
                                        Node


                                              Without
                                           Notifications

                                                  With
                                           Notifications

                                 Node

                 Client

                          Node
                                        Node

©2012 DataStax                                       12
Asynchronous Architecture

                              Node
            Client
            Thread
                              Node

            Client
                     Driver
            Thread
                              Node


            Client
            Thread
                              Node




©2012 DataStax                       13
Asynchronous Architecture

                                                  Node
            Client
            Thread       6

                     1                            Node

            Client
                             Driver       2
            Thread                            3
                                                  Node
                                      5
                                              4
            Client
            Thread
                                                  Node




©2012 DataStax                                           14
LoadBalancingPolicy


                 public interface LoadBalancingPolicy {

                     HostDistance distance(Host host);

                     Iterator<Host> newQueryPlan(Query query);

                     [...]

                 }




©2012 DataStax                                                   15
DCAwareRoundRobinPolicy
                                      Datacenter A
      Local nodes are
      queried first, if non   Client              Node
      are available, the
      request will be sent   Client                     Node
      to a remote node.
                                                 Node
                             Client



                             Client              Node


                             Client                     Node


                                                 Node
                             Client

                                      Datacenter B
©2012 DataStax                                                 16
TokenAwarePolicy
      Nodes that own a
      Replica of the data
      being read or written
      by the query will be
      contacted first.
                                             Replica
                                             Node       Node




                        Client   Replica
                                 Node
                                                               Node




                                           Replica
                                                       Node


©2012 DataStax                                                        17
RetryPolicy
public interface RetryPolicy {

      RetryDecision onReadTimeout(Query query, ConsistencyLevel cl, [...] );

      RetryDecision onWriteTimeout(Query query, ConsistencyLevel cl, [...] );

      RetryDecision onUnavailable(Query query, ConsistencyLevel cl, [...] );

      public static class RetryDecision {
           public static enum Type { RETRY, RETHROW, IGNORE };

                 private final Type type;
                 private final ConsistencyLevel retryCL;

                 [...]
      }
}


©2012 DataStax                                                             18
Downgrading Consistency
      If the requested
      Consistency Level
      cannot be reached
      (QUORUM here), a
      second request with a
      lower CL is sent
      automatically.                    Node     Replica




                       Client   Node
                                                           Replica




                                       Node
                                               Replica


©2012 DataStax                                                       19
Connect and Write

       Cluster cluster = Cluster.builder()
                         .addContactPoints("10.0.0.1", "10.0.0.2")
                         .build();

       Session session = cluster.connect("myKeyspace");

       session.execute(
          "INSERT INTO user (user_id, name, email)
           VALUES (12345, 'johndoe', 'john@doe.com')"
       );




©2012 DataStax                                                       20
Read

             ResultSet rs = session.execute("SELECT * FROM test");

             List<Row> rows = rs.all();

             for (Row row : rows) {

                 String userId = row.getString("user_id");
                 String name = row.getString("name");
                 String email = row.getString("email");
             }




©2012 DataStax                                                       21
Asynchronous Read

            ResultSetFuture future =
               session.executeAsync("SELECT * FROM test");

            for (Row row : future.get()) {

                 String userId = row.getString("user_id");
                 String name = row.getString("name");
                 String email = row.getString("email");
            }




©2012 DataStax                                               22
Prepared Statements
         PreparedStatement ps =
            session.prepare("SELECT * FROM users WHERE id = ?");

         BoundStatement bs =
            session.execute(ps.bind("123")).one().getInt("age");

         bs.setString("k");

         int age = session.execute(bs).one().getInt("age");




         age = session.execute(ps.bind("123")).one().getInt("age");




©2012 DataStax                                                        23
Query Builder
      String query = "SELECT a,b,"C"
                      FROM foo
                      WHERE a IN (127.0.0.1,127.0.0.3)
                      AND "C"='foo'
                      ORDER BY a ASC,b DESC LIMIT 42;";



      Query select =
         select("a", "b", quote("C")).from("foo")
         .where(in("a", InetAddress.getByName("127.0.0.1"),
                        InetAddress.getByName("127.0.0.3")))
         .and(eq(quote("C"), "foo"))
         .orderBy(asc("a"), desc("b"))
         .limit(42);




©2012 DataStax                                                 24
Object Mapping
     @Table(name = "user")
     public class User {           public enum Gender {
     	
     	 @PartitionKey               	   @EnumValue("m")
     	 @Column(name = "user_id")   	   MALE,
     	 private String userId;      	
     	                             	   @EnumValue("f")
     	 private String name;        	   FEMALE;
     	                             }
     	 private String email;
     	
     	 private Gender gender;
     }



©2012 DataStax                                            25
Inheritance
@Table(name = "catalog")
@Inheritance(
                                          @InheritanceValue("tv")
  subClasses = {Phone.class, TV.class},
                                          public class TV
  column = "product_type"
                                          extends Product {
)
public abstract class Product {
                                          	 private float size;
                                          }
	     @Column(name = "product_id")
	     private String productId;
	
	     private float price;
	
	     private String vendor;
	
	     private String model;

}
©2012 DataStax                                                    26
Betas now available!


      https://github.com/datastax/
Stay Tuned!

          blog.datastax.com
          @mfiguiere

More Related Content

PDF
Paris Cassandra Meetup - Cassandra for Developers
PDF
EclipseCon - Building an IDE for Apache Cassandra
PDF
ChtiJUG - Cassandra 2.0
PDF
YaJug - Cassandra for Java Developers
PDF
Geneva JUG - Cassandra for Java Developers
PDF
Paris Cassandra Meetup - Overview of New Cassandra Drivers
PDF
In-depth caching in Varnish - GOG Varnish Meetup, march 2019
PPTX
Apache zookeeper 101
Paris Cassandra Meetup - Cassandra for Developers
EclipseCon - Building an IDE for Apache Cassandra
ChtiJUG - Cassandra 2.0
YaJug - Cassandra for Java Developers
Geneva JUG - Cassandra for Java Developers
Paris Cassandra Meetup - Overview of New Cassandra Drivers
In-depth caching in Varnish - GOG Varnish Meetup, march 2019
Apache zookeeper 101

What's hot (20)

PDF
06 response-headers
PDF
Hazelcast
PDF
How Prometheus Store the Data
PPTX
Hazelcast Essentials
PPTX
DataStax | Data Science with DataStax Enterprise (Brian Hess) | Cassandra Sum...
PDF
Cassandra 3.0 advanced preview
PPTX
Introduction to Apache ZooKeeper
PPTX
Using Spark to Load Oracle Data into Cassandra
PDF
Bulk Loading into Cassandra
PPTX
Spark Cassandra Connector: Past, Present and Furure
PDF
Kerberizing spark. Spark Summit east
PPTX
SCWCD : Thread safe servlets : CHAP : 8
PPTX
Hazelcast
PDF
Apache Cassandra multi-datacenter essentials
ODP
Meetup cassandra for_java_cql
PDF
Introduction to data modeling with apache cassandra
PPTX
Think Distributed: The Hazelcast Way
PPTX
Understanding DSE Search by Matt Stump
PPTX
Apache cassandra v4.0
PDF
Storing time series data with Apache Cassandra
06 response-headers
Hazelcast
How Prometheus Store the Data
Hazelcast Essentials
DataStax | Data Science with DataStax Enterprise (Brian Hess) | Cassandra Sum...
Cassandra 3.0 advanced preview
Introduction to Apache ZooKeeper
Using Spark to Load Oracle Data into Cassandra
Bulk Loading into Cassandra
Spark Cassandra Connector: Past, Present and Furure
Kerberizing spark. Spark Summit east
SCWCD : Thread safe servlets : CHAP : 8
Hazelcast
Apache Cassandra multi-datacenter essentials
Meetup cassandra for_java_cql
Introduction to data modeling with apache cassandra
Think Distributed: The Hazelcast Way
Understanding DSE Search by Matt Stump
Apache cassandra v4.0
Storing time series data with Apache Cassandra
Ad

Similar to NYC* Tech Day - New Cassandra Drivers in Depth (20)

PPT
Toronto jaspersoft meetup
PDF
On Cassandra Development: Past, Present and Future
PPTX
DataStax NYC Java Meetup: Cassandra with Java
PDF
Post-relational databases: What's wrong with web development?
PPTX
An Overview of Apache Cassandra
PDF
Apache Con NA 2013 - Cassandra Internals
PDF
HBase Client APIs (for webapps?)
PDF
State of Cassandra 2012
PPTX
Software architecture for data applications
PDF
Cassandra at High Performance Transaction Systems 2011
PDF
Post-relational databases: What's wrong with web development? v3
PDF
Apache Cassandra in Bangalore - Cassandra Internals and Performance
PDF
Python & Cassandra - Best Friends
PDF
Cassandra Day Denver 2014: Python & Cassandra Best Friends
PPTX
Concurrency Constructs Overview
PDF
Datastax day 2016 introduction to apache cassandra
PDF
Going native with Apache Cassandra
PDF
NYC Cassandra Day - Java Intro
PPTX
Cassandra and Storm at Health Market Sceince
PPT
Scaling web applications with cassandra presentation
Toronto jaspersoft meetup
On Cassandra Development: Past, Present and Future
DataStax NYC Java Meetup: Cassandra with Java
Post-relational databases: What's wrong with web development?
An Overview of Apache Cassandra
Apache Con NA 2013 - Cassandra Internals
HBase Client APIs (for webapps?)
State of Cassandra 2012
Software architecture for data applications
Cassandra at High Performance Transaction Systems 2011
Post-relational databases: What's wrong with web development? v3
Apache Cassandra in Bangalore - Cassandra Internals and Performance
Python & Cassandra - Best Friends
Cassandra Day Denver 2014: Python & Cassandra Best Friends
Concurrency Constructs Overview
Datastax day 2016 introduction to apache cassandra
Going native with Apache Cassandra
NYC Cassandra Day - Java Intro
Cassandra and Storm at Health Market Sceince
Scaling web applications with cassandra presentation
Ad

More from Michaël Figuière (18)

PDF
Cassandra summit 2013 - DataStax Java Driver Unleashed!
PDF
ApacheCon Europe 2012 - Real Time Big Data in practice with Cassandra
PDF
NoSQL Matters 2012 - Real Time Big Data in practice with Cassandra
PDF
GTUG Nantes (Dec 2011) - BigTable et NoSQL
PDF
Duchess France (Nov 2011) - Atelier Apache Mahout
PDF
JUG Summer Camp (Sep 2011) - Les applications et architectures d’entreprise d...
PDF
BreizhCamp (Jun 2011) - Haute disponibilité et élasticité avec Cassandra
PDF
Mix-IT (Apr 2011) - Intelligence Collective avec Apache Mahout
PDF
Xebia Knowledge Exchange (mars 2011) - Machine Learning with Apache Mahout
PDF
Breizh JUG (mar 2011) - NoSQL : Des Grands du Web aux Entreprises
PDF
FOSDEM (feb 2011) - A real-time search engine with Lucene and S4
PDF
Xebia Knowledge Exchange (feb 2011) - Large Scale Web Development
PDF
Xebia Knowledge Exchange (jan 2011) - Trends in Enterprise Applications Archi...
PDF
Lorraine JUG (dec 2010) - NoSQL, des grands du Web aux entreprises
PDF
Tours JUG (oct 2010) - NoSQL, des grands du Web aux entreprises
PPTX
Paris JUG (sept 2010) - NoSQL : Des concepts à la réalité
PPTX
Xebia Knowledge Exchange (mars 2010) - Lucene : From theory to real world
PPTX
Xebia Knowledge Exchange (may 2010) - NoSQL : Using the right tool for the ri...
Cassandra summit 2013 - DataStax Java Driver Unleashed!
ApacheCon Europe 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
Duchess France (Nov 2011) - Atelier Apache Mahout
JUG Summer Camp (Sep 2011) - Les applications et architectures d’entreprise d...
BreizhCamp (Jun 2011) - Haute disponibilité et élasticité avec Cassandra
Mix-IT (Apr 2011) - Intelligence Collective avec Apache Mahout
Xebia Knowledge Exchange (mars 2011) - Machine Learning with Apache Mahout
Breizh JUG (mar 2011) - NoSQL : Des Grands du Web aux Entreprises
FOSDEM (feb 2011) - A real-time search engine with Lucene and S4
Xebia Knowledge Exchange (feb 2011) - Large Scale Web Development
Xebia Knowledge Exchange (jan 2011) - Trends in Enterprise Applications Archi...
Lorraine JUG (dec 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é
Xebia Knowledge Exchange (mars 2010) - Lucene : From theory to real world
Xebia Knowledge Exchange (may 2010) - NoSQL : Using the right tool for the ri...

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Approach and Philosophy of On baking technology
PPTX
Chapter 5: Probability Theory and Statistics
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
August Patch Tuesday
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Hybrid model detection and classification of lung cancer
PPTX
cloud_computing_Infrastucture_as_cloud_p
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Unlocking AI with Model Context Protocol (MCP)
Approach and Philosophy of On baking technology
Chapter 5: Probability Theory and Statistics
Univ-Connecticut-ChatGPT-Presentaion.pdf
SOPHOS-XG Firewall Administrator PPT.pptx
MIND Revenue Release Quarter 2 2025 Press Release
Building Integrated photovoltaic BIPV_UPV.pdf
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Group 1 Presentation -Planning and Decision Making .pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
A comparative study of natural language inference in Swahili using monolingua...
A comparative analysis of optical character recognition models for extracting...
A novel scalable deep ensemble learning framework for big data classification...
August Patch Tuesday
Assigned Numbers - 2025 - Bluetooth® Document
Hybrid model detection and classification of lung cancer
cloud_computing_Infrastucture_as_cloud_p

NYC* Tech Day - New Cassandra Drivers in Depth

  • 1. New Cassandra Drivers in Depth Michaël Figuière @mfiguiere
  • 2. Speaker Michaël Figuière @mfiguiere ©2012 DataStax 2
  • 3. CQL: the new face of Cassandra • CQL 3 • Simpler Data Model using denormalized Tables • SQL-like query language • Schema definition • CQL Binary Protocol • Introduced in Cassandra 1.2 (CASSANDRA-2478) • Designed for CQL 3 • Opens doors for Streaming, Notifications, ... • Thrift will keep being supported by Cassandra ©2012 DataStax 3
  • 4. CQL3 Denormalized Model CQL3 Query Language comes with a new Data Model abstraction made of denormalized, statically defined tables Data duplicated over several tables ©2012 DataStax 4
  • 5. CQL3 Data Model Timeline Table user_id tweet_id author body gmason 1735 phenry Give me liberty or give me death 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 Partition Clustering Key Key ©2012 DataStax 5
  • 6. CQL3 Data Model Timeline Table user_id tweet_id author body gmason 1735 phenry Give me liberty or give me death 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 CQL CREATE TABLE timeline ( user_id varchar, tweet_id timeuuid, author varchar, body varchar, PRIMARY KEY (user_id, tweet_id)); ©2012 DataStax 6
  • 7. CQL3 Data Model Timeline Table user_id tweet_id author body gmason 1735 phenry Give me liberty or give me death 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 Timeline Physical Layout [1735, author] [1735, body] [1742, author] [1742, body] gmason gwashington I chopped down the... phenry Give me liberty or give... [1767, author] [1767, body] [1794, author] [1794, body] ahamilton gwashington I chopped down the... jadams A government of laws... ©2012 DataStax 7
  • 8. Current Drivers Architecture CQL API Thrift API OO API DB API Thrift RPC Thrift RPC Client Library CQL Driver * This is a simplified view of drivers architecture. Details vary from one language to another. ©2012 DataStax 8
  • 9. New Drivers Architecture DB API CQL API OO API CQL Native Protocol Next Generation Driver * This is a simplified view of drivers architecture. Details vary from one language to another. ©2012 DataStax 9
  • 10. DataStax Java Driver • Reference Implementation • Asynchronous architecture based on Netty • Prepared Statements Support • Automatic Fail-over • Node Discovery • Cassandra Tracing Support • Tunable policies • LoadBalancingPolicy • ReconnectionPolicy • ©2012 DataStax RetryPolicy 10
  • 11. Request Pipelining Client Cassandra Without Request Pipelining With Client Cassandra Request Pipelining ©2012 DataStax 11
  • 12. Notifications Node Client Node Node Without Notifications With Notifications Node Client Node Node ©2012 DataStax 12
  • 13. Asynchronous Architecture Node Client Thread Node Client Driver Thread Node Client Thread Node ©2012 DataStax 13
  • 14. Asynchronous Architecture Node Client Thread 6 1 Node Client Driver 2 Thread 3 Node 5 4 Client Thread Node ©2012 DataStax 14
  • 15. LoadBalancingPolicy public interface LoadBalancingPolicy { HostDistance distance(Host host); Iterator<Host> newQueryPlan(Query query); [...] } ©2012 DataStax 15
  • 16. DCAwareRoundRobinPolicy Datacenter A Local nodes are queried first, if non Client Node are available, the request will be sent Client Node to a remote node. Node Client Client Node Client Node Node Client Datacenter B ©2012 DataStax 16
  • 17. TokenAwarePolicy Nodes that own a Replica of the data being read or written by the query will be contacted first. Replica Node Node Client Replica Node Node Replica Node ©2012 DataStax 17
  • 18. RetryPolicy public interface RetryPolicy { RetryDecision onReadTimeout(Query query, ConsistencyLevel cl, [...] ); RetryDecision onWriteTimeout(Query query, ConsistencyLevel cl, [...] ); RetryDecision onUnavailable(Query query, ConsistencyLevel cl, [...] ); public static class RetryDecision { public static enum Type { RETRY, RETHROW, IGNORE }; private final Type type; private final ConsistencyLevel retryCL; [...] } } ©2012 DataStax 18
  • 19. Downgrading Consistency If the requested Consistency Level cannot be reached (QUORUM here), a second request with a lower CL is sent automatically. Node Replica Client Node Replica Node Replica ©2012 DataStax 19
  • 20. Connect and Write Cluster cluster = Cluster.builder() .addContactPoints("10.0.0.1", "10.0.0.2") .build(); Session session = cluster.connect("myKeyspace"); session.execute( "INSERT INTO user (user_id, name, email) VALUES (12345, 'johndoe', 'john@doe.com')" ); ©2012 DataStax 20
  • 21. Read ResultSet rs = session.execute("SELECT * FROM test"); List<Row> rows = rs.all(); for (Row row : rows) { String userId = row.getString("user_id"); String name = row.getString("name"); String email = row.getString("email"); } ©2012 DataStax 21
  • 22. Asynchronous Read ResultSetFuture future = session.executeAsync("SELECT * FROM test"); for (Row row : future.get()) { String userId = row.getString("user_id"); String name = row.getString("name"); String email = row.getString("email"); } ©2012 DataStax 22
  • 23. Prepared Statements PreparedStatement ps = session.prepare("SELECT * FROM users WHERE id = ?"); BoundStatement bs = session.execute(ps.bind("123")).one().getInt("age"); bs.setString("k"); int age = session.execute(bs).one().getInt("age"); age = session.execute(ps.bind("123")).one().getInt("age"); ©2012 DataStax 23
  • 24. Query Builder String query = "SELECT a,b,"C" FROM foo WHERE a IN (127.0.0.1,127.0.0.3) AND "C"='foo' ORDER BY a ASC,b DESC LIMIT 42;"; Query select = select("a", "b", quote("C")).from("foo") .where(in("a", InetAddress.getByName("127.0.0.1"), InetAddress.getByName("127.0.0.3"))) .and(eq(quote("C"), "foo")) .orderBy(asc("a"), desc("b")) .limit(42); ©2012 DataStax 24
  • 25. Object Mapping @Table(name = "user") public class User { public enum Gender { @PartitionKey @EnumValue("m") @Column(name = "user_id") MALE, private String userId; @EnumValue("f") private String name; FEMALE; } private String email; private Gender gender; } ©2012 DataStax 25
  • 26. Inheritance @Table(name = "catalog") @Inheritance( @InheritanceValue("tv") subClasses = {Phone.class, TV.class}, public class TV column = "product_type" extends Product { ) public abstract class Product { private float size; } @Column(name = "product_id") private String productId; private float price; private String vendor; private String model; } ©2012 DataStax 26
  • 27. Betas now available! https://github.com/datastax/
  • 28. Stay Tuned! blog.datastax.com @mfiguiere