Creating a custom data type

Apache Cassandra allows for the creation of custom user-defined types (UDTs). UDTs allow for further denormalization of data within a row. A good example of this is a mailing address for customers. Assume a simple table:

CREATE TABLE customer ( last_name TEXT, first_name TEXT, company TEXT, PRIMARY KEY (last_name,first_name));

Now, our customers have mailing addresses. Corporate customers usually have addresses for multiple things, including billing, shipping, headquarters, distribution centers, store locations, and data centers. So how do we track multiple addresses for a single customer? One way to accomplish this would be to create a collection of a UDT:

CREATE TYPE customer_address ( type TEXT, street TEXT, ...

Get Mastering Apache Cassandra 3.x - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.