SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
NoSQL

                             Scott Gonyea
                              Epoch, LLC.
                                             @acts_as
                                      github.com/aitrus
                                     me@sgonyea.com




Tuesday, December 14, 2010                                1
NoSQL




Tuesday, December 14, 2010           2
{ {{ {{{ NoSQL }}} }} }
                              * GONG *




Tuesday, December 14, 2010                      3
NoSQL
                             So... What is it?




Tuesday, December 14, 2010                       4
NoSQL
                   •         It’s “Not SQL”
                   •         Less Structured; Sometimes Un-Structured
                   •         Usually Implies:
                         •     Key-Value Store
                         •     Document Datastore
                         •     Graph Databases (and its Variants)
                   •         Often not much more than that



Tuesday, December 14, 2010                                              5
NoSQL
                             Recap and Comparison




Tuesday, December 14, 2010                          6
NoSQL
               SELECT persons.*
                 FROM      persons
                 LEFT JOIN automobiles
                   ON    persons.id = automobiles.person_id
                 WHERE     automobiles.color IS 'RED'

               /* Wait! We can NORMALIZE this some more! */

               SELECT persons.*
                 FROM      persons
                 LEFT JOIN automobiles
                 LEFT JOIN colors
                   ON    persons.id = automobiles.person_id
                   AND   colors.id   = automobiles.color_id
                 WHERE     colors.name IS 'RED-34'

               /* Wait! ... */




Tuesday, December 14, 2010                                    7
NoSQL
               SELECT persons.*
                 FROM      persons
                 LEFT JOIN automobiles
                   ON    persons.id = automobiles.person_id
                   WHERE automobiles.color IS 'RED'

               /* Wait! We can NORMALIZE this some more! */

               SELECT persons.*, automobiles.*                /* Selects    */
                 FROM      persons
                 LEFT JOIN automobiles                        /* Joins      */
                 LEFT JOIN colors
                   ON    persons.id = automobiles.person_id
                   AND   colors.id   = automobiles.color_id
                 WHERE colors.name IS 'RED-34'                /* Conditions */

               /* Wait! ... */




Tuesday, December 14, 2010                                                       8
Persons
                                                       NoSQL                                  Colors
               id     First Name   Last Name                                                   id        name
               1        Seymore         Butts                                                  212      RED-34
               2        Amanda     Hugginkiss                                                  213     BLUE-32




          Join Table =>            PersonsVehicles
                                   id      vehicle_id   person_id     color_id
                                    1           7384       1            212
                                    2           7231       2            212
                                                                                      Automobiles
                                                                                        id    make        model       Year
                                                                                      23192   Honda           Civic   2003
                                                                                      19763   Chevy       Tahoe       1998



         Relationship: “Belongs To” =>                         Vehicles
                                                                id               identier       automobile_id

   Normalization                                               7231
                                                               7384
                                                                       1FALP62W4WH128703
                                                                       4WH1287031FALP62W
                                                                                                      23192
                                                                                                      19763

Tuesday, December 14, 2010                                                                                                   9
NoSQL
                                                 Key-Value Stores
                                                AKA: Dictionary,
                                                     Hash Table, etc.




                                                                      KV Database
                             Key           Give me what’s at “John”
                             “John”




                                                                                    “Jo
                                                                                       hn
                                                                                         ”
                                                                                             Value at “John”
                                      “Smith”
                                                                                                 “Smith”




Tuesday, December 14, 2010                                                                                     10
NoSQL
                                 Key-Value Stores
                   • Very Fast
                   • Simple
                   • Key-Value Pairs are Self-Contained
                    ∴Easier Replication
                       - Twitter, Facebook, Google, etc.
                       - Also,Your Computer
Tuesday, December 14, 2010                                 11
NoSQL
                                        Document[-Oriented] Stores
               Very De-Normalized                                       Less De-Normalized
                              “John Smith”                                          “John Smith”
                     string     rst_name              John           string     rst_name                     John
                     string     last_name             Smith           string     last_name                     Smith
              embedded automobiles                                embedded automobiles
              document doc_id   make                    Honda     document doc_ref     vehicle         id(fd18d0af6c053886d)
                               string       model        Civic                   string       color                Red
                                int         year         2003         string      employer                Epoch, LLC.
                               string       color        Red
                                                                                        fd18d0af6c053886d
                     string      employer           Epoch, LLC.
                                                                               string     make                   Honda
                                                                               string     model                  Civic
                                                                                  int      year                  2003
                                                                        embedded features
                                                                        document string               breaks           anti-lock
                                                                                          bool        air_cond           TRUE
                                                                        geo_coord        made_at      39.975542, -82.992096

