Database Reference
In-Depth Information
Reading discrete values from collections
The most powerful feature of CQL collections is the ability to write discrete values to a
collection. It's possible to append a single value to a list, update a single key-value pair in a
map, remove a specific value from a set, and so on.
At read time, however, there is no special support for reading discrete values. For instance,
we might want to be able to do something like the following to read a specific element
from a list column:
SELECT "shared_by"[2]
FROM "user_status_updates"
WHERE "username" = 'alice'
AND "id" = 76e7a4d0-e796-11e3-90ce-5f98e903bf02;
Or we might like to read the value at a specific key within a map column:
SELECT "social_identities"['twitter']
FROM "users"
WHERE "username" = 'alice';
However, both queries will result in an error; partial reads of collection columns are not
possible in CQL. The only way to retrieve data from a collection is to read the collection in
its entirety; for this reason, it's generally impractical to store large, unbounded datasets
within a collection column. Were we to store status updates in a collection column on the
users table, we would need to read all of a user's status updates whenever we wanted to
display any status update.
Collection size limit
Lack of support for partial reads is one reason to keep collections fairly small; another is
that there is a built-in size limit for collections that Cassandra can store. In particular, any
given collection can contain no more than 64 KB of data. Nothing will prevent you from
inserting more than 64 KB of data into a collection but, when you try to read the collection
back, the result will be truncated at 64 KB, resulting in data loss. Of course, a collection
that large would be quite unwieldy to work with, so you should stick with collections that
are far smaller than that threshold.
In general, data that can be expected to grow in an unbounded fashion is inappropriate for
collection columns; stick with datasets that you expect to stay fairly small.
Search WWH ::




Custom Search