gerry mcnicol graph databases

80
Graph Databases @gerrymcnicol

Upload: gerry-mcnicol

Post on 15-Jan-2015

136 views

Category:

Technology


3 download

DESCRIPTION

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.

TRANSCRIPT

Page 1: Gerry McNicol Graph Databases

Graph Databases

@gerrymcnicol

Page 2: Gerry McNicol Graph Databases

What is a Graph Database?

Page 3: Gerry McNicol Graph Databases

Relational - RDBMSMySQL

MS SQL Server

Oracle

IBM DB2

Terra Data

Page 4: Gerry McNicol Graph Databases

Relational - RDBMS

Page 5: Gerry McNicol Graph Databases

Relational - RDBMSAtomicConsistentIsolatedDurable

SQL Language

IndexesStored Procedures

Functions

Multi-Dimensional Modelling (cubes)

Triggers

Referential Integrity

Page 6: Gerry McNicol Graph Databases
Page 7: Gerry McNicol Graph Databases
Page 8: Gerry McNicol Graph Databases

Neo4j

Page 9: Gerry McNicol Graph Databases

Data Model

Page 10: Gerry McNicol Graph Databases

Data ModelThing

Page 11: Gerry McNicol Graph Databases

Data ModelThing Relational

Page 12: Gerry McNicol Graph Databases

Data ModelThing Relational Graph

Page 13: Gerry McNicol Graph Databases

Data ModelThing Relational Graph

Database Server

Page 14: Gerry McNicol Graph Databases

Data ModelThing Relational Graph

Database Server Yes

Page 15: Gerry McNicol Graph Databases

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Page 16: Gerry McNicol Graph Databases

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue

Page 17: Gerry McNicol Graph Databases

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes

Page 18: Gerry McNicol Graph Databases

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Page 19: Gerry McNicol Graph Databases

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Table

Page 20: Gerry McNicol Graph Databases

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Table Yes

Page 21: Gerry McNicol Graph Databases

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Table Yes No

Page 22: Gerry McNicol Graph Databases

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Table Yes No

Row

Page 23: Gerry McNicol Graph Databases

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Table Yes No

Row Yes

Page 24: Gerry McNicol Graph Databases

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Table Yes No

Row Yes No

Page 25: Gerry McNicol Graph Databases

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Table Yes No

Row Yes No

Cell?

Page 26: Gerry McNicol Graph Databases

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Table Yes No

Row Yes No

Cell? Yes

Page 27: Gerry McNicol Graph Databases

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Table Yes No

Row Yes No

Cell? Yes No

Page 28: Gerry McNicol Graph Databases

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Table Yes No

Row Yes No

Cell? Yes No

Relationship

Page 29: Gerry McNicol Graph Databases

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Table Yes No

Row Yes No

Cell? Yes No

Relationship Yes

Page 30: Gerry McNicol Graph Databases

Data ModelThing 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..)

Page 31: Gerry McNicol Graph Databases

What is a Graph?

Page 32: Gerry McNicol Graph Databases

What is a Graph?

Gerry

Page 33: Gerry McNicol Graph Databases

What is a Graph?

Gerry Tom

Page 34: Gerry McNicol Graph Databases

What is a Graph?

Gerry Tom

Page 35: Gerry McNicol Graph Databases

What is a Graph?

Gerry TomFRIENDS_WITH

Page 36: Gerry McNicol Graph Databases

What is a Graph?

Gerry TomFRIENDS_WITH

Tennis MouseFormula 1

Page 37: Gerry McNicol Graph Databases

What is a Graph?

Gerry TomFRIENDS_WITH

Tennis MouseFormula 1

IS_A

Page 38: Gerry McNicol Graph Databases

What is a Graph?

Gerry TomFRIENDS_WITH

Tennis MouseFormula 1

CHASESIS_A

Page 39: Gerry McNicol Graph Databases

What is a Graph?

Gerry TomFRIENDS_WITH

Tennis MouseFormula 1

LIKES CHASESIS_A

Page 40: Gerry McNicol Graph Databases

What is a Graph?

Gerry TomFRIENDS_WITH

Tennis MouseFormula 1

