introduction to graph databases
DESCRIPTION
TRANSCRIPT
![Page 2: Introduction to Graph Databases](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54bf96cb4a7959f47f8b4597/html5/thumbnails/2.jpg)
Who am I?
• Software developer: PHP, Javascript, SQL• http://www.dunnwell.com• Fan of using the right tool for the job
![Page 3: Introduction to Graph Databases](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54bf96cb4a7959f47f8b4597/html5/thumbnails/3.jpg)
The Problem
![Page 4: Introduction to Graph Databases](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54bf96cb4a7959f47f8b4597/html5/thumbnails/4.jpg)
The Solution?
> -- Given "Keanu Reeves" find a connection to "Kevin Bacon"> SELECT ??? FROM cast WHERE ???
+---------------------------------------------------------------------+| actor_name | movie_title |+============================+========================================+| Jennifer Connelley | Higher Learning |+----------------------------+----------------------------------------+| Laurence Fishburne | Mystic River |+----------------------------+----------------------------------------+| Laurence Fishburne | Higher Learning |+----------------------------+----------------------------------------+| Kevin Bacon | Mystic River |+----------------------------+----------------------------------------+| Keanu Reeves | The Matrix |+----------------------------+----------------------------------------+| Laurence Fishburne | The Matrix |+----------------------------+----------------------------------------+
![Page 5: Introduction to Graph Databases](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54bf96cb4a7959f47f8b4597/html5/thumbnails/5.jpg)
Find Every Actor at Each Degree
> -- First degree> SELECT actor_name FROM cast WHERE movie_title IN (SELECT DISTINCT movie_title FROM cast WHERE actor_name='Kevin Bacon')
> -- Second degree> 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')))
> -- Third degree> 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'))))
![Page 6: Introduction to Graph Databases](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54bf96cb4a7959f47f8b4597/html5/thumbnails/6.jpg)
The Truth
Relational databases aren't very good with relationships
Data
RDBMs
![Page 7: Introduction to Graph Databases](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54bf96cb4a7959f47f8b4597/html5/thumbnails/7.jpg)
The Real Problem
Finding relationships across multiple degrees of separation ...and across multiple data types ...and where you don't even know there is a relationship
![Page 8: Introduction to Graph Databases](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54bf96cb4a7959f47f8b4597/html5/thumbnails/8.jpg)
The Real Solution
![Page 9: Introduction to Graph Databases](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54bf96cb4a7959f47f8b4597/html5/thumbnails/9.jpg)
Graph Examples
![Page 10: Introduction to Graph Databases](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54bf96cb4a7959f47f8b4597/html5/thumbnails/10.jpg)
Relational Databases are Graphs!
![Page 11: Introduction to Graph Databases](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54bf96cb4a7959f47f8b4597/html5/thumbnails/11.jpg)
Some Graph Use Cases
• Social networking• Manufacturing• Mapping and Geolocation• Bioinformatics• Fraud detection• Multi-tenancy
![Page 12: Introduction to Graph Databases](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54bf96cb4a7959f47f8b4597/html5/thumbnails/12.jpg)
Modelling a Domain with Graphs
• Graphs are "whiteboard-friendly"• Nouns become nodes• Verbs become relationships• Properties are adjectives and adverbs
![Page 13: Introduction to Graph Databases](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54bf96cb4a7959f47f8b4597/html5/thumbnails/13.jpg)
Graph Mining
• Paths• Traversals• Ad-hoc Queries
![Page 14: Introduction to Graph Databases](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54bf96cb4a7959f47f8b4597/html5/thumbnails/14.jpg)
New Solution to the Bacon Problem
$keanu = $actorIndex->find('name', 'Keanu Reeves');$kevin = $actorIndex->find('name', 'Kevin Bacon');
$path = $keanu->findPathTo($kevin);
![Page 15: Introduction to Graph Databases](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54bf96cb4a7959f47f8b4597/html5/thumbnails/15.jpg)
Cypher
• "What to find" vs. "How to find"
// 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
![Page 16: Introduction to Graph Databases](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54bf96cb4a7959f47f8b4597/html5/thumbnails/16.jpg)
Are RDBs Useful At All?
• Aggregation• Ordered data• Truly tabular data• Few or clearly defined relationships
![Page 17: Introduction to Graph Databases](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54bf96cb4a7959f47f8b4597/html5/thumbnails/17.jpg)
• Neo Technologies• http://neo4j.org• Embedded in Java applications• Standalone server via REST• Plugins: spatial, lucene, rdf
Others:• Tinkerpop• OrientDB
![Page 18: Introduction to Graph Databases](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54bf96cb4a7959f47f8b4597/html5/thumbnails/18.jpg)
Questions?
![Page 19: Introduction to Graph Databases](https://reader035.vdocuments.mx/reader035/viewer/2022081414/54bf96cb4a7959f47f8b4597/html5/thumbnails/19.jpg)
Resources
• http://neo4j.org• http://docs.neo4j.org• http://www.youtube.com/watch?v=UodTzseLh04
o Emil Eifrem (Neo Tech. CEO) webinaro Check out around the 54 minute mark
• http://github.com/jadell/Neo4jPHP
• http://joshadell.com• [email protected]• @josh_adell• Google+, Facebook, LinkedIn