Top Banner
©2013 DataStax Confidential. Do not distribute without consent. @rustyrazorblade Jon Haddad Technical Evangelist, DataStax Graph Databases 101 1
32

Getting Started with Graph Databases

Apr 11, 2017

Download

Technology

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Getting Started with Graph Databases

©2013 DataStax Confidential. Do not distribute without consent.

@rustyrazorblade

Jon HaddadTechnical Evangelist, DataStax

Graph Databases 101

1

Page 2: Getting Started with Graph Databases

A Quick Look at Relational

View the Full-Length Video & Tutorialhttps://academy.datastax.com/demos/getting-started-graph-databases

Page 3: Getting Started with Graph Databases

Tables• Very structured data • Relational calculus • Various normal forms

id name title country

1 jon evangelist usa

2 patrick chief evangelist usa

3 rebecca jr evangelist canada

4 billy ceo usa

Page 4: Getting Started with Graph Databases

Selecting and Filtering

id name title country

1 jon evangelist usa

2 patrick chief evangelist usa

3 rebecca jr evangelist canada

4 billy ceo usa

select * from people where country = 'canada';

Page 5: Getting Started with Graph Databases

Foreign Keys

id name title country

1 jon evangelist 1

2 patrick chief evangelist 1

3 rebecca jr evangelist 2

4 billy ceo 1

id name

1 usa

2 canada

3 germany

4 japan

Page 6: Getting Started with Graph Databases

Joins

select * from people join country on people.country = country.id;

id name title country name

1 jon evangelist 1 usa

2 patrick chief evangelist 1 usa

3 rebecca jr evangelist 2 canada

4 billy ceo 1 usa

Page 7: Getting Started with Graph Databases

Many to Many Relationships

id name title

1 jon evangelist

2 patrick chief evangelist

3 rebecca jr evangelist

4 billy ceo

id name

1 usa

2 canada

3 germany

4 japan

user country

1 1

1 2

2 1

3 2

4 1

Page 8: Getting Started with Graph Databases

Joiningselect * from people join people_country on people.id = people_country.user join country on people_country.country = country.id;

id name title country name

1 jon evangelist 1 usa

1 jon evangelist 2 canada

2 patrick chief evangelist 1 usa

3 rebecca jr evangelist 2 canada

4 billy ceo 1 usa

Page 9: Getting Started with Graph Databases

A Fun, Real World Example

Page 10: Getting Started with Graph Databases

movieidnameyear

tv_show

id

name

personidnamedob

actor_moviepersonmovierole

actor_tvpersontv_showdob

episodetv_showseasonepisode

actor_episodeepisodeactor

Page 11: Getting Started with Graph Databases

Problems• Every entity gets a table • Lots of many to many tables • Very rigid structure • Going from one to many requires a

migration and new data model

Page 12: Getting Started with Graph Databases

How is this Solved with a Graph?

Page 13: Getting Started with Graph Databases

Vertex• A vertex represents a "thing" • For example: Movie, Person

JCVD Time cop

Page 14: Getting Started with Graph Databases

JCVD Time cop

Edge• Edges are labeled relationships • Edges have direction

ActedIn

Page 15: Getting Started with Graph Databases

Edges are always many to many

JCVD Time copActedIn

Bloodsport

ActedIn

Page 16: Getting Started with Graph Databases

Properties• Similar to fields in a table •Much more flexible •Meta properties - properties on

properties • Can be on an edge or a vertex • Special property - a label

JCVD

status amazing

charm infinite

odds of rendezvous 99.6%

enemies decapitated 108747

Page 17: Getting Started with Graph Databases

Tinkerpop 3• Cross database graph query

language • API for graph • Gremlin Server

Page 18: Getting Started with Graph Databases

Adding Data

1 graph = TitanFactory.build().set('storage.backend', 'inmemory').open() 2 3 g = graph.traversal() 4 5 jcvd = graph.addVertex(label, "actor", 6 "name", "jean claude van damme") 7 8 kick = graph.addVertex(label, "movie", "name", "Kickboxer", 9 "year", 1989) 10 11 blood = graph.addVertex(label, "movie", "name", "Bloodsport", 12 "year", 1988) 13 14 jcvd.addEdge("acted_in", kick) 15 jcvd.addEdge("acted_in", blood)

Page 19: Getting Started with Graph Databases

Summary

•We don't define tables •We create vertices to represent real

world objects • Relationships don't need to be

explicitly modeled • Expressing complex relationships is

not hard • Adding new edge types is easy

Page 20: Getting Started with Graph Databases

Traversing the Graph

Page 21: Getting Started with Graph Databases

Finding Vertices

single vertex g.V(4160)

matching a property

g.V().has("name", "jean claude van damme")

range filteringg.V().has("year", between(1980, 1990))

Page 22: Getting Started with Graph Databases

Traversals

Bloodsport (1988)

Kickboxer (1989)

Timecop (1994)jcvd.out()

Page 23: Getting Started with Graph Databases

Traversals

Bloodsport (1988)

Kickboxer (1989)

Timecop (1994)jcvd.outE()

Page 24: Getting Started with Graph Databases

Traversals

to other vertices g.V().has("name", "jean claude van damme").out()

to edges g.V().has("name", "jean claude van damme").outE()

filtering with traversals

g.V().has("name", "jean claude van damme").out(). has("year", between(1980, 1990))

Page 25: Getting Started with Graph Databases
Page 26: Getting Started with Graph Databases

Use Cases

Page 27: Getting Started with Graph Databases

Recommendation Engines•What do I like? •What do others like? •What do others listen to? • Find correlations

Page 28: Getting Started with Graph Databases

Fraud & Anomaly Detection

Page 29: Getting Started with Graph Databases

Complex Taxonomies

Page 30: Getting Started with Graph Databases

Titan• Open Source •Works with Cassandra to scale to massive

graphs • OLTP + OLAP graph queries via Spark •Works with Solr or Elastic Search

Page 31: Getting Started with Graph Databases

DSE Graph•Next generation of distributed graph • Benefits of Titan but tightly integrated

with DataStax Enterprise

Page 32: Getting Started with Graph Databases

©2013 DataStax Confidential. Do not distribute without consent. 32