Book Image

Learning Apache Cassandra - Second Edition

Book Image

Learning Apache Cassandra - Second Edition

Overview of this book

Cassandra is a distributed database that stands out thanks to its robust feature set and intuitive interface, while providing high availability and scalability of a distributed data store. This book will introduce you to the rich feature set offered by Cassandra, and empower you to create and manage a highly scalable, performant and fault-tolerant database layer. The book starts by explaining the new features implemented in Cassandra 3.x and get you set up with Cassandra. Then you’ll walk through data modeling in Cassandra and the rich feature set available to design a flexible schema. Next you’ll learn to create tables with composite partition keys, collections and user-defined types and get to know different methods to avoid denormalization of data. You will then proceed to create user-defined functions and aggregates in Cassandra. Then, you will set up a multi node cluster and see how the dynamics of Cassandra change with it. Finally, you will implement some application-level optimizations using a Java client. By the end of this book, you'll be fully equipped to build powerful, scalable Cassandra database layers for your applications.
Table of Contents (14 chapters)

Interacting with Cassandra


Most common programming languages have drivers for interacting with Cassandra. When selecting a driver, you should look for libraries that support the CQL binary protocol, which is the latest and most efficient way to communicate with Cassandra.

Note

The CQL binary protocol is a relatively new introduction; older versions of Cassandra used the Thrift protocol as a transport layer. Although Cassandra continues to support Thrift, avoid Thrift-based drivers as they are less performant than the binary protocol.

Here are the CQL binary drivers available for some popular programming languages:

Language

Driver

Available at

Java

DataStax Java Driver

https://github.com/datastax/java-driver

Python

DataStax Python Driver

https://github.com/datastax/python-driver

Ruby

DataStax Ruby Driver

https://github.com/datastax/ruby-driver

C++

DataStax C++ Driver

https://github.com/datastax/cpp-driver

C#

DataStax C# Driver

https://github.com/datastax/csharp-driver

JavaScript (Node.js)

node-cassandra-cql

https://github.com/jorgebay/node-cassandra-cql

PHP

phpbinarycql

https://github.com/rmcfrazier/phpbinarycql

While you are likely to use one of these drivers in your applications, to try out the code examples in this book, you can simply use the cqlsh tool, which is a command-line interface for executing CQL queries and viewing the results. To start cqlsh on OS X or Linux, simply type cqlsh into your command line; you should see something like this:

$ cqlsh
Connected to Test Cluster at 127.0.01:9042.
[cqlsh 5.0.1 | Cassandra 3.0.9 | CQL spec 3.4.0 | Native protocol v4]
Use HELP for help.
cqlsh>

On Windows, you can start cqlsh just the way you ran nodetool:

C:> cd %CASSANDRA_HOME%
C:> bin\cqlsh

Once you open it, you should see the same output we just saw.