Tuesday, December 14, 2010                                                                                                         12
NoSQL
                             Document[-Oriented] Stores

                   • Analogous to Printed Documents
                   • Varying Levels of De-normalization
                   • Documents Still Relatively Self-Contained
                    ∴Easier Replication, Too
                      - Twitter, Facebook, Google, etc.

Tuesday, December 14, 2010                                       13
NoSQL
                                                 Graph Databases
                             untitled




                                   6
                                                   4                5
                                                                                  1

                                                       3                2

                                          Six Degrees of Separation
                                        or: How you realized you have no friends :-(
Tuesday, December 14, 2010                                                             14
NoSQL
                                           Graph Databases
                   •      Relationships Derived Through “Distance”
                   •      Some Use-Cases:
                         • Geographic
                         • Networking
                         • Routing / Shortest Path
                         • Social
                         • Molecular Modeling
                         • Kevin Bacon Jokes
                   •      Also Quite Trendy:
                         -   Twitter, Facebook, Google [Maps, Mail, & Your Life]


Tuesday, December 14, 2010                                                         15
NoSQL
                             Let’s Explore: redis




Tuesday, December 14, 2010                          16
NoSQL
                                      Let’s Explore: redis

                   • Versatile Key/Value Store
                   • Type Aware (Optional)
                         ‣   Nums, Strings, Lists, Sets, Hashes
                   • Atomic Operations
                   • Subscriptions
                   • Transactional (When needed)
                   • Customizable Durability
Tuesday, December 14, 2010                                        17
redis
                                Needs a Better R Package

                             > install.packages("rredis")
                             > require('rredis')
                             > redisConnect()

                             > key   <- 'zero'
                             > value <- 'hero'

                             > redisSet(key, value)
                             [1] TRUE

                             > redisGet(key)
                             [1] "hero"



Tuesday, December 14, 2010                                  18
redis
                              doRedis (rredis + foreach)
                                    redis Subscriptions

              # Uses Redis' publish/subscribe messaging to distribute workloads
              require('doRedis')

              registerDoRedis('jobs')

              foreach(j=1:1000,.combine=sum,.multicombine=TRUE) %dopar%
                      4*sum((runif(1000000)^2 + runif(1000000)^2)<1)/10000000

              removeQueue('jobs')




Tuesday, December 14, 2010                                                        19
redis
                                      Sets, From Ruby
               ruby                                    redis
               require "redis"

               redis = Redis.new
               users = %w{albert bernard charles}      redis> smembers "users"
                                                       1. "charles"
               users.each {|usr|
                 redis.sadd "users", usr
                                                       2. "bernard"
               }                                       3. "albert"

               redis.smembers "users"
               # => ["charles", "bernard", "albert"]




Tuesday, December 14, 2010                                                       20
redis
                             Set Intersections, Unions, Rand
                               admins = %w{bernard frank alice}

                               admins.each do |adm|
                                 redis.sadd "admins", adm
                               end

                               redis.sinter("users", "admins")

                               # => ["bernard"]

                               redis.sunion "admins", "users"

                               # => ["alice", "bernard", "albert",
                                     "frank", "charles"]

                               redis.srandmember "users"

                               # => "albert"


Tuesday, December 14, 2010                                           21
redis
                                    Atomic String Operations



                             redis.set "foo", "bar"
                             # => "OK"

                             redis.append "foo", "baz"
                             # => 6

                             redis.get "foo"
                             # => "barbaz"




Tuesday, December 14, 2010                                     22
redis
                                        Atomic Operations


                             # Strings
                             redis.set    "foo", "bar"          # => "OK"
                             redis.append "foo", "baz"          # => 6
                             redis.get    "foo"                 # => "barbaz"

                             # Fixnums
                             redis.set      "one", 1   #   =>    "OK"
                             redis.incr     "one"      #   =>    2
                             redis.incrby   "one", 3   #   =>    5
                             redis.get      "empty"    #   =>    nil
                             redis.incr     "empty"    #   =>    1
                             redis.get      "empty"    #   =>    "1"




