Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Become a super modelerPatrick McFadin @PatrickMcFadinSenior Solutions ArchitectDataStaxThursday, May 16, 13
Become a super modelerPatrick McFadin @PatrickMcFadinSenior Solutions ArchitectDataStaxThursday, May 16, 13
... the saga continues.This is the second part of a data modeling seriesPart 1:The data model is dead, long live the data ...
Becoming a super modeler• Data model is the key to happiness• Successful deployments depend on it• Not just a Cassandra pr...
Time series - BasicCREATE TABLE temperature (weatherstation_id text,event_time timestamp,temperature text,PRIMARY KEY (wea...
Time series - Super!• Every second? Row would be too big• Order by access pattern• Partition the rows by day- One weather ...
User model - basic• Plain ole entity table• One primary key• Booooring6CREATE TABLE users (username text PRIMARY KEY,first...
Cassandra feature - Collections• Collections give you three types:- Set- List- Map• Each allow for dynamic updates• Fully ...
Cassandra Collections - Set• Set is sorted by CQL type comparator8INSERT INTO collections_example (id, set_example)VALUES(...
Cassandra Collections - Set Operations9UPDATE collections_exampleSET set_example = set_example + {3-three} WHERE id = 1;UP...
Cassandra Collections - List• Ordered by insertion10list_example list<text>Collection name Collection type CQLTypeINSERT I...
Cassandra Collections - List Operations• Adding an element to the end of a list11UPDATE collections_exampleSET list_exampl...
Cassandra Collections - Map• Key and value• Key is sorted by CQL type comparator12INSERT INTO collections_example (id, map...
Cassandra Collections - Map Operations• Add an element to the map13UPDATE collections_exampleSET map_example[3] = three WH...
User model - Super!•Take boring user table and kick it up• Great for static + some dynamic•Takes advantage of row level is...
Super user profile - Operations• Adding new login locations to the map15UPDATE user_with_locationSET last_login = now(), lo...
Indexing• Indexing expresses application intent• Fast access to specific queries• Secondary indexes != relational indexes•...
Keyword index• Use a word as a key• Columns are the occurrence• Ex: Index of tag words about videos17CREATE TABLE tag_inde...
Partial word index• Where row size will be large•Take one part for key, rest for columns name18CREATE TABLE email_index (d...
Partial word index - Super!• Create partitions + partial indexes FTW19CREATE TABLE product_index (store int,part_number0_3...
Bit map index• Multiple parts to a key• Create a truth table of the different combinations• Inserts == the number of combi...
Bit map index• Find a car in a lot by variable combinations21Make Model Color Combinationx Colorx Modelx x Model+Colorx Ma...
Bit map index -Table create• Make a table with three different key combos22CREATE TABLE car_location_index (make varchar,m...
Bit map index - Adding records• Pre-optimize for 7 possible questions on insert23INSERT INTO car_location_index (make,mode...
Bit map index - Selecting records• Different combinations now possible24SELECT vehical_id,lot_idFROM car_location_indexWHE...
Feeling super yet?• Use these skills. Save you they will.• Don’t settle for boring data models• Stay tuned for more!25• Fi...
Be there!!!26Sony, eBay, Netflix, Intuit, Spotify... the list goes on. Don’t miss it.Here is my discount code! Use it: PMcV...
Bonus!• DataStax Java Driver Preso - June 12th• Download today!27https://github.com/datastax/java-driverThursday, May 16, 13
ThankYouQ&AThursday, May 16, 13
Upcoming SlideShare
Loading in …5
×

Become a super modeler

18,790 views

Published on

Slides from my webinar May 16, 2013.

Published in: Technology
  • Thanks for providing helpful information and for your professionalism. ✔✔✔ https://w.url.cn/s/Aaxmqpl
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Hi there! I just wanted to share a list of sites that helped me a lot during my studies: .................................................................................................................................... www.EssayWrite.best - Write an essay .................................................................................................................................... www.LitReview.xyz - Summary of books .................................................................................................................................... www.Coursework.best - Online coursework .................................................................................................................................... www.Dissertations.me - proquest dissertations .................................................................................................................................... www.ReMovie.club - Movies reviews .................................................................................................................................... www.WebSlides.vip - Best powerpoint presentations .................................................................................................................................... www.WritePaper.info - Write a research paper .................................................................................................................................... www.EddyHelp.com - Homework help online .................................................................................................................................... www.MyResumeHelp.net - Professional resume writing service .................................................................................................................................. www.HelpWriting.net - Help with writing any papers ......................................................................................................................................... Save so as not to lose
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Follow the link, new dating source: ❶❶❶ http://bit.ly/2Qu6Caa ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Dating for everyone is here: ❶❶❶ http://bit.ly/2Qu6Caa ❶❶❶
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy &amp; Proven Way to Build Good Habits &amp; Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Become a super modeler

  1. 1. Become a super modelerPatrick McFadin @PatrickMcFadinSenior Solutions ArchitectDataStaxThursday, May 16, 13
  2. 2. Become a super modelerPatrick McFadin @PatrickMcFadinSenior Solutions ArchitectDataStaxThursday, May 16, 13
  3. 3. ... the saga continues.This is the second part of a data modeling seriesPart 1:The data model is dead, long live the data model!• Relational -> Cassandra topics• Basic entity modeling• one-to-many• many-to-many•Transaction like modelingThursday, May 16, 13
  4. 4. Becoming a super modeler• Data model is the key to happiness• Successful deployments depend on it• Not just a Cassandra problem...3Thursday, May 16, 13
  5. 5. Time series - BasicCREATE TABLE temperature (weatherstation_id text,event_time timestamp,temperature text,PRIMARY KEY (weatherstation_id,event_time));• Weather station collects regular temperature• Each weather station is a row• Each event is a new column in a wide rowThursday, May 16, 13
  6. 6. Time series - Super!• Every second? Row would be too big• Order by access pattern• Partition the rows by day- One weather station by day5CREATE TABLE temperature_by_day (weatherstation_id text,date text,event_time timestamp,temperature text,PRIMARY KEY ((weatherstation_id,date),event_time)) WITH CLUSTERING ORDER BY (event_time DESC);Compound row keyReverse sort: Last event, first on rowThursday, May 16, 13
  7. 7. User model - basic• Plain ole entity table• One primary key• Booooring6CREATE TABLE users (username text PRIMARY KEY,first_name text,last_name text,address1 text,city text,postal_code text,last_login timestamp);Thursday, May 16, 13
  8. 8. Cassandra feature - Collections• Collections give you three types:- Set- List- Map• Each allow for dynamic updates• Fully supported in CQL 3• Requires serialization so don’t go crazy7CREATE TABLE collections_example (! id int PRIMARY KEY,! set_example set<text>,! list_example list<text>,! map_example map<int,text>);Thursday, May 16, 13
  9. 9. Cassandra Collections - Set• Set is sorted by CQL type comparator8INSERT INTO collections_example (id, set_example)VALUES(1, {1-one, 2-two});set_example set<text>Collection name Collection type CQLTypeThursday, May 16, 13
  10. 10. Cassandra Collections - Set Operations9UPDATE collections_exampleSET set_example = set_example + {3-three} WHERE id = 1;UPDATE collections_exampleSET set_example = set_example + {0-zero} WHERE id = 1;UPDATE collections_exampleSET set_example = set_example - {3-three} WHERE id = 1;• Adding an element to the set• After adding this element, it will sort to the beginning.• Removing an element from the setThursday, May 16, 13
  11. 11. Cassandra Collections - List• Ordered by insertion10list_example list<text>Collection name Collection type CQLTypeINSERT INTO collections_example (id, list_example)VALUES(1, [1-one, 2-two]);Thursday, May 16, 13
  12. 12. Cassandra Collections - List Operations• Adding an element to the end of a list11UPDATE collections_exampleSET list_example = list_example + [3-three] WHERE id = 1;UPDATE collections_exampleSET list_example = [0-zero] + list_example WHERE id = 1;• Adding an element to the beginning of a listUPDATE collections_exampleSET list_example = list_example - [3-three] WHERE id = 1;• Deleting an element from a listThursday, May 16, 13
  13. 13. Cassandra Collections - Map• Key and value• Key is sorted by CQL type comparator12INSERT INTO collections_example (id, map_example)VALUES(1, { 1 : one, 2 : two });map_example map<int,text>Collection name Collection type Value CQLTypeKey CQLTypeThursday, May 16, 13
  14. 14. Cassandra Collections - Map Operations• Add an element to the map13UPDATE collections_exampleSET map_example[3] = three WHERE id = 1;UPDATE collections_exampleSET map_example[3] = tres WHERE id = 1;DELETE map_example[3]FROM collections_example WHERE id = 1;• Update an existing element in the map• Delete an element in the mapThursday, May 16, 13
  15. 15. User model - Super!•Take boring user table and kick it up• Great for static + some dynamic•Takes advantage of row level isolation14CREATE TABLE user_with_location (! username text PRIMARY KEY,! first_name text,! last_name text,! address1 text,! city text,! postal_code text,! last_login timestamp,! location_by_date map<timeuuid,text>);Thursday, May 16, 13
  16. 16. Super user profile - Operations• Adding new login locations to the map15UPDATE user_with_locationSET last_login = now(), location_by_date = {now() : 123.123.123.1}WHERE username=PatrickMcFadin;UPDATE user_with_locationUSING TTL 2592000 // 30 DaysSET last_login = now(), location_by_date = {now() : 123.123.123.1}WHERE username=PatrickMcFadin;• Adding new login locations to the map +TTL!Thursday, May 16, 13
  17. 17. Indexing• Indexing expresses application intent• Fast access to specific queries• Secondary indexes != relational indexes• Use information you have. No pre-reads.16Goals:1. Create row key for speed2. Use wide rows for efficiencyThursday, May 16, 13
  18. 18. Keyword index• Use a word as a key• Columns are the occurrence• Ex: Index of tag words about videos17CREATE TABLE tag_index (tag varchar,videoid uuid,timestamp timestamp,PRIMARY KEY (tag, videoid));VideoId1 .. VideoIdNtagFastEfficientThursday, May 16, 13
  19. 19. Partial word index• Where row size will be large•Take one part for key, rest for columns name18CREATE TABLE email_index (domain varchar,user varchar,username varchar,PRIMARY KEY (domain, user));INSERT INTO email_index (domain, user, username)VALUES (@relational.com,tcodd, tcodd);User: tcodd Email: tcodd@relational.comThursday, May 16, 13
  20. 20. Partial word index - Super!• Create partitions + partial indexes FTW19CREATE TABLE product_index (store int,part_number0_3 int,part_number4_9 int,count int,PRIMARY KEY ((store,part_number0_3), part_number4_9));INSERT INTO product_index (store,part_number0_3,part_number4_9,count)VALUES (8675309,7079,48575,3);SELECT countFROM product_indexWHERE store = 8675309AND part_number0_3 = 7079AND part_number4_9 = 48575;Compound row key!Fast and efficient!• Store #8675309 has 3 of part# 7079748575Thursday, May 16, 13
  21. 21. Bit map index• Multiple parts to a key• Create a truth table of the different combinations• Inserts == the number of combinations- 3 fields? 7 options (Not going to use null choice)- 4 fields? 15 options20Thursday, May 16, 13
  22. 22. Bit map index• Find a car in a lot by variable combinations21Make Model Color Combinationx Colorx Modelx x Model+Colorx Makex x Make+Colorx x Make+Modelx x x Make+Model+ColorThursday, May 16, 13
  23. 23. Bit map index -Table create• Make a table with three different key combos22CREATE TABLE car_location_index (make varchar,model varchar,color varchar,vehical_id int,lot_id int,PRIMARY KEY ((make,model,color),vehical_id));Compound row key with three different optionsThursday, May 16, 13
  24. 24. Bit map index - Adding records• Pre-optimize for 7 possible questions on insert23INSERT INTO car_location_index (make,model,color,vehical_id,lot_id)VALUES (Ford,Mustang,Blue,1234,8675309);INSERT INTO car_location_index (make,model,color,vehical_id,lot_id)VALUES (Ford,Mustang,,1234,8675309);INSERT INTO car_location_index (make,model,color,vehical_id,lot_id)VALUES (Ford,,Blue,1234,8675309);INSERT INTO car_location_index (make,model,color,vehical_id,lot_id)VALUES (Ford,,,1234,8675309);INSERT INTO car_location_index (make,model,color,vehical_id,lot_id)VALUES (,Mustang,Blue,1234,8675309);INSERT INTO car_location_index (make,model,color,vehical_id,lot_id)VALUES (,Mustang,,1234,8675309);INSERT INTO car_location_index (make,model,color,vehical_id,lot_id)VALUES (,,Blue,1234,8675309);Thursday, May 16, 13
  25. 25. Bit map index - Selecting records• Different combinations now possible24SELECT vehical_id,lot_idFROM car_location_indexWHERE make = FordAND model = AND color = Blue;vehical_id | lot_id------------+---------1234 | 8675309SELECT vehical_id,lot_idFROM car_location_indexWHERE make = AND model = AND color = Blue;vehical_id | lot_id------------+---------1234 | 86753098765 | 5551212Thursday, May 16, 13
  26. 26. Feeling super yet?• Use these skills. Save you they will.• Don’t settle for boring data models• Stay tuned for more!25• Final will be at the Cassandra Summit: June 11thThe worlds next top data modelThursday, May 16, 13
  27. 27. Be there!!!26Sony, eBay, Netflix, Intuit, Spotify... the list goes on. Don’t miss it.Here is my discount code! Use it: PMcVIPThursday, May 16, 13
  28. 28. Bonus!• DataStax Java Driver Preso - June 12th• Download today!27https://github.com/datastax/java-driverThursday, May 16, 13
  29. 29. ThankYouQ&AThursday, May 16, 13

×