Database Reference
In-Depth Information
Consider a scenario where the user wants to store only a collection of follower's id (not
full name). Cassandra offers collection support for keeping a list or set of such ele-
ments. Let's discuss how to implement it using set support.
1.
First, let's create a keyspace twitter and column family users .
create keyspace twitter with replication =
{'class':'SimpleStrategy','replication_factor':3};
use twitter;
create table users(twitter_id text primary
key,followers set<text>);
2.
Store few columns in users column family for row key value 'im-
vivek' .
insert into users(twitter_id,followers)
values('imvivek',
{'guestuser','ritaf','team_marketing'});
Here we are adding followers as dynamic columns as set attributes for
user imvivek .
3.
Let's add the following:
'imvivek' and 'team_marketing' as followers for 'ritaf'
'ritaf' as a follower for 'jhassell'
insert into users(twitter_id,followers)
values('ritaf',
{'imvivek','jhassell','team_marketing'});
insert into users(twitter_id,followers)
values('jhassell', {'ritaf'});
4.
To view the list of rows in users column family (see Figure 2-10 ), use
the following command:
select * from users;
 
Search WWH ::




Custom Search