Square Pegs and Round Holes on the NOSQL World

32

description

Square Pegs and Round Holes on the NOSQL World. Jim Webber Chief Scientist, Neo Technology @ jimwebber. Koans A free tutorial that gets you up to speed with Neo4j through hacking. http:// bit.ly /neo4j-koan https:// github.com / jimwebber /neo4j-tutorial. N ot O nly S QL. - PowerPoint PPT Presentation

Transcript of Square Pegs and Round Holes on the NOSQL World

Page 1: Square Pegs and Round Holes on the NOSQL World
Page 2: Square Pegs and Round Holes on the NOSQL World

Square Pegs and Round Holes on the NOSQL World

Jim WebberChief Scientist, Neo Technology

@jimwebber

Page 3: Square Pegs and Round Holes on the NOSQL World

KoansA free tutorial that gets you up to speed with Neo4j through hacking

http://bit.ly/neo4j-koanhttps://github.com/jimwebber/neo4j-tutorial

Page 4: Square Pegs and Round Holes on the NOSQL World

Not Only SQLRemember that NOSQL means

Page 5: Square Pegs and Round Holes on the NOSQL World

http://www.flickr.com/photos/crazyneighborlady/355232758/

Page 6: Square Pegs and Round Holes on the NOSQL World

http://gallery.nen.gov.uk/image82582-.html

Page 7: Square Pegs and Round Holes on the NOSQL World

http://www.xtranormal.com/watch/6995033/mongo-db-is-web-scale

Page 8: Square Pegs and Round Holes on the NOSQL World

http://www.orangesmile.com/destinations/img/berlin-map-metro-big.gif

Page 9: Square Pegs and Round Holes on the NOSQL World

Creating NodesGraphDatabaseService db = new EmbeddedGraphDatabase("/tmp/neo");Transaction tx = db.beginTx();try { Node theDoctor = db.createNode(); theDoctor.setProperty("name", "the Doctor"); tx.success();} finally { tx.finish();}

Page 10: Square Pegs and Round Holes on the NOSQL World

Creating RelationshipsTransaction tx = db.beginTx();try { Node theDoctor = db.createNode(); theDoctor.setProperty("name", "The Doctor");

Node susan = db.createNode(); susan.setProperty("firstname", "Susan"); susan.setProperty("lastname", "Campbell");

susan.createRelationshipTo(theDoctor, DynamicRelationshipType.withName("COMPANION_OF"));

tx.success();} finally { tx.finish();}

Page 11: Square Pegs and Round Holes on the NOSQL World

http://malden-dsme.co.uk/public/hcj.html

Page 12: Square Pegs and Round Holes on the NOSQL World

http://easystreetdiscount.auctivacommerce.com/Nirvana-Smiley-Face-Music-Band-Decal-Sticker-P188162.aspx

Page 13: Square Pegs and Round Holes on the NOSQL World

http://www.tolkienlibrary.com/press/922-Isildur_Poker_Champion.php

Page 14: Square Pegs and Round Holes on the NOSQL World

http://www.vaccinetimes.com/wp-content/uploads/2010/12/microscope.jpg

Page 15: Square Pegs and Round Holes on the NOSQL World

Document Database

username: Jeff1986age: 25

friend : SallyDJfriend : Gazza

username: SallyDJage: 28

friend : Jeff1986friend: FunkySam

username: FunkySamage: 24

friend : SallyDJ

username: Gazzaage: 32

friend : Jeff1986

Page 16: Square Pegs and Round Holes on the NOSQL World

Application Layer

username: Jeff1986age: 25

username: SallyDJage: 28

username: FunkySamage: 24

username: Gazzaage: 32

Document Database

username: Jeff1986age: 25

friend : SallyDJfriend : Gazza

username: SallyDJage: 28

friend : Jeff1986friend: FunkySam

username: FunkySamage: 24

friend : SallyDJ

username: Gazzaage: 32

friend : Jeff1986Re

ify

Page 17: Square Pegs and Round Holes on the NOSQL World

Graph Database

username: Jeff1986age: 25

username: SallyDJage: 28

username: FunkySamage: 24

username: Gazzaage: 32

FRIE

ND FRIEND

FRIEND

Page 18: Square Pegs and Round Holes on the NOSQL World

http://www.freewebs.com/fictionfrek101/han.jpg

Page 19: Square Pegs and Round Holes on the NOSQL World

Graph Database

username: SallyDJage: 28

product: CoolDecksmanufacturer : Acme

price : 599PU

RCHA

SED