LIKES CHASESIS_ALIKES

Page 41: Gerry McNicol Graph Databases

What is a Graph?

Gerry TomFRIENDS_WITH

Tennis MouseFormula 1

LIKES CHASESIS_ALIKESDRIVES_IN

Page 42: Gerry McNicol Graph Databases

Gerry TomFRIENDS_WITH

Tennis MouseFormula 1

LIKES CHASESIS_ALIKESDRIVES_IN

Page 43: Gerry McNicol Graph Databases

Gerry TomFRIENDS_WITH

Tennis MouseFormula 1

LIKES CHASESIS_ALIKESDRIVES_IN

IS_A

Page 44: Gerry McNicol Graph Databases

Gerry TomFRIENDS_WITH

Tennis MouseFormula 1

LIKES CHASESIS_ALIKESDRIVES_IN

Sport

IS_A

Page 45: Gerry McNicol Graph Databases

Gerry TomFRIENDS_WITH

Tennis MouseFormula 1

LIKES CHASESIS_ALIKESDRIVES_IN

Sport

IS_AIS_A

Page 46: Gerry McNicol Graph Databases

Exeter

London

S'hampton

Bristol

Taunton

Page 47: Gerry McNicol Graph Databases

Exeter

London

S'hampton

Bristol

Taunton

HORSE

TRAIN

TRAIN TRAIN

TRAINBUS

TRAIN

BUS

Page 48: Gerry McNicol Graph Databases

Exeter

London

S'hampton

Bristol

Taunton

HORSE

TRAIN

TRAIN TRAIN

TRAINBUS

TRAIN

BUStime:35 time:120

busco:mega

time:37busco:mega

time:34

time:31

time:65

time:45

time:453name: buttercup

Page 49: Gerry McNicol Graph Databases

Exeter

London

S'hampton

Bristol

Taunton

HORSE

TRAIN

TRAIN TRAIN

TRAINBUS

TRAIN

BUStime:35 time:120

busco:mega

time:37busco:mega

time:34

time:31

time:65

time:45

time:453name: buttercup

stn:esd

stn:trs

stn:ssm

stn:btm

stn:lpad

Page 50: Gerry McNicol Graph Databases

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

Page 51: Gerry McNicol Graph Databases

Exeter

London

S'hampton

Bristol

Taunton

HORSE

TRAIN

TRAIN TRAIN

TRAIN

BUS

TRAIN

BUStime:35 time:120

busco:mega

time:37 busco:mega

time:34

time:31

time:65

time:45

time:453 name: buttercup

stn:esd

stn:trs

stn:ssm

stn:btm

stn:lpad

Page 52: Gerry McNicol Graph Databases

Exeter

London

S'hampton

Bristol

Taunton

HORSE

TRAIN

TRAIN TRAIN

TRAIN

BUS

TRAIN

BUStime:35 time:120

busco:mega

time:37 busco:mega

time:34

time:31

time:65

time:45

time:453 name: buttercup

stn:esd

stn:trs

stn:ssm

stn:btm

stn:lpad

GerryLIKES

Page 53: Gerry McNicol Graph Databases

Exeter

London

S'hampton

Bristol

Taunton

HORSE

TRAI

TRAIN TRAINTRAIN

BUS

TRAIN

BUS

GerryLIKE

TomFRIENDS

Tennis MouseFormula 1

LIKE CHASEIS_LIKEDRIVE

Sport

IS_AIS_A

Page 54: Gerry McNicol Graph Databases

Use Cases

• Very powerful and flexible data model

• Semantically rich - very descriptive

• Densely-connected data sets

• Variably Structured data sets

Page 55: Gerry McNicol Graph Databases

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

Page 56: Gerry McNicol Graph Databases

Use Cases

• Communication networks

• Recommendation Engines

• Fraud rings

• Access Control

• Logistics Networks

• Medical Pathways

• Transport Network

• Data Center Networks

• Electricity Grids

• Time series

Page 57: Gerry McNicol Graph Databases

Graph databases• Neo4j

• FlockDB

• AllegroGraph

• InfiniteGraph

• HypergraphDB

