39
Graphs, Databases and what we can use them for Michael Hackstein @mchacki November 6, 2013 c 2013 triAGENS GmbH | 2013-11-6

GraphDatabases and what we can use them for

Embed Size (px)

DESCRIPTION

In this talk the general idea of graph databases is presented and the execution of a graph traversal is shown. The talk has been given at NoSQL UG Cologne (in Nov. 2013)

Citation preview

Page 1: GraphDatabases and what we can use them for

Graphs, Databases and what we can use them for

Michael Hackstein@mchacki

November 6, 2013

c©2013 triAGENS GmbH | 2013-11-6

Page 2: GraphDatabases and what we can use them for

About me

Still Student (Master Informatik) at RWTH

Just handed in my thesis

Software developer at triAGENS GmbH, CGN

Part of the ArangoDB team

c©2013 triAGENS GmbH | 2013-11-6

Page 3: GraphDatabases and what we can use them for

Table of contents

1 Definition

2 Use Cases

3 Databases

4 Traversals

5 Visualisation

c©2013 triAGENS GmbH | 2013-11-6

Page 4: GraphDatabases and what we can use them for

What is a graph?

A set of arbitrary objects, called vertices

And a set of relations between them, called edges

c©2013 triAGENS GmbH | 2013-11-6

Page 5: GraphDatabases and what we can use them for

What is a graph?

A set of arbitrary objects, called verticesAnd a set of relations between them, called edges

c©2013 triAGENS GmbH | 2013-11-6

Page 6: GraphDatabases and what we can use them for

Formal Definition

Let V be the set of vertices

Let E ⊆ V × V be the set of edges

Define G = (V ,E ) is a graph

c©2013 triAGENS GmbH | 2013-11-6

Page 7: GraphDatabases and what we can use them for

Formal Definition

Let V be the set of vertices

Let E ⊆ V × V be the set of edges

Define G = (V ,E ) is a graph

Define δ+(n) =∑

v∈V |(n,v)∈E 1 is the indegree of n ∈ V

Define δ−(n) =∑

v∈V |(v ,n)∈E 1 is the outdegree of n ∈ V

Define δ(n) = δ+(n) + δ−(n) as the degree of n ∈ V

c©2013 triAGENS GmbH | 2013-11-6

Page 8: GraphDatabases and what we can use them for

Directed Graphs

Edges have a directionOne vertex is the sourceThe other vertex is the targetFormal: (a, b) ∈ E ; (b, a) ∈ EAnd (a, b) ∈ E ∧ (b, a) ∈ E ⇒ (a, b) 6= (b, a)

a

b

c

d

c©2013 triAGENS GmbH | 2013-11-6

Page 9: GraphDatabases and what we can use them for

Example: Navigation Systems

c©2013 triAGENS GmbH | 2013-11-6

Page 10: GraphDatabases and what we can use them for

Undirected Graphs

Edges do not have a directionNo vertex is source or targetFormal: (a, b) ∈ E ⇔ (b, a) ∈ EAnd (a, b) ∈ E ∧ (b, a) ∈ E ⇒ (a, b) = (b, a)

a

b

c

d

c©2013 triAGENS GmbH | 2013-11-6

Page 11: GraphDatabases and what we can use them for

Example: Social Networks

Alice

Bob

Charly

Diana

c©2013 triAGENS GmbH | 2013-11-6

Page 12: GraphDatabases and what we can use them for

Property Graphs

Vertices have properties in addition to a labelEdges have properties in addition to a label

c©2013 triAGENS GmbH | 2013-11-6

Page 13: GraphDatabases and what we can use them for

Graphs in Relational Databases

Vertex Edge

m

n

c©2013 triAGENS GmbH | 2013-11-6

Page 14: GraphDatabases and what we can use them for

Where else to store Graphs?

c©2013 triAGENS GmbH | 2013-11-6

Page 15: GraphDatabases and what we can use them for

How to store Graphs?

We will have an example using ArangoDB.

First Example: Create new database using Graphs API

DEMO TIME

c©2013 triAGENS GmbH | 2013-11-6

Page 16: GraphDatabases and what we can use them for

How to store Graphs?

Second Example: You already have vertices.

How to add edges?

DEMO TIME

c©2013 triAGENS GmbH | 2013-11-6

Page 17: GraphDatabases and what we can use them for

But what can we do with the data now?

c©2013 triAGENS GmbH | 2013-11-6

Page 18: GraphDatabases and what we can use them for

Queries on graphs

Mechanism to query a graph

Starts at one specific vertex

Searches all connected vertices

Searches children of these vertices

Until predefined boundary is reached

