liveBook · Manning

Collection

As explained in ScyllaDB in Action

A collection type is a ScyllaDB data type that stores multiple related values, such as set elements or map key-value pairs, in a single column value.

A collection stores multiple related values in one ScyllaDB column. Use it for a small, bounded group of values that belongs with one row—not as a substitute for a table. When data may become large or grow unpredictably, model it in its own table with partition or clustering keys so ScyllaDB can optimize access. section 4.5

Figure 4.3 Scylla supports storing multiple values in its collection data types: lists, sets, and maps.
figure

ScyllaDB provides three collection types: LIST, SET, and MAP. Choose by whether order, duplicates, or named key-value entries matter. section 4.5

Choose a collection by the shape of the values:

  • LIST<T> stores ordered values of one type and may contain duplicates. section 4.5
  • SET<T> stores unique values of one type. Prefer it over a list when duplicate entries are unnecessary. section 4.5 section 4.5.2
  • MAP<K, V> stores unique keys and values; all keys share one type, and all values share one type. section 4.5 section 4.5.3

Declare the contained type in angle brackets. A list or set needs one type, such as SET<TEXT>; a map needs key and value types, such as MAP<TEXT, TEXT>. Because set is reserved in CQL, use another column name such as set_text. section 4.5

Updating a set or map

A set can add values with + and remove values with -. Re-adding an existing value leaves the set unique. A map supports the same add and remove style, and it can update or delete one entry by key, such as map['k2']. section 4.5.2 section 4.5.3

For an article image gallery, a set fits when duplicate images are not needed. An image itself has named fields with differing types, so represent its metadata with a user-defined type (UDT), then store a frozen UDT in the collection: SET<FROZEN<image>>. Store image files separately and keep metadata such as name, location, and caption in the database. section 4.5.6 section 4.5.4

How ScyllaDB in Action covers it

How deep it goes
Defines LIST, SET, and MAP, then demonstrates declarations and update operations; defers large or unbounded data to separate tables.
Examples
Uses a collections table, unique text sets, editable text maps, and an article image gallery modeled as SET<FROZEN<image>>.
What it assumes
Builds from basic column types and schema fields while assuming a query-first table and primary-key design already exists.
What you can do after
Apply it via CQL by choosing, declaring, and updating LIST, SET, or MAP columns for bounded related data.
How it connects
Connects collections with query-first design, primary keys, user-defined types, frozen types, and image metadata.

Also explained in

Compare how 16 books explain collection →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ScyllaDB in Action. The section links point to the parts of the book it draws on.