product: SuperCansmanufacturer : Acme

price : 150

PURCHASE

D

username: Gazzaage: 32

PURC

HASE

D

Document Database

username: SallyDJage: 28

purchased : CoolDecks

purchased : SuperCans

username: Gazzaage: 32

purchased : SuperCans

product: SuperCans

manufacturer : Acmeprice : 150

product: CoolDecks

manufacturer : Acmeprice : 599

Page 20: Square Pegs and Round Holes on the NOSQL World

http://xkcd.com/653/

Page 21: Square Pegs and Round Holes on the NOSQL World

Graph Database

product: CoolDecksmanufacturer : Acme

price : 599

PURCHASED

product: SuperCansmanufacturer : Acme

price : 150

PURCHASED

PURC

HASE

D

username: Jeff1986age: 25

username: SallyDJage: 28

username: FunkySamage: 24

username: Gazzaage: 32

FRIE

ND FRIEND

FRIEND

Page 22: Square Pegs and Round Holes on the NOSQL World

http://void.iddqd.cz/comic-book-guy-pc.jpg

Page 23: Square Pegs and Round Holes on the NOSQL World

Graph AlgorithmsWhat’s the shortest path between the Doctor and the Master?

Node theMaster = …Node theDoctor = … int maxDepth = 5; PathFinder<Path> shortestPathFinder = GraphAlgoFactory.shortestPath( Traversal.expanderForAllTypes(), maxDepth); Path shortestPath = shortestPathFinder.findSinglePath(theDoctor, theMaster);

Page 24: Square Pegs and Round Holes on the NOSQL World

Path findingFind all the episodes where Rose Tyler fought the Daleks

Page 25: Square Pegs and Round Holes on the NOSQL World

Path finder codeNode rose = ...Node daleks = ...

PathFinder<Path> pathFinder = GraphAlgoFactory.pathsWithLength( Traversal.expanderForTypes( DoctorWhoUniverse.APPEARED_IN, Direction.BOTH), 2);

Iterable<Path> paths = pathFinder.findAllPaths(rose, daleks);

algo

constraintsfixed path length

Page 26: Square Pegs and Round Holes on the NOSQL World

age: < 40

PURC

HASED

product: SuperCansmanufacturer : Acme

product: CoolDecksmanufacturer : Acme

!PURCHASED

Page 27: Square Pegs and Round Holes on the NOSQL World

Why graph matching?

• It’s super-powerful for looking for patterns in a data set– TW has done retail analytics PoCs (and hopefully

projects) with this stuff• Higher-level abstraction than raw traversers– Uses PatternNode and PatternRelationship types to describe graph patterns

– The “unbound” parts of the graph

Page 28: Square Pegs and Round Holes on the NOSQL World

In which episodes did the Doctor battle the Cybermen?

Page 29: Square Pegs and Round Holes on the NOSQL World

Setting up and matching a patternfinal PatternNode theDoctor = new PatternNode();theDoctor.setAssociation(universe.theDoctor());

final PatternNode anEpisode = new PatternNode();anEpisode.addPropertyConstraint("title", CommonValueMatchers.has());anEpisode.addPropertyConstraint("episode", CommonValueMatchers.has());

final PatternNode aDoctorActor = new PatternNode();aDoctorActor.createRelationshipTo(theDoctor, DoctorWhoUniverse.PLAYED);aDoctorActor.createRelationshipTo(anEpisode, DoctorWhoUniverse.APPEARED_IN);aDoctorActor.addPropertyConstraint("actor", CommonValueMatchers.has());

final PatternNode theCybermen = new PatternNode();theCybermen.setAssociation(universe.speciesIndex.get("species", "Cyberman").getSingle());theCybermen.createRelationshipTo(anEpisode, DoctorWhoUniverse.APPEARED_IN);theCybermen.createRelationshipTo(theDoctor, DoctorWhoUniverse.ENEMY_OF);

PatternMatcher matcher = PatternMatcher.getMatcher();final Iterable<PatternMatch> matches = matcher.match(theDoctor, universe.theDoctor());

Page 30: Square Pegs and Round Holes on the NOSQL World

http://male-ejaculation.net/

Page 31: Square Pegs and Round Holes on the NOSQL World

http://www.561studios.com/blog/wp-content/uploads/2010/07/commonsense.jpg

Page 32: Square Pegs and Round Holes on the NOSQL World

Questions?Community: http://neo4j.orgKoans: https://github.com/jimwebber/neo4j-tutorialMe: @jimwebber, [email protected]