3 Demo Data Model - Reference Documentation
Authors: Bob Florian
Version: 0.4.3
3 Demo Data Model
3.1 Class Declarations
Person
class User { String username String emailAddress String firstName String lastName String address String city String state String zip String country String phone Gender gender Date birthDate List posts static hasMany = [posts: Post] static cassandraMapping = [ primaryKey: 'username', explicitIndexes: ["emailAddress", "phone", 'birthDate', ["country","state","city"]], secondaryIndexes: ["gender","country", "state"], counters: [ [groupBy: ['birthDate']], [groupBy: ['gender']], [groupBy: ['country','state','city','gender']], [findBy: ['country','state'], groupBy:['city','gender']] ] ] }
Post
class Post { UUID uuid String text Date occurTime Person person static belongsTo = [person: Person] List comments Set likedBy static hasMany = [comments: Comment, likedBy: Person] static cassandraMapping = [ primaryKey: 'uuid', counters: [ [groupBy: ['occurTime']] ], keySpace: "demo" ] Boolean isLikedBy(person) { likedByCount(start:person.id, finish:person.id) > 0 } }
Comment
class Comment { UUID uuid String text Date occurTime Person person Post post static belongsTo = [post: Post] Set likedBy static hasMany = [likedBy: Person] static cassandraMapping = [ primaryKey: 'uuid', counters: [ [findBy: ['post'], groupBy:['occurTime']], [findBy: ['person'], groupBy:['occurTime']] ], keySpace: "demo" ] Boolean isLikedBy(person) { likedByCount(start:person.id, finish:person.id) > 0 } }
3.2 Schema
CLI schema creation script
create column family Person with comparator=UTF8Type and default_validation_class=UTF8Type;create column family Person_IDX with comparator=UTF8Type and default_validation_class=UTF8Type;create column family Person_CTR with comparator=UTF8Type and default_validation_class=CounterColumnType; create column family Post with comparator=UTF8Type and default_validation_class=UTF8Type;create column family Post_IDX with comparator=UTF8Type and default_validation_class=UTF8Type;create column family Post_CTR with comparator=UTF8Type and default_validation_class=CounterColumnType; create column family Comment with comparator=UTF8Type and default_validation_class=UTF8Type;create column family Comment_IDX with comparator=UTF8Type and default_validation_class=UTF8Type;create column family Comment_CTR with comparator=UTF8Type and default_validation_class=CounterColumnType;
3.3 Data Structures
The Cassandra data structures produced by this model are shown in the following sections.Person
Person: user1 => class_name => 'example.Person' username => 'user1' user2 => class_name => 'example.Person' username => 'user2'
Person_IDX
Person_IDX: Comment?likedBy=001347471378565_5c260b50-fd00-11e1-8230-001c42000009 => user1 => '' user2 => '' Comment?likedBy=001347471378631_5c301d70-fd00-11e1-8230-001c42000009 => user1 => '' Person?friends=user1 => user1 => '' user2 => '' Person?friends=user2 => user1 => '' user2 => '' Post?likedBy=001347471378340_5c03b640-fd00-11e1-8230-001c42000009 => user2 => '' Post?likedBy=001347471378502_5c1c6e60-fd00-11e1-8230-001c42000009 => user1 => '' this => user1 => '' user2 => '' this#user1 => Comment?likedBy=001347471378565_5c260b50-fd00-11e1-8230-001c42000009 => '' Comment?likedBy=001347471378631_5c301d70-fd00-11e1-8230-001c42000009 => '' Person?friends=user1 => '' Person?friends=user2 => '' Post?likedBy=001347471378502_5c1c6e60-fd00-11e1-8230-001c42000009 => '' this#user2 => Comment?likedBy=001347471378565_5c260b50-fd00-11e1-8230-001c42000009 => '' Person?friends=user1 => '' Person?friends=user2 => '' Post?likedBy=001347471378340_5c03b640-fd00-11e1-8230-001c42000009 => '' this@user1 => 001347471378340_5c03b640-fd00-11e1-8230-001c42000009�person�Post => '' 001347471378631_5c301d70-fd00-11e1-8230-001c42000009�person�Comment => '' this@user2 => 001347471378502_5c1c6e60-fd00-11e1-8230-001c42000009�person�Post => '' 001347471378565_5c260b50-fd00-11e1-8230-001c42000009�person�Comment => ''
Post
001347471378340_5c03b640-fd00-11e1-8230-001c42000009 => class_name => 'example.Post' occurTime => '2012-09-12T17:36:18.308Z' personId => 'user1' text => 'User 1's Post 1' uuid => '5c03b640-fd00-11e1-8230-001c42000009' 001347471378502_5c1c6e60-fd00-11e1-8230-001c42000009 => class_name => 'example.Post' occurTime => '2012-09-12T17:36:18.498Z' personId => 'user2' text => 'User 2's Post 1' uuid => '5c1c6e60-fd00-11e1-8230-001c42000009'
Post_IDX
Person?posts=user1 => 001347471378340_5c03b640-fd00-11e1-8230-001c42000009 => '' Person?posts=user2 => 001347471378502_5c1c6e60-fd00-11e1-8230-001c42000009 => '' this => 001347471378340_5c03b640-fd00-11e1-8230-001c42000009 => '' 001347471378502_5c1c6e60-fd00-11e1-8230-001c42000009 => '' this#001347471378340_5c03b640-fd00-11e1-8230-001c42000009 => Person?posts=user1 => '' this#001347471378502_5c1c6e60-fd00-11e1-8230-001c42000009 => Person?posts=user2 => '' this@001347471378340_5c03b640-fd00-11e1-8230-001c42000009 => 001347471378565_5c260b50-fd00-11e1-8230-001c42000009�post�Comment => '' this@001347471378502_5c1c6e60-fd00-11e1-8230-001c42000009 => 001347471378631_5c301d70-fd00-11e1-8230-001c42000009�post�Comment => ''
Post_CTR
this#occurTime => 2012-09-12T17 => 2 this#occurTime[yyyy-MM-dd] => 2012-09-12 => 2 this#occurTime[yyyy-MM] => 2012-09 => 2
Comment
001347471378565_5c260b50-fd00-11e1-8230-001c42000009 => class_name => 'example.Comment' occurTime => '2012-09-12T17:36:18.559Z' personId => 'user2' postId => '001347471378340_5c03b640-fd00-11e1-8230-001c42000009' text => 'Comments to post 1 from user 2' uuid => '5c260b50-fd00-11e1-8230-001c42000009' 001347471378631_5c301d70-fd00-11e1-8230-001c42000009 => class_name => 'example.Comment' occurTime => '2012-09-12T17:36:18.627Z' personId => 'user1' postId => '001347471378502_5c1c6e60-fd00-11e1-8230-001c42000009' text => 'Comments to post 2 from user 1' uuid => '5c301d70-fd00-11e1-8230-001c42000009'
Comment_IDX
Post?comments=001347471378340_5c03b640-fd00-11e1-8230-001c42000009 => 001347471378565_5c260b50-fd00-11e1-8230-001c42000009 => '' Post?comments=001347471378502_5c1c6e60-fd00-11e1-8230-001c42000009 => 001347471378631_5c301d70-fd00-11e1-8230-001c42000009 => '' this => 001347471378565_5c260b50-fd00-11e1-8230-001c42000009 => '' 001347471378631_5c301d70-fd00-11e1-8230-001c42000009 => '' this#001347471378565_5c260b50-fd00-11e1-8230-001c42000009 => Post?comments=001347471378340_5c03b640-fd00-11e1-8230-001c42000009 => '' this#001347471378631_5c301d70-fd00-11e1-8230-001c42000009 => Post?comments=001347471378502_5c1c6e60-fd00-11e1-8230-001c42000009 => ''
Comment_CTR
this?person=user1#occurTime => 2012-09-12T17 => 1 this?person=user1#occurTime[yyyy-MM-dd] => 2012-09-12 => 1 this?person=user1#occurTime[yyyy-MM] => 2012-09 => 1 this?person=user2#occurTime => 2012-09-12T17 => 1 this?person=user2#occurTime[yyyy-MM-dd] => 2012-09-12 => 1 this?person=user2#occurTime[yyyy-MM] => 2012-09 => 1 this?post=001347471378340_5c03b640-fd00-11e1-8230-001c42000009#occurTime => 2012-09-12T17 => 1 this?post=001347471378340_5c03b640-fd00-11e1-8230-001c42000009#occurTime[yyyy-MM-dd] => 2012-09-12 => 1 this?post=001347471378340_5c03b640-fd00-11e1-8230-001c42000009#occurTime[yyyy-MM] => 2012-09 => 1 this?post=001347471378502_5c1c6e60-fd00-11e1-8230-001c42000009#occurTime => 2012-09-12T17 => 1 this?post=001347471378502_5c1c6e60-fd00-11e1-8230-001c42000009#occurTime[yyyy-MM-dd] => 2012-09-12 => 1 this?post=001347471378502_5c1c6e60-fd00-11e1-8230-001c42000009#occurTime[yyyy-MM] => 2012-09 => 1