Bringing together the Apache Cassandra experts from the community and DataStax.

Want to learn? Have a question? Want to share your expertise? You are in the right place!

Not sure where to begin? Getting Started



Barnesicle avatar image
Barnesicle asked Erick Ramirez commented

Nested collections and types

I am wondering if I should be wary of using types with collections or collections in general. I did read somewhere that it is recommended not to even use collections at all but instead to use multiple columns with denormalized data. Is this true for later Cassandra versions as well?

If it is ok to use collections is there a point where it can be a concern? Like field size?

Small example:

name text

id text,
name text,
max_quantity int,
options list<FROZEN<option>>,
created timestamp,
last_updated timestamp

id text,
name text,
description text,
email text,
categories set<text>,
end_date timestamp,
created timestamp,
last_updated timestamp,
owner_id text,
accepted boolean,
role text,
first_nested list<FROZEN<nested1>>,
PRIMARY KEY ((id), email)

UPDATE: If you don't mind I would like to also expand on my question. Is there a limit to the size of the lists? Or nested collections inside. In the example above, what if I had for example 100 records in the first_nested row? Or a collection on first_nested, what if I had another 100 records on that? Collections greatly simplify query patterns but I am worried that it will cause issues in the future.

1 comment
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

@Barnesicle apologies for the delayed response. I thought I had already answered this last night.

0 Likes 0 ·

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered Erick Ramirez commented

@Barnesicle you are right in that you should store data in multiple columns if it suits your use case/data model. But if you really need UDTs, then you should use them. Just be aware of the cons such as an entire frozen list must be read so its size may affect performance; individual fields in a frozen collection cannot be updated; and you can't remove fields in a UDT. Cheers!

2 comments Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

I added an extra question at the end if you don't mind.

1 Like 1 ·

@Barnesicle in theory lists can have up to 64K (2^16) items. See Creating Collections for details. Cheers!

0 Likes 0 ·