Database Reference
In-Depth Information
Using maps to store key-value pairs
The third and final collection type offered by Cassandra is the map, which stores key-value
pairs. Keys are unique and unordered, like the elements of a set.
Suppose we'd like to keep track of our users' identities on other social networks. We could
create a column for each network, but that would require changing the schema each time
we discovered a new network that we want to track, and would also potentially result in a
large number of columns in the users table just to keep track of a given user's identities.
Instead, let's create a map column that maps the name of a social network to the numeric ID
of the user on that network:
ALTER TABLE "users"
ADD social_identities MAP<text,bigint>;
This definition looks a bit different from the earlier ones in this chapter, since we're now
specifying a pair of types rather than just one. Maps do not require their keys and values to
be of the same type, so each is specified individually. The first type given is the key type,
and the second is the value type. So our keys—the names of social networks—are strings,
and our values—IDs on those networks—are long integers.
Search WWH ::




Custom Search