understand the data model of Cassandra

来源:互联网 发布:免费书旗软件下载 编辑:程序博客网 时间:2024/05/14 13:57

// this note is helpful to understand the data model of Cassandra

// ref: http://arin.me/blog/wtf-is-a-supercolumn-cassandra-data-model

 

set up a simple blog system, the requirements are as follow:

1, has many users

2, a blog has the title, body, timestamp

3, any user can comment a blog. a comment has the content, user, and timestamp

4, each blog can have many tags with no count limits

 

schma of Sql/RDMS

table : authors {

id primary_key,

name,

sex,

mail

}

table: blogs {

id primary_key,

title,

body,

timestamp,

author_id foreign_key(authors.id)

}

table: comments {

id primary_key,

content,

timestamp,

author_id foreign_key(authors.id)

}

table: tags {

id primary_key

name

}

table: blog_tags {

blog_id,

tag_id

} // it's the relation !

sample query

select b.title from blogs b, tags t, blog_tags bt

where b.id = bt.blog_id and bt.tag_id = t.id and t.name = 'sql';

 

schma of Cassandra

actually, it's not suitable to use 'schma' here

authors: {

Tom: {

sex: male,

mail: tom@xxx.com

}

}

blogs: {

notes_for_nosql: {

body: blahblahblah,

timestamp: 123456

tags: nosql, dev

}

comments: {

notes_for_nosql: {

timeuuid_1: {

commenter: Lily,

content: good

pubdate: 12345

}

timeuuid_2: {

commenter: John,

content: good job,

pubdata: 123457

}

}

}

 

taggedposts: {

nosql: {

timeuuid_1: notes_for_nosql,

timeuuid_2: learn_cassandra

}

dev: {

timeuuid_3: notes_for_nosql

}

}

to be continued ...

原创粉丝点击