Search⌘ K
AI Features

Collection Data Type: MAP

Explore how to use the MAP collection data type in Apache Cassandra to store multiple key-value pairs within a single column. Learn to create tables with MAP columns, insert and update key-value pairs, and remove elements effectively, gaining practical skills for handling small collections of related data in Cassandra.

In Apache Cassandra, collections are data types that store multiple values in a single column, simplifying table design and enabling efficient data retrieval with atomic operations. Collections are best suited for small datasets, like a user’s email addresses or phone numbers. When using collections, it’s important to consider access patterns, data size, and growth potential to avoid performance issues, as improper use can lead to inefficient queries and data management challenges.

Cassandra doesn’t allow accessing individual elements of a collection, as collections are read entirely. The FROZEN keyword is needed to nest one collection inside another.

Cassandra provides the following three collection types:

  • SET

  • LIST

  • MAP

The MAP collection

A MAP stores a collection of key-value pairs in the same cell. Each key is associated with a value, and the value is accessed using its key. The collection is enclosed in curly brackets { }, with each key and its value separated by a colon {key1:value1, key2:value2, ….}. Keys are unique, and a key can only appear once in the collection. Key and value can have different data types specified in the column definition. 

The following syntax is used to create a column as a MAP:

columnName MAP <KeyDataType:ValueDataType>

For example, to create a MAP of topic_tags, the following ...