Square Pegs and Round Holes on the NOSQL World
description
Transcript of Square Pegs and Round Holes on the NOSQL World
![Page 1: Square Pegs and Round Holes on the NOSQL World](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/1.jpg)
![Page 2: Square Pegs and Round Holes on the NOSQL World](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/2.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/3.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/4.jpg)
Not Only SQLRemember that NOSQL means
![Page 5: Square Pegs and Round Holes on the NOSQL World](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/5.jpg)
http://www.flickr.com/photos/crazyneighborlady/355232758/
![Page 6: Square Pegs and Round Holes on the NOSQL World](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/6.jpg)
http://gallery.nen.gov.uk/image82582-.html
![Page 7: Square Pegs and Round Holes on the NOSQL World](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/7.jpg)
http://www.xtranormal.com/watch/6995033/mongo-db-is-web-scale
![Page 8: Square Pegs and Round Holes on the NOSQL World](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/8.jpg)
http://www.orangesmile.com/destinations/img/berlin-map-metro-big.gif
![Page 9: Square Pegs and Round Holes on the NOSQL World](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/9.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/10.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/11.jpg)
http://malden-dsme.co.uk/public/hcj.html
![Page 12: Square Pegs and Round Holes on the NOSQL World](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/12.jpg)
http://easystreetdiscount.auctivacommerce.com/Nirvana-Smiley-Face-Music-Band-Decal-Sticker-P188162.aspx
![Page 13: Square Pegs and Round Holes on the NOSQL World](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/13.jpg)
http://www.tolkienlibrary.com/press/922-Isildur_Poker_Champion.php
![Page 14: Square Pegs and Round Holes on the NOSQL World](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/14.jpg)
http://www.vaccinetimes.com/wp-content/uploads/2010/12/microscope.jpg
![Page 15: Square Pegs and Round Holes on the NOSQL World](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/15.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/16.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/17.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/18.jpg)
http://www.freewebs.com/fictionfrek101/han.jpg
![Page 19: Square Pegs and Round Holes on the NOSQL World](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/19.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/20.jpg)
http://xkcd.com/653/
![Page 21: Square Pegs and Round Holes on the NOSQL World](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/21.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/22.jpg)
http://void.iddqd.cz/comic-book-guy-pc.jpg
![Page 23: Square Pegs and Round Holes on the NOSQL World](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/23.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/24.jpg)
Path findingFind all the episodes where Rose Tyler fought the Daleks
![Page 25: Square Pegs and Round Holes on the NOSQL World](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/25.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/26.jpg)
age: < 40
PURC
HASED
product: SuperCansmanufacturer : Acme
product: CoolDecksmanufacturer : Acme
!PURCHASED
![Page 27: Square Pegs and Round Holes on the NOSQL World](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/27.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/28.jpg)
In which episodes did the Doctor battle the Cybermen?
![Page 29: Square Pegs and Round Holes on the NOSQL World](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/29.jpg)
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](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/30.jpg)
http://male-ejaculation.net/
![Page 31: Square Pegs and Round Holes on the NOSQL World](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/31.jpg)
http://www.561studios.com/blog/wp-content/uploads/2010/07/commonsense.jpg
![Page 32: Square Pegs and Round Holes on the NOSQL World](https://reader035.fdocuments.in/reader035/viewer/2022081505/568165a2550346895dd880b2/html5/thumbnails/32.jpg)
Questions?Community: http://neo4j.orgKoans: https://github.com/jimwebber/neo4j-tutorialMe: @jimwebber, [email protected]