Gerry McNicol Graph Databases

294 views
216 views

Published on

An introduction to Graph databases and in particular Neo4j, including where Neo4j lives on the CAP Scale in relation to other databases, the Graph data model and a very quick introduction to the Cypher Query Language.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
294
On SlideShare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
3
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Gerry McNicol Graph Databases

  1. 1. Graph Databases @gerrymcnicol
  2. 2. What is a Graph Database?
  3. 3. Relational - RDBMS MySQL MS SQL Server Oracle IBM DB2 Terra Data
  4. 4. Relational - RDBMS
  5. 5. Functions Relational - RDBMS Triggers Atomic Consistent Isolated Durable SQL Language Referential Integrity Indexes Stored Procedures Multi-Dimensional Modelling (cubes)
  6. 6. Neo4j
  7. 7. Data Model
  8. 8. Data Model Thing
  9. 9. Data Model Thing Relational
  10. 10. Data Model Thing Relational Graph
  11. 11. Data Model Thing Database Server Relational Graph
  12. 12. Data Model Thing Relational Database Server Yes Graph
  13. 13. Data Model Thing Database Server Relational Graph Yes Yes (and possibly no)
  14. 14. Data Model Thing Database Server Catalogue Relational Graph Yes Yes (and possibly no)
  15. 15. Data Model Thing Relational Graph Database Server Yes Yes (and possibly no) Catalogue Yes
  16. 16. Data Model Thing Relational Graph Database Server Yes Yes (and possibly no) Catalogue Yes No
  17. 17. Data Model Thing Relational Graph Database Server Yes Yes (and possibly no) Catalogue Yes No Table
  18. 18. Data Model Thing Relational Graph Database Server Yes Yes (and possibly no) Catalogue Yes No Table Yes
  19. 19. Data Model Thing Relational Graph Database Server Yes Yes (and possibly no) Catalogue Yes No Table Yes No
  20. 20. Data Model Thing Relational Graph Database Server Yes Yes (and possibly no) Catalogue Yes No Table Yes No Row
  21. 21. Data Model Thing Relational Graph Database Server Yes Yes (and possibly no) Catalogue Yes No Table Yes No Row Yes
  22. 22. Data Model Thing Relational Graph Database Server Yes Yes (and possibly no) Catalogue Yes No Table Yes No Row Yes No
  23. 23. Data Model Thing Relational Graph Database Server Yes Yes (and possibly no) Catalogue Yes No Table Yes No Row Yes No Cell?
  24. 24. Data Model Thing Relational Graph Database Server Yes Yes (and possibly no) Catalogue Yes No Table Yes No Row Yes No Cell? Yes
  25. 25. Data Model Thing Relational Graph Database Server Yes Yes (and possibly no) Catalogue Yes No Table Yes No Row Yes No Cell? Yes No
  26. 26. Data Model Thing Relational Graph Database Server Yes Yes (and possibly no) Catalogue Yes No Table Yes No Row Yes No Cell? Yes No Relationship
  27. 27. Data Model Thing Relational Graph Database Server Yes Yes (and possibly no) Catalogue Yes No Table Yes No Row Yes No Cell? Yes No Relationship Yes
  28. 28. Data Model Thing Relational Graph Database Server Yes Yes (and possibly no) Catalogue Yes No Table Yes No Row Yes No Cell? Yes No Relationship Yes Yes! (well, kind of..)
  29. 29. What is a Graph?
  30. 30. What is a Graph? Gerry
  31. 31. What is a Graph? Gerry Tom
  32. 32. What is a Graph? Gerry Tom
  33. 33. What is a Graph? FRIENDS_WITH Gerry Tom
  34. 34. What is a Graph? FRIENDS_WITH Gerry Formula 1 Tom Tennis Mouse
  35. 35. What is a Graph? FRIENDS_WITH Gerry Tom IS_A Formula 1 Tennis Mouse
  36. 36. What is a Graph? FRIENDS_WITH Gerry Tom IS_A Formula 1 CHASES Tennis Mouse
  37. 37. What is a Graph? FRIENDS_WITH Gerry Tom LIKES IS_A Formula 1 Tennis CHASES Mouse
  38. 38. What is a Graph? FRIENDS_WITH Gerry LIKES Formula 1 Tom LIKES IS_A Tennis CHASES Mouse
  39. 39. What is a Graph? FRIENDS_WITH Gerry DRIVES_IN Formula 1 LIKES Tom LIKES IS_A Tennis CHASES Mouse
  40. 40. FRIENDS_WITH Gerry DRIVES_IN Formula 1 LIKES Tom LIKES IS_A Tennis CHASES Mouse
  41. 41. FRIENDS_WITH Gerry DRIVES_IN LIKES Tom LIKES IS_A Tennis Formula 1 IS_A CHASES Mouse
  42. 42. FRIENDS_WITH Gerry DRIVES_IN Tom LIKES LIKES IS_A Tennis Formula 1 IS_A Sport CHASES Mouse
  43. 43. FRIENDS_WITH Gerry DRIVES_IN Tom LIKES LIKES IS_A Tennis Formula 1 IS_A IS_A Sport CHASES Mouse
  44. 44. Bristol Taunton London Exeter S'hampton
  45. 45. Bristol TRAIN TRAIN BUS Taunton London TRAIN TRAIN TRAIN BUS Exeter S'hampton HORSE
  46. 46. Bristol TRAIN time:65 TRAIN BUS time:35 time:120 busco:mega Taunton London TRAIN time:45 TRAIN TRAIN time:34 BUS time:31 time:37 busco:mega Exeter S'hampton HORSE time:453 name: buttercup
  47. 47. Bristol TRAIN stn:btm time:65 TRAIN BUS time:35 time:120 busco:mega Taunton London stn:trs stn:lpad TRAIN time:45 TRAIN TRAIN time:34 BUS time:31 time:37 busco:mega Exeter stn:esd S'hampton HORSE time:453 name: buttercup stn:ssm
  48. 48. What is a Graph? • Made up of Nodes and Relationships • Nodes are connected by Relationships • Every Relationship has ... • a starting and ending Node • a direction • Both Nodes and Relationships can have properties. • Very flexible data structure
  49. 49. Bristol TRAIN stn:btm time:65 TRAIN BUS time:35 time:120 busco:mega Taunton London stn:trs time:37 busco:mega TRAIN time:45 TRAIN TRAIN time:34 time:31 Exeter stn:esd S'hampton HORSE time:453 name: buttercup stn:ssm BUS stn:lpad
  50. 50. Bristol TRAIN stn:btm time:65 TRAIN BUS time:35 time:120 busco:mega Taunton London stn:trs time:37 busco:mega TRAIN time:45 TRAIN TRAIN stn:lpad BUS time:34 time:31 Exeter stn:esd Gerry S'hampton HORSE time:453 name: buttercup stn:ssm LIKES
  51. 51. Bristol TRAIN TRAI BUS Taunto n TRAIN Londo n TRAIN BUS TRAIN Exeter HORSE S'ham pton Gerry FRIENDS Tom LIKE DRIVE LIKE Formu la 1 LIKE IS_ Tennis IS_A IS_A Sport CHASE Mouse
  52. 52. Use Cases • Very powerful and flexible data model • Semantically rich - very descriptive • Densely-connected data sets • Variably Structured data sets
  53. 53. Use Cases Situations where we need to understand not only that somethings are connected, but also something about those connections. ! e.g. strength, weight, quality
  54. 54. Use Cases • Communication networks • Medical Pathways • Recommendation Engines • Transport Network • Fraud rings • Data Center Networks • Access Control • Electricity Grids • Logistics Networks • Time series
  55. 55. Graph databases • Neo4j • FlockDB • AllegroGraph • InfiniteGraph • HypergraphDB
  56. 56. Neo4j • ACID compliment • Open source - community option • Good driver support - REST API, .net, java, php, ruby, python, scala, node.js, etc... • Has a powerful query language - Cypher
  57. 57. Cypher: Creating Nodes and Relationships
  58. 58. Cypher: Creating Nodes and Relationships name:Gerry
  59. 59. Cypher: Creating Nodes and Relationships name:Gerry CREATE ({name:’Gerry’});
  60. 60. Cypher: Creating Nodes and Relationships name:Gerry
  61. 61. Cypher: Creating Nodes and Relationships name:Gerry CREATE (u:user {name:’Gerry’}) return u;
  62. 62. Cypher: Creating Nodes and Relationships name:Gerry CREATE (u:user {name:’Gerry’}) return u; Node type label
  63. 63. Cypher: Creating Nodes and Relationships name:Gerry CREATE (u:user {name:’Gerry’}) return u; Node type label ‘u’ is is declared and, in the context of this statement, represents the node.
  64. 64. Cypher: Creating Nodes and Relationships name:Gerry name:Tom
  65. 65. Cypher: Creating Nodes and Relationships name:Gerry name:Tom CREATE (u:user {name:’Gerry’}) WITH u CREATE (t:user {name:’Tom’}) RETURN u,t;
  66. 66. Cypher: Creating Nodes and Relationships name:Gerry name:Tom
  67. 67. Cypher: Creating Nodes and Relationships FRIENDS_WITH name:Gerry name:Tom
  68. 68. Cypher: Creating Nodes and Relationships FRIENDS_WITH name:Gerry name:Tom CREATE (u:user {name:’Gerry’}) WITH u CREATE (t:user {name:’Tom’}) WITH u,t CREATE (u)-[r:FRIENDS_WITH]->(t) RETURN u,t,r;
  69. 69. Cypher: Creating Nodes and Relationships FRIENDS_WITH name:Gerry name:Tom {since: 10/1/2013} CREATE (u:user {name:’Gerry’}) WITH u CREATE (t:user {name:’Tom’}) WITH u,t CREATE (u)-[r:FRIENDS_WITH {since:’10/01/2013’}]->(t) RETURN u,t,r;
  70. 70. Cypher: Selecting Stuff name:Gerry name:Pete name:Barry name:Tom
  71. 71. Cypher: Selecting Stuff name:Gerry name:Pete name:Barry name:Tom match (n:user) return n;
  72. 72. Cypher: Selecting Stuff name:Gerry name:Pete name:Barry name:Tom match (n:user) return n; name:Pete match (n:user{name:’Pete’}) return n;
  73. 73. Cypher: Selecting Stuff name:Pete FRIENDS_WITH name:Gerry FRIENDS_WITH FRIENDS_WITH name:Tom name:Barry
  74. 74. Cypher: Selecting Stuff name:Pete FRIENDS_WITH name:Gerry FRIENDS_WITH FRIENDS_WITH name:Barry name:Tom MATCH (u:user {name:’Gerry'}) WITH u MATCH (u)-[FRIENDS_WITH*0..1]-(f) RETURN f;
  75. 75. Cypher: Selecting Stuff name:Pete FRIENDS_WITH name:Gerry FRIENDS_WITH FRIENDS_WITH name:Tom name:Barry
  76. 76. Cypher: Selecting Stuff name:Pete FRIENDS_WITH name:Gerry FRIENDS_WITH FRIENDS_WITH name:Barry FRIENDS_WITH name:Tom MATCH (u:user {name:’Gerry'}) WITH u MATCH (u)-[FRIENDS_WITH*0..2]-(f) RETURN f; name:Alan
  77. 77. Demo
  78. 78. www.neo4j.org http://graphdatabases.com Ian Robinson http://gerrymcnicol.com @gerrymcnicol

×