introduction to graph databases

19
Introduction to Graph Databases Josh Adell <[email protected]> 20110806

Upload: josh-adell

Post on 21-Jan-2015

1.449 views

Category:

Technology


5 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Introduction to Graph Databases

Introduction toGraph Databases

Josh Adell <[email protected]>20110806

Page 2: Introduction to Graph Databases

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

The Problem

Page 4: Introduction to Graph Databases

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

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

The Truth

Relational databases aren't very good with relationships

Data

RDBMs

Page 7: Introduction to Graph Databases

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

The Real Solution

Page 9: Introduction to Graph Databases

Graph Examples

Page 10: Introduction to Graph Databases

Relational Databases are Graphs!

Page 11: Introduction to Graph Databases

Some Graph Use Cases

• Social networking• Manufacturing• Mapping and Geolocation• Bioinformatics• Fraud detection• Multi-tenancy

Page 12: Introduction to Graph Databases

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

Graph Mining

• Paths• Traversals• Ad-hoc Queries

Page 14: Introduction to Graph Databases

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

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

Are RDBs Useful At All?

• Aggregation• Ordered data• Truly tabular data• Few or clearly defined relationships

Page 17: Introduction to Graph Databases

• 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

Questions?

Page 19: Introduction to Graph Databases

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