Database Reference
In-Depth Information
Here column name is the follower's
twitter_id
and their full
name is column value. That's how we can manage schema and play
with dynamic columns in Thrift way. We will discuss dynamic
column support with CQL3 in
Chapter 3
.
Dynamic Columns via cqlsh Using Map Support
In this section, we will discuss how to implement the same Twitter use case using map
support. Collection support in Cassandra would work only with CQL3 binary protocol.
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 map<text,text>);
2.
Store a few columns in
users
column family for row key value
'im-
vivek'
:
insert into users(twitter_id,followers)
values('imvivek',{'guestuser':'guest','ritaf':'rita
fernando','team_marketing':'apress
marketing'});
Here we are adding followers as dynamic columns as map attributes
for user
imvivek
.
3.
Let's add
'imvivek'
and
'team_marketing'
as followers for
'ritaf'
:
insert into users(twitter_id,followers)
values('ritaf',{'imvivek':'vivek mishra'});
insert into
users(twitter_id,followers)
values('team_marketing',{'imvivek':'vivek
mishra'});