Order of vertices can be configured

c©2013 triAGENS GmbH | 2013-11-6

Page 19: GraphDatabases and what we can use them for

The visitor

Active at each searched vertex

Can execute queries on this vertex like collecting attributes

Does know the path followed to reach the current vertex

Does not know vertices that will be visited in future

c©2013 triAGENS GmbH | 2013-11-6

Page 20: GraphDatabases and what we can use them for

Traversals

Grain: 0Nuts: 0

Grain: 2Nuts: 3

Grain: 1Nuts: 1

Grain: 0Nuts: 2

Grain: 2Nuts: 0

Grain: 5Nuts: 5

Grain: 2Nuts: 1

Grain: 1Nuts: 1

Grain: 8Nuts: 9

c©2013 triAGENS GmbH | 2013-11-6

Page 21: GraphDatabases and what we can use them for

Traversals

Grain: 0Nuts: 0

Grain: 2Nuts: 3

Grain: 1Nuts: 1

Grain: 0Nuts: 2

Grain: 2Nuts: 0

Grain: 5Nuts: 5

Grain: 2Nuts: 1

Grain: 1Nuts: 1

Grain: 8Nuts: 9

Grain: 0 Nuts: 0

c©2013 triAGENS GmbH | 2013-11-6

Page 22: GraphDatabases and what we can use them for

Traversals

Grain: 0Nuts: 0

Grain: 2Nuts: 3

Grain: 1Nuts: 1

Grain: 0Nuts: 2

Grain: 2Nuts: 0

Grain: 5Nuts: 5

Grain: 2Nuts: 1

Grain: 1Nuts: 1

Grain: 8Nuts: 9

Grain: 0 Nuts: 0

c©2013 triAGENS GmbH | 2013-11-6

Page 23: GraphDatabases and what we can use them for

Traversals

Grain: 0Nuts: 0

Grain: 2Nuts: 3

Grain: 1Nuts: 1

Grain: 0Nuts: 2

Grain: 2Nuts: 0

Grain: 5Nuts: 5

Grain: 2Nuts: 1

Grain: 1Nuts: 1

Grain: 8Nuts: 9

Grain: 0 Nuts: 0

c©2013 triAGENS GmbH | 2013-11-6

Page 24: GraphDatabases and what we can use them for

Traversals

Grain: 0Nuts: 0

Grain: 2Nuts: 3

Grain: 1Nuts: 1

Grain: 0Nuts: 2

Grain: 2Nuts: 0

Grain: 5Nuts: 5

Grain: 2Nuts: 1

Grain: 1Nuts: 1

Grain: 8Nuts: 9

Grain: 2 Nuts: 3

c©2013 triAGENS GmbH | 2013-11-6

Page 25: GraphDatabases and what we can use them for

Traversals

Grain: 0Nuts: 0

Grain: 2Nuts: 3

Grain: 1Nuts: 1

Grain: 0Nuts: 2

Grain: 2Nuts: 0

Grain: 5Nuts: 5

Grain: 2Nuts: 1

Grain: 1Nuts: 1

Grain: 8Nuts: 9

Grain: 2 Nuts: 3

c©2013 triAGENS GmbH | 2013-11-6

Page 26: GraphDatabases and what we can use them for

Traversals

Grain: 0Nuts: 0

Grain: 2Nuts: 3

Grain: 1Nuts: 1

Grain: 0Nuts: 2

Grain: 2Nuts: 0

Grain: 5Nuts: 5

Grain: 2Nuts: 1

Grain: 1Nuts: 1

Grain: 8Nuts: 9

Grain: 2 Nuts: 3

c©2013 triAGENS GmbH | 2013-11-6

Page 27: GraphDatabases and what we can use them for

Traversals

Grain: 0Nuts: 0

Grain: 2Nuts: 3

Grain: 1Nuts: 1

Grain: 0Nuts: 2

Grain: 2Nuts: 0

Grain: 5Nuts: 5

Grain: 2Nuts: 1

Grain: 1Nuts: 1

Grain: 8Nuts: 9

Grain: 4 Nuts: 3

c©2013 triAGENS GmbH | 2013-11-6

Page 28: GraphDatabases and what we can use them for

Traversals

Grain: 0Nuts: 0

Grain: 2Nuts: 3

Grain: 1Nuts: 1

Grain: 0Nuts: 2

Grain: 2Nuts: 0

Grain: 5Nuts: 5

Grain: 2Nuts: 1

Grain: 1Nuts: 1

Grain: 8Nuts: 9

Grain: 4 Nuts: 3

c©2013 triAGENS GmbH | 2013-11-6

Page 29: GraphDatabases and what we can use them for

