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.

Introduction to Graph Databases

1,930 views

Published on

Published in: Technology, Business
  • Be the first to comment

Introduction to Graph Databases

  1. 1. Introduction to Graph Databases Josh Adell <josh.adell@gmail.com> 20110806
  2. 2. Who am I? <ul><ul><li>Software developer: PHP, Javascript, SQL </li></ul></ul><ul><ul><li>http://www.dunnwell.com </li></ul></ul><ul><ul><li>Fan of using the right tool for the job </li></ul></ul>
  3. 3. The Problem
  4. 4. The Solution? <ul><li>> -- Given &quot;Keanu Reeves&quot; find a connection to &quot;Kevin Bacon&quot; </li></ul><ul><li>> SELECT ??? FROM cast WHERE ??? </li></ul><ul><li>+---------------------------------------------------------------------+ </li></ul><ul><li>| actor_name                 | movie_title                            | </li></ul><ul><li>+============================+========================================+ </li></ul><ul><li>| Jennifer Connelley         | Higher Learning                        | </li></ul><ul><li>+----------------------------+----------------------------------------+ </li></ul><ul><li>| Laurence Fishburne         | Mystic River                           | </li></ul><ul><li>+----------------------------+----------------------------------------+ </li></ul><ul><li>| Laurence Fishburne         | Higher Learning                        | </li></ul><ul><li>+----------------------------+----------------------------------------+ </li></ul><ul><li>| Kevin Bacon                | Mystic River                           | </li></ul><ul><li>+----------------------------+----------------------------------------+ </li></ul><ul><li>| Keanu Reeves               | The Matrix                             | </li></ul><ul><li>+----------------------------+----------------------------------------+ </li></ul><ul><li>| Laurence Fishburne         | The Matrix                             | </li></ul><ul><li>+----------------------------+----------------------------------------+ </li></ul>
  5. 5. Find Every Actor at Each Degree <ul><li>> -- First degree </li></ul><ul><li>> SELECT actor_name FROM cast WHERE movie_title IN (SELECT DISTINCT movie_title FROM cast WHERE actor_name='Kevin Bacon') </li></ul><ul><li>> -- Second degree </li></ul><ul><li>> SELECT actor_name FROM cast WHERE movie_title IN (SELECT DISTINCT movie_title FROM cast WHERE actor_name IN (SELECT actor_name FROM cast WHERE movie_title IN (SELECT DISTINCT movie_title FROM cast WHERE actor_name='Kevin Bacon'))) </li></ul><ul><li>> -- Third degree </li></ul><ul><li>> SELECT actor_name FROM cast WHERE movie_title IN(SELECT DISTINCT movie_title FROM cast WHERE actor_name IN (SELECT actor_name FROM cast WHERE movie_title IN (SELECT DISTINCT movie_title FROM cast WHERE actor_name IN (SELECT actor_name FROM cast WHERE movie_title IN (SELECT DISTINCT movie_title FROM cast WHERE actor_name='Kevin Bacon')))) </li></ul>
  6. 6. The Truth <ul><li>Relational databases aren't very good with relationsh ips </li></ul>Data RDBMs
  7. 7. The Real Problem <ul><li>Finding relationships across multiple degrees of separation </li></ul><ul><li>    ...and across multiple data types </li></ul><ul><li>    ...and where you don't even know there is a relationship </li></ul>
  8. 8. The Real Solution
  9. 9. Graph Examples
  10. 10. Relational Databases are Graphs!
  11. 11. Some Graph Use Cases <ul><ul><li>Social networking </li></ul></ul><ul><ul><li>Manufacturing </li></ul></ul><ul><ul><li>Mapping and Geolocation </li></ul></ul><ul><ul><li>Bioinformatics </li></ul></ul><ul><ul><li>Fraud detection </li></ul></ul><ul><ul><li>Multi-tenancy </li></ul></ul>
  12. 12. Modelling a Domain with Graphs <ul><ul><li>Graphs are &quot;whiteboard-friendly&quot; </li></ul></ul><ul><ul><li>Nouns become nodes </li></ul></ul><ul><ul><li>Verbs become relationships </li></ul></ul><ul><ul><li>Properties are adjectives and adverbs </li></ul></ul>
  13. 13. Graph Mining <ul><ul><li>Paths </li></ul></ul><ul><ul><li>Traversals </li></ul></ul><ul><ul><li>Ad-hoc Queries </li></ul></ul>
  14. 14. New Solution to the Bacon Problem $keanu = $actorIndex->find('name', 'Keanu Reeves'); $kevin = $actorIndex->find('name', 'Kevin Bacon'); $path = $keanu->findPathTo($kevin);
  15. 15. Cypher <ul><ul><li>&quot;What to find&quot; vs. &quot;How to find&quot; </li></ul></ul>// Find all the directors who have directed a movie scored by John Williams // that starred Kevin Bacon START actor=(actors, 'Kevin Bacon'), composer=(compsers, 'John Williams') MATCH (actor)-[:IN]->(movie)<-[:DIRECTED]-(director),       (movie)<-[:SCORED]-(composer) RETURN director
  16. 16. Are RDBs Useful At All? <ul><ul><li>Aggregation </li></ul></ul><ul><ul><li>Ordered data </li></ul></ul><ul><ul><li>Truly tabular data </li></ul></ul><ul><ul><li>Few or clearly defined relationships </li></ul></ul>
  17. 17. <ul><ul><li>Neo Technologies </li></ul></ul><ul><ul><li>http://neo4j.org </li></ul></ul><ul><ul><li>Embedded in Java applications </li></ul></ul><ul><ul><li>Standalone server via REST </li></ul></ul><ul><ul><li>Plugins: spatial, lucene, rdf </li></ul></ul><ul><li>Others: </li></ul><ul><ul><li>Tinkerpop </li></ul></ul><ul><ul><li>OrientDB </li></ul></ul>
  18. 18. Questions?
  19. 19. Resources <ul><ul><li>http://neo4j.org </li></ul></ul><ul><ul><li>http://docs.neo4j.org </li></ul></ul><ul><ul><li>http://www.youtube.com/watch?v=UodTzseLh04 </li></ul></ul><ul><ul><ul><li>Emil Eifrem (Neo Tech. CEO) webinar </li></ul></ul></ul><ul><ul><ul><li>Check out around the 54 minute mark </li></ul></ul></ul><ul><ul><li>http://github.com/jadell/Neo4jPHP </li></ul></ul><ul><ul><li>http://joshadell.com </li></ul></ul><ul><ul><li>[email_address] </li></ul></ul><ul><ul><li>@josh_adell </li></ul></ul><ul><ul><li>Google+, Facebook, LinkedIn </li></ul></ul>

×