gerry mcnicol graph databases

Post on 15-Jan-2015

136 Views

Category:

Technology

3 Downloads

Preview:

Click to see full reader

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

Graph Databases

@gerrymcnicol

What is a Graph Database?

Relational - RDBMSMySQL

MS SQL Server

Oracle

IBM DB2

Terra Data

Relational - RDBMS

Relational - RDBMSAtomicConsistentIsolatedDurable

SQL Language

IndexesStored Procedures

Functions

Multi-Dimensional Modelling (cubes)

Triggers

Referential Integrity

Neo4j

Data Model

Data ModelThing

Data ModelThing Relational

Data ModelThing Relational Graph

Data ModelThing Relational Graph

Database Server

Data ModelThing Relational Graph

Database Server Yes

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Table

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Table Yes

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Table Yes No

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Table Yes No

Row

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Table Yes No

Row Yes

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Table Yes No

Row Yes No

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Table Yes No

Row Yes No

Cell?

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Table Yes No

Row Yes No

Cell? Yes

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Table Yes No

Row Yes No

Cell? Yes No

Data ModelThing Relational Graph

Database Server Yes Yes (and possibly no)

Catalogue Yes No

Table Yes No

Row Yes No

Cell? Yes No

Relationship

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

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

What is a Graph?

What is a Graph?

Gerry

What is a Graph?

Gerry Tom

What is a Graph?

Gerry Tom

What is a Graph?

Gerry TomFRIENDS_WITH

What is a Graph?

Gerry TomFRIENDS_WITH

Tennis MouseFormula 1

What is a Graph?

Gerry TomFRIENDS_WITH

Tennis MouseFormula 1

IS_A

What is a Graph?

Gerry TomFRIENDS_WITH

Tennis MouseFormula 1

CHASESIS_A

What is a Graph?

Gerry TomFRIENDS_WITH

Tennis MouseFormula 1

LIKES CHASESIS_A

What is a Graph?

Gerry TomFRIENDS_WITH

Tennis MouseFormula 1

LIKES CHASESIS_ALIKES

What is a Graph?

Gerry TomFRIENDS_WITH

Tennis MouseFormula 1

LIKES CHASESIS_ALIKESDRIVES_IN

Gerry TomFRIENDS_WITH

Tennis MouseFormula 1

LIKES CHASESIS_ALIKESDRIVES_IN

Gerry TomFRIENDS_WITH

Tennis MouseFormula 1

LIKES CHASESIS_ALIKESDRIVES_IN

IS_A

Gerry TomFRIENDS_WITH

Tennis MouseFormula 1

LIKES CHASESIS_ALIKESDRIVES_IN

Sport

IS_A

Gerry TomFRIENDS_WITH

Tennis MouseFormula 1

LIKES CHASESIS_ALIKESDRIVES_IN

Sport

IS_AIS_A

Exeter

London

S'hampton

Bristol

Taunton

Exeter

London

S'hampton

Bristol

Taunton

HORSE

TRAIN

TRAIN TRAIN

TRAINBUS

TRAIN

BUS

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

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

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

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

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

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

Use Cases

• Very powerful and flexible data model

• Semantically rich - very descriptive

• Densely-connected data sets

• Variably Structured data sets

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

Use Cases

• Communication networks

• Recommendation Engines

• Fraud rings

• Access Control

• Logistics Networks

• Medical Pathways

• Transport Network

• Data Center Networks

• Electricity Grids

• Time series

Graph databases• Neo4j

• FlockDB

• AllegroGraph

• InfiniteGraph

• HypergraphDB

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

Cypher: Creating Nodes and Relationships

name:Gerry

Cypher: Creating Nodes and Relationships

name:Gerry

CREATE ({name:’Gerry’});

Cypher: Creating Nodes and Relationships

name:Gerry

Cypher: Creating Nodes and Relationships

name:Gerry

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

Cypher: Creating Nodes and Relationships

name:Gerry

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

Node type label

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.

Cypher: Creating Nodes and Relationships

Cypher: Creating Nodes and Relationships

name:Gerry name:Tom

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

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

Cypher: Creating Nodes and Relationships

name:Gerry name:Tom

Cypher: Creating Nodes and Relationships

name:Gerry name:Tom

Cypher: Creating Nodes and Relationships

name:Gerry name:TomFRIENDS_WITH

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

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}

Cypher: Selecting Stuff

name:Gerry name:Tomname:Pete name:Barry

Cypher: Selecting Stuff

name:Gerry name:Tomname:Pete name:Barry

match (n:user) return n;

Cypher: Selecting Stuff

name:Gerry name:Tomname:Pete name:Barry

match (n:user) return n;

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

name:Pete

Cypher: Selecting Stuff

name:Gerry

name:Tom

name:Pete

name:Barry

FRIENDS_WITH

FRIENDS_WITH

FRIENDS_WITH

FRIENDS_WITH

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;

Cypher: Selecting Stuff

name:Gerry

name:Tom

name:Pete

name:Barry

FRIENDS_WITH

FRIENDS_WITH

FRIENDS_WITH

FRIENDS_WITH

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

Demo

www.neo4j.org

@gerrymcnicol

http://graphdatabases.com

http://gerrymcnicol.com

Ian Robinson

top related