Weitere ähnliche Inhalte
Ähnlich wie Apache Cassandra at Narmal 2014
Ähnlich wie Apache Cassandra at Narmal 2014 (20)
Mehr von DataStax Academy
Mehr von DataStax Academy (20)
Kürzlich hochgeladen (20)
Apache Cassandra at Narmal 2014
- 5. Data Model - Conversations
CREATE TABLE conversations (
user_id uuid,
ts big_int,
recipients_hash text,
PRIMARY KEY(user_id, ts);
- 6. Data Model - Conversations
INSERT INTO.conversations (user_id, ts, rec_hash) VALUES (1,
‘141...x‘, pr135t’);
INSERT INTO.conversations (user_id, ts, subject) VALUES (1,
‘141...y‘, ‘ra881’);
INSERT INTO.conversations (user_id, ts, subject) VALUES (1,
‘141...z‘, ‘pr135t!’);
1
141y:rec_hash
ra881
141x:rec_hash
pr135t
141z:rec_hash
pr135t
- 7. Data Model - Edge Case
141y:rec_hash
ra881
141x:rec_hash
pr135t
141z:rec_hash
pr135t
2x recipients_hash => ‘pr135t
def mostRecent[T](models: List[T])(implicit tc: MostRecentItems[T]): Seq[T] = {
models.groupBy(model => tc.member(model))
.map(_._2.headOption)
.filter(_.isDefined)
.map(_.get).toSeq
.sortBy(model => tc.ts(model)).reverse
}
- 8. Data Model - Topics
CREATE TABLE topics (
user_id uuid,
rec_hash text,
ts bigint,
thread_id,
PRIMARY KEY((user_id, rec_hash), ts);
- 9. INSERT INTO topics (user_id, rec_hash, ts, thread_id) VALUES
(1, ‘pr135t’, ‘141...x‘, ‘d97’);
INSERT INTO topics (user_id, rec_hash, ts, thread_id) VALUES
(1, ‘ra881’, ‘141...y‘, c24);
INSERT INTO topics (user_id, rec_hash, ts, thread_id) VALUES
(1, ‘pr135t!’, ‘141...z‘, ‘d97’);
1 | pr135t
141x:thread_id
d97
141y:thread_id
c24
141z:thread_id
d97
1 | ra881
- 10. Data Model - Emails
CREATE TABLE emails_by_topic (
user_id uuid,
thread_id text,
ts big_int,
id text,
body text,
PRIMARY KEY(user_id, thread_id), ts, id);
- 11. INSERT INTO emails (user_id, thread_id, ts, id, body) VALUES
(1, ‘d97’, ‘141...x‘, ‘32’, “GO”);
INSERT INTO emails (user_id, thread_id, ts, id, body) VALUES
(1, ‘c24’, ‘141...y‘, 99, “YEAH”);
INSERT INTO topics (user_id, thread_id, ts, id, body) VALUES (1,
‘d97’, ‘141...z‘, 33, ‘ROYALS’);
1 | d97
141x:32:body
GO
141y:99:body
YEAH
141z:33:body
ROYALS
1 | c24
- 14. Data Model - Emails 2
CREATE TABLE emails_by_conversation (
user_id uuid,
rec_hash text,
ts big_int,
id text,
thread_id
body text,
PRIMARY KEY(user_id, rec_hash), ts, id);
- 15. INSERT INTO emails (user_id, rec_hash, ts, id, body) VALUES (1,
‘pr135t’, ‘141...x‘, ‘32’, “YEAH!”);
INSERT INTO emails (user_id, rec_hash, ts, id, body) VALUES (1,
‘ra881’, ‘141...y‘, 99, “GO”);
INSERT INTO topics (user_id, rec_hash, ts, id, body) VALUES (1,
‘pr135t’, ‘141...z‘, 33, ‘ROYALS’);
1 | pr135t
141x:32:body
YEAH
141y:99:body
GO
141z:33:body
ROYALS
1 | ra881