Tuesday, December 14, 2010                                                      23

Weitere ähnliche Inhalte

KĂźrzlich hochgeladen

Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
lizamodels9
 
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Anamikakaur10
 
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai KuwaitThe Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
daisycvs
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
amitlee9823
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
dollysharma2066
 
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
amitlee9823
 

KĂźrzlich hochgeladen (20)

Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
Russian Call Girls In Rajiv Chowk Gurgaon ❤️8448577510 ⊹Best Escorts Service ...
 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and pains
 
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League City
 
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
 
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
Lundin Gold - Q1 2024 Conference Call Presentation (Revised)
 
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Nelamangala Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai KuwaitThe Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
 
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
 
Falcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investorsFalcon Invoice Discounting: The best investment platform in india for investors
Falcon Invoice Discounting: The best investment platform in india for investors
 
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 MonthsSEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
 
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
Call Girls Jp Nagar Just Call 👗 7737669865 👗 Top Class Call Girl Service Bang...
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
 
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
(Anamika) VIP Call Girls Napur Call Now 8617697112 Napur Escorts 24x7
 
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Hebbal Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 
Organizational Transformation Lead with Culture
Organizational Transformation Lead with CultureOrganizational Transformation Lead with Culture
Organizational Transformation Lead with Culture
 
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Majnu Ka Tilla, Delhi Contact Us 8377877756
 
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service AvailableCall Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
Call Girls Ludhiana Just Call 98765-12871 Top Class Call Girl Service Available
 
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort ServiceEluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
 
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
Call Girls Kengeri Satellite Town Just Call 👗 7737669865 👗 Top Class Call Gir...
 