Traversals

Grain: 0Nuts: 0

Grain: 2Nuts: 3

Grain: 1Nuts: 1

Grain: 0Nuts: 2

Grain: 2Nuts: 0

Grain: 5Nuts: 5

Grain: 2Nuts: 1

Grain: 1Nuts: 1

Grain: 8Nuts: 9

Grain: 4 Nuts: 3

c©2013 triAGENS GmbH | 2013-11-6

Page 30: GraphDatabases and what we can use them for

Traversals

Grain: 0Nuts: 0

Grain: 2Nuts: 3

Grain: 1Nuts: 1

Grain: 0Nuts: 2

Grain: 2Nuts: 0

Grain: 5Nuts: 5

Grain: 2Nuts: 1

Grain: 1Nuts: 1

Grain: 8Nuts: 9

Grain: 9 Nuts: 8

c©2013 triAGENS GmbH | 2013-11-6

Page 31: GraphDatabases and what we can use them for

Traversals

Grain: 0Nuts: 0

Grain: 2Nuts: 3

Grain: 1Nuts: 1

Grain: 0Nuts: 2

Grain: 2Nuts: 0

Grain: 5Nuts: 5

Grain: 2Nuts: 1

Grain: 1Nuts: 1

Grain: 8Nuts: 9

Grain: 9 Nuts: 8

c©2013 triAGENS GmbH | 2013-11-6

Page 32: GraphDatabases and what we can use them for

Traversals

Grain: 0Nuts: 0

Grain: 2Nuts: 3

Grain: 1Nuts: 1

Grain: 0Nuts: 2

Grain: 2Nuts: 0

Grain: 5Nuts: 5

Grain: 2Nuts: 1

Grain: 1Nuts: 1

Grain: 8Nuts: 9

Grain: 9 Nuts: 8

c©2013 triAGENS GmbH | 2013-11-6

Page 33: GraphDatabases and what we can use them for

Traversals

Grain: 0Nuts: 0

Grain: 2Nuts: 3

Grain: 1Nuts: 1

Grain: 0Nuts: 2

Grain: 2Nuts: 0

Grain: 5Nuts: 5

Grain: 2Nuts: 1

Grain: 1Nuts: 1

Grain: 8Nuts: 9

Grain: 10 Nuts: 9

c©2013 triAGENS GmbH | 2013-11-6

Page 34: GraphDatabases and what we can use them for

Traversals

Grain: 0Nuts: 0

Grain: 2Nuts: 3

Grain: 1Nuts: 1

Grain: 0Nuts: 2

Grain: 2Nuts: 0

Grain: 5Nuts: 5

Grain: 2Nuts: 1

Grain: 1Nuts: 1

Grain: 8Nuts: 9

Grain: 12 Nuts: 10

c©2013 triAGENS GmbH | 2013-11-6

Page 35: GraphDatabases and what we can use them for

Traversals

Grain: 0Nuts: 0

Grain: 2Nuts: 3

Grain: 1Nuts: 1

Grain: 0Nuts: 2

Grain: 2Nuts: 0

Grain: 5Nuts: 5

Grain: 2Nuts: 1

Grain: 1Nuts: 1

Grain: 8Nuts: 9

Grain: 12 Nuts: 12

c©2013 triAGENS GmbH | 2013-11-6

Page 36: GraphDatabases and what we can use them for

Traversals

Grain: 0Nuts: 0

Grain: 2Nuts: 3

Grain: 1Nuts: 1

Grain: 0Nuts: 2

Grain: 2Nuts: 0

Grain: 5Nuts: 5

Grain: 2Nuts: 1

Grain: 1Nuts: 1

Grain: 8Nuts: 9

Grain: 13 Nuts: 13

c©2013 triAGENS GmbH | 2013-11-6

Page 37: GraphDatabases and what we can use them for

Traversals

Grain: 0Nuts: 0

Grain: 2Nuts: 3

Grain: 1Nuts: 1

Grain: 0Nuts: 2

Grain: 2Nuts: 0

Grain: 5Nuts: 5

Grain: 2Nuts: 1

Grain: 1Nuts: 1

Grain: 8Nuts: 9

Grain: 13 Nuts: 13 Done

c©2013 triAGENS GmbH | 2013-11-6

Page 38: GraphDatabases and what we can use them for

Traversals Live

Example: Execute traversal in ArangoDB

DEMO TIME

c©2013 triAGENS GmbH | 2013-11-6

Page 39: GraphDatabases and what we can use them for

Visualisation

Example: How to view the graph

DEMO TIME

c©2013 triAGENS GmbH | 2013-11-6