Page 58: Gerry McNicol Graph Databases

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

Page 59: Gerry McNicol Graph Databases

Cypher: Creating Nodes and Relationships

Page 60: Gerry McNicol Graph Databases

name:Gerry

Cypher: Creating Nodes and Relationships

Page 61: Gerry McNicol Graph Databases

name:Gerry

CREATE ({name:’Gerry’});

Cypher: Creating Nodes and Relationships

Page 62: Gerry McNicol Graph Databases

name:Gerry

Cypher: Creating Nodes and Relationships

Page 63: Gerry McNicol Graph Databases

name:Gerry

CREATE (u:user {name:’Gerry’}) return u;

Cypher: Creating Nodes and Relationships

Page 64: Gerry McNicol Graph Databases

name:Gerry

CREATE (u:user {name:’Gerry’}) return u;

Node type label

Cypher: Creating Nodes and Relationships

Page 65: Gerry McNicol Graph Databases

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.

Cypher: Creating Nodes and Relationships

Page 66: Gerry McNicol Graph Databases

Cypher: Creating Nodes and Relationships

name:Gerry name:Tom

Page 67: Gerry McNicol Graph Databases

CREATE (u:user {name:’Gerry’}) WITH u

CREATE (t:user {name:’Tom’}) RETURN u,t;

Cypher: Creating Nodes and Relationships

name:Gerry name:Tom

Page 68: Gerry McNicol Graph Databases

Cypher: Creating Nodes and Relationships

name:Gerry name:Tom

Page 69: Gerry McNicol Graph Databases

Cypher: Creating Nodes and Relationships

name:Gerry name:TomFRIENDS_WITH

Page 70: Gerry McNicol Graph Databases

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;

Cypher: Creating Nodes and Relationships

name:Gerry name:TomFRIENDS_WITH

Page 71: Gerry McNicol Graph Databases

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;

Cypher: Creating Nodes and Relationships

name:Gerry name:TomFRIENDS_WITH

{since: 10/1/2013}

Page 72: Gerry McNicol Graph Databases

Cypher: Selecting Stuff

name:Gerry name:Tomname:Pete name:Barry

Page 73: Gerry McNicol Graph Databases

Cypher: Selecting Stuff

name:Gerry name:Tomname:Pete name:Barry

match (n:user) return n;

Page 74: Gerry McNicol Graph Databases

Cypher: Selecting Stuff

name:Gerry name:Tomname:Pete name:Barry

match (n:user) return n;

match (n:user{name:’Pete’}) return n;

name:Pete

Page 75: Gerry McNicol Graph Databases

Cypher: Selecting Stuff

name:Gerry

name:Tom

name:Pete

name:Barry

FRIENDS_WITH

FRIENDS_WITH

FRIENDS_WITH

FRIENDS_WITH

Page 76: Gerry McNicol Graph Databases

Cypher: Selecting Stuff

name:Gerry

name:Tom

name:Pete

name:Barry

FRIENDS_WITH

FRIENDS_WITH

FRIENDS_WITH

FRIENDS_WITH

MATCH (u:user {name:’Gerry'}) WITH u MATCH (u)-[FRIENDS_WITH*0..1]-(f)

RETURN f;

Page 77: Gerry McNicol Graph Databases

Cypher: Selecting Stuff

name:Gerry

name:Tom

name:Pete

name:Barry

FRIENDS_WITH

FRIENDS_WITH

FRIENDS_WITH

FRIENDS_WITH

Page 78: Gerry McNicol Graph Databases

Cypher: Selecting Stuff

name:Gerry

name:Tom

name:Pete

name:Barry

FRIENDS_WITH

FRIENDS_WITH

FRIENDS_WITH

FRIENDS_WITH

MATCH (u:user {name:’Gerry'}) WITH uMATCH (u)-[FRIENDS_WITH*0..2]-(f)

RETURN f;

name:AlanFRIENDS_WITH

Page 79: Gerry McNicol Graph Databases

Demo

Page 80: Gerry McNicol Graph Databases

www.neo4j.org

@gerrymcnicol

http://graphdatabases.com

http://gerrymcnicol.com

Ian Robinson