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)

Chapter 8. Collections, Tuples, and User-Defined Types

In the preceding chapters, we focused largely on the high-level structure of Cassandra tables, and particularly on the forms and uses of primary keys. We paid scant attention to data columns, generally defining our table schemas with one or two text columns at most. While this type of scalar data column is the workhorse of Cassandra schemas, they're not the only arrow in Cassandra's quiver. Cassandra offers three different structures that store multiple values in a single column. Collection columns can store an arbitrary number of values, all of the same type. Tuples and user-defined types store a fixed number of values but these values can be of different types. While the fields in a tuple are specified by position, user-defined types give a name to each field; when reading data from a user-defined type, it's possible to retrieve a subset of the fields within the column.

Collections come in three flavors:

  • Lists: List columns store ordered...