Presentation is loading. Please wait.

Presentation is loading. Please wait.

Square Pegs and Round Holes on the NOSQL World Jim Webber Chief Scientist, Neo

Similar presentations


Presentation on theme: "Square Pegs and Round Holes on the NOSQL World Jim Webber Chief Scientist, Neo"— Presentation transcript:

1

2 Square Pegs and Round Holes on the NOSQL World Jim Webber Chief Scientist, Neo

3 Koans A free tutorial that gets you up to speed with Neo4j through hacking https://github.com/jimwebber/neo4j-tutorial

4 Not Only SQL Remember that NOSQL means

5

6

7

8

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

10 Creating Relationships Transaction 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(); }

11

12

13

14

15 Document Database username: Jeff1986 age: 25 friend : SallyDJ friend : Gazza username: SallyDJ age: 28 friend : Jeff1986 friend: FunkySam username: FunkySam age: 24 friend : SallyDJ username: Gazza age: 32 friend : Jeff1986

16 Application Layer username: Jeff1986 age: 25 username: SallyDJ age: 28 username: FunkySam age: 24 username: Gazza age: 32 Document Database username: Jeff1986 age: 25 friend : SallyDJ friend : Gazza username: SallyDJ age: 28 friend : Jeff1986 friend: FunkySam username: FunkySam age: 24 friend : SallyDJ username: Gazza age: 32 friend : Jeff1986 Reify

17 Graph Database username: Jeff1986 age: 25 username: SallyDJ age: 28 username: FunkySam age: 24 username: Gazza age: 32 FRIEND

18

19 Graph Database username: SallyDJ age: 28 product: CoolDecks manufacturer : Acme price : 599 PURCHASE D product: SuperCans manufacturer : Acme price : 150 PURCHASE D username: Gazza age: 32 PURCHASE D Document Database username: SallyDJ age: 28 purchased : CoolDecks purchased : SuperCans username: Gazza age: 32 purchased : SuperCans product: SuperCans manufacturer : Acme price : 150 product: CoolDecks manufacturer : Acme price : 599

20

21 Graph Database product: CoolDecks manufacturer : Acme price : 599 PURCHASE D product: SuperCans manufacturer : Acme price : 150 PURCHASE D username: Jeff1986 age: 25 username: SallyDJ age: 28 username: FunkySam age: 24 username: Gazza age: 32 FRIEND

22

23 Graph Algorithms What’s the shortest path between the Doctor and the Master? Node theMaster = … Node theDoctor = … int maxDepth = 5; PathFinder shortestPathFinder = GraphAlgoFactory.shortestPath( Traversal.expanderForAllTypes(), maxDepth); Path shortestPath = shortestPathFinder.findSinglePath(theDoctor, theMaster);

24 Path finding Find all the episodes where Rose Tyler fought the Daleks

25 Path finder code Node rose =... Node daleks =... PathFinder pathFinder = GraphAlgoFactory.pathsWithLength( Traversal.expanderForTypes( DoctorWhoUniverse.APPEARED_IN, Direction.BOTH), 2); Iterable paths = pathFinder.findAllPaths(rose, daleks); algo constraints fixed path length

26 age: < 40 PURCHASED product: SuperCans manufacturer : Acme product: CoolDecks manufacturer : Acme !PURCHASED

27 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

28 In which episodes did the Doctor battle the Cybermen?

29 Setting up and matching a pattern final 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 matches = matcher.match(theDoctor, universe.theDoctor());

30

31

32 Questions? Community: Koans: https://github.com/jimwebber/neo4j-tutorial


Download ppt "Square Pegs and Round Holes on the NOSQL World Jim Webber Chief Scientist, Neo"

Similar presentations


Ads by Google