Empfohlen

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Los Angeles R users group - Dec 14 2010 - Part 3

  • 1. NoSQL Scott Gonyea Epoch, LLC. @acts_as github.com/aitrus me@sgonyea.com Tuesday, December 14, 2010 1
  • 3. { {{ {{{ NoSQL }}} }} } * GONG * Tuesday, December 14, 2010 3
  • 4. NoSQL So... What is it? Tuesday, December 14, 2010 4
  • 5. NoSQL • It’s “Not SQL” • Less Structured; Sometimes Un-Structured • Usually Implies: • Key-Value Store • Document Datastore • Graph Databases (and its Variants) • Often not much more than that Tuesday, December 14, 2010 5
  • 6. NoSQL Recap and Comparison Tuesday, December 14, 2010 6
  • 7. NoSQL SELECT persons.* FROM persons LEFT JOIN automobiles ON persons.id = automobiles.person_id WHERE automobiles.color IS 'RED' /* Wait! We can NORMALIZE this some more! */ SELECT persons.* FROM persons LEFT JOIN automobiles LEFT JOIN colors ON persons.id = automobiles.person_id AND colors.id = automobiles.color_id WHERE colors.name IS 'RED-34' /* Wait! ... */ Tuesday, December 14, 2010 7
  • 8. NoSQL SELECT persons.* FROM persons LEFT JOIN automobiles ON persons.id = automobiles.person_id WHERE automobiles.color IS 'RED' /* Wait! We can NORMALIZE this some more! */ SELECT persons.*, automobiles.* /* Selects */ FROM persons LEFT JOIN automobiles /* Joins */ LEFT JOIN colors ON persons.id = automobiles.person_id AND colors.id = automobiles.color_id WHERE colors.name IS 'RED-34' /* Conditions */ /* Wait! ... */ Tuesday, December 14, 2010 8
  • 9. Persons NoSQL Colors id First Name Last Name id name 1 Seymore Butts 212 RED-34 2 Amanda Hugginkiss 213 BLUE-32 Join Table => PersonsVehicles id vehicle_id person_id color_id 1 7384 1 212 2 7231 2 212 Automobiles id make model Year 23192 Honda Civic 2003 19763 Chevy Tahoe 1998 Relationship: “Belongs To” => Vehicles id identier automobile_id Normalization 7231 7384 1FALP62W4WH128703 4WH1287031FALP62W 23192 19763 Tuesday, December 14, 2010 9
  • 10. NoSQL Key-Value Stores AKA: Dictionary, Hash Table, etc. KV Database Key Give me what’s at “John” “John” “Jo hn ” Value at “John” “Smith” “Smith” Tuesday, December 14, 2010 10
  • 11. NoSQL Key-Value Stores • Very Fast • Simple • Key-Value Pairs are Self-Contained ∴Easier Replication - Twitter, Facebook, Google, etc. - Also,Your Computer Tuesday, December 14, 2010 11
  • 12. NoSQL Document[-Oriented] Stores Very De-Normalized Less De-Normalized “John Smith” “John Smith” string rst_name John string rst_name John string last_name Smith string last_name Smith embedded automobiles embedded automobiles document doc_id make Honda document doc_ref vehicle id(fd18d0af6c053886d) string model Civic string color Red int year 2003 string employer Epoch, LLC. string color Red fd18d0af6c053886d string employer Epoch, LLC. string make Honda string model Civic int year 2003 embedded features document string breaks anti-lock bool air_cond TRUE geo_coord made_at 39.975542, -82.992096 Tuesday, December 14, 2010 12
  • 13. NoSQL Document[-Oriented] Stores • Analogous to Printed Documents • Varying Levels of De-normalization • Documents Still Relatively Self-Contained ∴Easier Replication, Too - Twitter, Facebook, Google, etc. Tuesday, December 14, 2010 13
  • 14. NoSQL Graph Databases untitled 6 4 5 1 3 2 Six Degrees of Separation or: How you realized you have no friends :-( Tuesday, December 14, 2010 14
  • 15. NoSQL Graph Databases • Relationships Derived Through “Distance” • Some Use-Cases: • Geographic • Networking • Routing / Shortest Path • Social • Molecular Modeling • Kevin Bacon Jokes • Also Quite Trendy: - Twitter, Facebook, Google [Maps, Mail, & Your Life] Tuesday, December 14, 2010 15
  • 16. NoSQL Let’s Explore: redis Tuesday, December 14, 2010 16
  • 17. NoSQL Let’s Explore: redis • Versatile Key/Value Store • Type Aware (Optional) ‣ Nums, Strings, Lists, Sets, Hashes • Atomic Operations • Subscriptions • Transactional (When needed) • Customizable Durability Tuesday, December 14, 2010 17
  • 18. redis Needs a Better R Package > install.packages("rredis") > require('rredis') > redisConnect() > key <- 'zero' > value <- 'hero' > redisSet(key, value) [1] TRUE > redisGet(key) [1] "hero" Tuesday, December 14, 2010 18
  • 19. redis doRedis (rredis + foreach) redis Subscriptions # Uses Redis' publish/subscribe messaging to distribute workloads require('doRedis') registerDoRedis('jobs') foreach(j=1:1000,.combine=sum,.multicombine=TRUE) %dopar% 4*sum((runif(1000000)^2 + runif(1000000)^2)<1)/10000000 removeQueue('jobs') Tuesday, December 14, 2010 19
  • 20. redis Sets, From Ruby ruby redis require "redis" redis = Redis.new users = %w{albert bernard charles} redis> smembers "users" 1. "charles" users.each {|usr| redis.sadd "users", usr 2. "bernard" } 3. "albert" redis.smembers "users" # => ["charles", "bernard", "albert"] Tuesday, December 14, 2010 20
  • 21. redis Set Intersections, Unions, Rand admins = %w{bernard frank alice} admins.each do |adm| redis.sadd "admins", adm end redis.sinter("users", "admins") # => ["bernard"] redis.sunion "admins", "users" # => ["alice", "bernard", "albert", "frank", "charles"] redis.srandmember "users" # => "albert" Tuesday, December 14, 2010 21
  • 22. redis Atomic String Operations redis.set "foo", "bar" # => "OK" redis.append "foo", "baz" # => 6 redis.get "foo" # => "barbaz" Tuesday, December 14, 2010 22
  • 23. redis Atomic Operations # Strings redis.set "foo", "bar" # => "OK" redis.append "foo", "baz" # => 6 redis.get "foo" # => "barbaz" # Fixnums redis.set "one", 1 # => "OK" redis.incr "one" # => 2 redis.incrby "one", 3 # => 5 redis.get "empty" # => nil redis.incr "empty" # => 1 redis.get "empty" # => "1" Tuesday, December 14, 2010 23