Database Reference
In-Depth Information
name frozen <user_metadata>,
);
Here,
name
is a frozen type of
user_metadata
for the
users
table in the key-
space
twitter_keyspace
. With a column field defined with the
frozen
keyword, Cassandra serializes multiple components in single value. For example, with
user_metadata
,
fname
and
lname
will be serialized as a single value. Once a
user-defined data type is frozen with the
frozen
keyword, we cannot update compon-
ents of the user-defined type.
Indexing on Collection Attributes
In
Chapter 2
we discussed data modeling concepts and working with collections. Also
Cassandra collection attributes were not supported. With Cassandra 2.1, we now can
create indexes over Cassandra collection attributes like this:
create table users(user_id text PRIMARY KEY,fullname
text,email text,password text, followers map<text, text>);
insert into
users(user_id,email,password,fullname,followers) values
('imvivek','imvivek@xxx.com','password','vivekm',{'mkundera':'milan
kundera','guest': 'guestuser'});
create index followers_idx on users(followers);
Here,
users
is a table and
followers
is a map containing
user_id
as its key
and
name
as the value. The
create index
command will enable an index over the
values of the
followers
map (e.g., full name). We can also enable indexes over fol-
lowers map keys (e.g.,
user_id
) like this:
create index followers_idx_keys on users(KEYS(followers));
We can fetch records from
followers
using indexes as follows:
SELECT email, followers FROM users WHERE followers
CONTAINS 'milan kundera';