square pegs and round holes on the nosql world

Post on 24-Feb-2016

52 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

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

Square Pegs and Round Holes on the NOSQL World

Jim WebberChief Scientist, Neo Technology

@jimwebber

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

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

Not Only SQLRemember that NOSQL means

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

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

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

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

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();}

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();}

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

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

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

http://www.vaccinetimes.com/wp-content/uploads/2010/12/microscope.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

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

Graph Database

username: Jeff1986age: 25

username: SallyDJage: 28

username: FunkySamage: 24

username: Gazzaage: 32

FRIE

ND FRIEND

FRIEND

http://www.freewebs.com/fictionfrek101/han.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

http://xkcd.com/653/

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

http://void.iddqd.cz/comic-book-guy-pc.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);

Path findingFind all the episodes where Rose Tyler fought the Daleks

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

age: < 40

PURC

HASED

product: SuperCansmanufacturer : Acme

product: CoolDecksmanufacturer : Acme

!PURCHASED

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

In which episodes did the Doctor battle the Cybermen?

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());

http://male-ejaculation.net/

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

Questions?Community: http://neo4j.orgKoans: https://github.com/jimwebber/neo4j-tutorialMe: @jimwebber, jim@neotechnology.com

top related