GraphConnect 2014 SF: From Zero to Graph in 120: Model
-
Upload
neo4j-the-open-source-graph-database -
Category
Software
-
view
678 -
download
0
description
Transcript of GraphConnect 2014 SF: From Zero to Graph in 120: Model
SAN FRANCISCO | 10.22.2014
powered by
Zero����������� ������������������ to����������� ������������������ Graph����������� ������������������ in����������� ������������������ 120Data Modeling
!presented by @kennybastani
1
SAN FRANCISCO | 10.22.2014
powered by
Agenda
• Introduction����������� ������������������ to����������� ������������������ graphs����������� ������������������
• Introduction����������� ������������������ to����������� ������������������ the����������� ������������������ labeled����������� ������������������ property����������� ������������������ graph����������� ������������������ data����������� ������������������ model����������� ������������������
• Cypher����������� ������������������ Query����������� ������������������ Language����������� ������������������
• Introduction����������� ������������������ to����������� ������������������ graph-based����������� ������������������ modeling����������� ������������������
• Graph����������� ������������������ data����������� ������������������ modeling����������� ������������������ guidelines����������� ������������������
• Intermediate����������� ������������������ nodes
2
SAN FRANCISCO | 10.22.2014
powered by
Introduction����������� ������������������ to����������� ������������������ graphs
SAN FRANCISCO | 10.22.2014
powered by
What����������� ������������������ is����������� ������������������ a����������� ������������������ graph?
SAN FRANCISCO | 10.22.2014
powered by
5
John
Sally
Graph Databases Book
Friend Of
Friend Of
Has Rea
d
Has Read
SAN FRANCISCO | 10.22.2014
powered by
6
name: John age: 27
name: Sally age: 32
title: Graph Databases authors: Ian Robinson, Jim Webber
FRIEND_OF since: 01/09/2013
HAS_READ on: 2/03/2013 rating: 5
HAS_READ on: 02/09/2013 rating: 4
FRIEND_OF since: 01/09/2013
SAN FRANCISCO | 10.22.2014
powered by
The����������� ������������������ Relational����������� ������������������ Table����������� ������������������ Model
SAN FRANCISCO | 10.22.2014
powered by
8
Customers AccountsCustomer_Accounts
143 Alice 326 $100
725 $632
981 $212
143 981
143 725
143 326
SAN FRANCISCO | 10.22.2014
powered by
Introduction����������� ������������������ to����������� ������������������ the����������� ������������������ labeled����������� ������������������ property����������� ������������������ graph����������� ������������������ data����������� ������������������ model
SAN FRANCISCO | 10.22.2014
powered by
Four����������� ������������������ Building����������� ������������������ Blocks
•Nodes����������� ������������������
•Relationships����������� ������������������
•Properties����������� ������������������
•Labels
10
SAN FRANCISCO | 10.22.2014
powered by
11
Nodes
SAN FRANCISCO | 10.22.2014
powered by
Nodes
•Nodes����������� ������������������ are����������� ������������������ used����������� ������������������ to����������� ������������������ represent����������� ������������������ entities����������� ������������������ and����������� ������������������ complex����������� ������������������ value����������� ������������������ types����������� ������������������ in����������� ������������������ your����������� ������������������ domain����������� ������������������
•Nodes����������� ������������������ contain����������� ������������������ properties����������� ������������������
•Key-value����������� ������������������ pairs����������� ������������������
•Java����������� ������������������ primitives����������� ������������������
•Arrays����������� ������������������
•null����������� ������������������ is����������� ������������������ not����������� ������������������ a����������� ������������������ valid����������� ������������������ value����������� ������������������
•Every����������� ������������������ node����������� ������������������ can����������� ������������������ have����������� ������������������ different����������� ������������������ properties����������� ������������������
•Nodes����������� ������������������ do����������� ������������������ not����������� ������������������ have����������� ������������������ to����������� ������������������ have����������� ������������������ the����������� ������������������ same����������� ������������������ keys
12
SAN FRANCISCO | 10.22.2014
powered by
13
Relationships
SAN FRANCISCO | 10.22.2014
powered by
14
Relationships����������� ������������������ (continued)
Nodes can have more than one relationship
Self relationships are allowed
Nodes can be connected by more than one relationship
SAN FRANCISCO | 10.22.2014
powered by
Relationships
•Every����������� ������������������ relationship����������� ������������������ has����������� ������������������ a����������� ������������������ name����������� ������������������ and����������� ������������������ a����������� ������������������ direction����������� ������������������
•Add����������� ������������������ structure����������� ������������������ to����������� ������������������ the����������� ������������������ graph����������� ������������������
•Provide����������� ������������������ semantic����������� ������������������ context����������� ������������������ for����������� ������������������ nodes����������� ������������������
•Can����������� ������������������ contain����������� ������������������ properties����������� ������������������
•Used����������� ������������������ to����������� ������������������ represent����������� ������������������ quality����������� ������������������ or����������� ������������������ weight����������� ������������������ of����������� ������������������ relationship,����������� ������������������ or����������� ������������������ metadata����������� ������������������
•Every����������� ������������������ relationship����������� ������������������ must����������� ������������������ have����������� ������������������ a����������� ������������������ start����������� ������������������ node����������� ������������������ and����������� ������������������ end����������� ������������������ node����������� ������������������
•No����������� ������������������ dangling����������� ������������������ relationships
15
SAN FRANCISCO | 10.22.2014
powered by
16
Labels
SAN FRANCISCO | 10.22.2014
powered by
Labels
•Every����������� ������������������ node����������� ������������������ can����������� ������������������ have����������� ������������������ zero����������� ������������������ or����������� ������������������ more����������� ������������������ labels����������� ������������������
•Used����������� ������������������ to����������� ������������������ represent����������� ������������������ roles����������� ������������������ (e.g.����������� ������������������ user,����������� ������������������ product,����������� ������������������ company)����������� ������������������
•Group����������� ������������������ nodes����������� ������������������
•Allow����������� ������������������ us����������� ������������������ to����������� ������������������ associate����������� ������������������ indexes����������� ������������������ and����������� ������������������ constraints����������� ������������������ with����������� ������������������ groups����������� ������������������ of����������� ������������������ nodes
17
SAN FRANCISCO | 10.22.2014
powered by
Four����������� ������������������ Building����������� ������������������ Blocks
•Nodes����������� ������������������
•Entities����������� ������������������
•Relationships����������� ������������������
•Connect����������� ������������������ entities����������� ������������������ and����������� ������������������ structure����������� ������������������ domain����������� ������������������
•Properties����������� ������������������
•Entity����������� ������������������ attributes,����������� ������������������ relationship����������� ������������������ qualities,����������� ������������������ and����������� ������������������ metadata����������� ������������������
•Labels����������� ������������������
•Group����������� ������������������ nodes����������� ������������������ by����������� ������������������ role
18
SAN FRANCISCO | 10.22.2014
powered by
Cypher����������� ������������������ Query����������� ������������������ Language
SAN FRANCISCO | 10.22.2014
powered by
Cypher����������� ������������������ is����������� ������������������ Neo4j's����������� ������������������ graph����������� ������������������ query����������� ������������������ language
•Declarative����������� ������������������ Pattern-Matching����������� ������������������ language����������� ������������������
•SQL-like����������� ������������������ syntax����������� ������������������
•Designed����������� ������������������ for����������� ������������������ graphs
20
SAN FRANCISCO | 10.22.2014
powered by
21
It’s����������� ������������������ all����������� ������������������ about����������� ������������������ Patterns
A
B C
SAN FRANCISCO | 10.22.2014
powered by
22
SAN FRANCISCO | 10.22.2014
powered by
23
SAN FRANCISCO | 10.22.2014
powered by
Introduction����������� ������������������ to����������� ������������������ Graph����������� ������������������ Modeling
SAN FRANCISCO | 10.22.2014
powered by
Start����������� ������������������ with����������� ������������������ a����������� ������������������ whiteboard
SAN FRANCISCO | 10.22.2014
powered by
26
SAN FRANCISCO | 10.22.2014
powered by
Adam
LOL Cat
FRIEND_OFSHARED
COMMENTED
SarahFUNNY
ON
LIKES
SAN FRANCISCO | 10.22.2014
powered by
Adam
LOL Cat
FRIEND_OFSHARED
COMMENTED
SarahFUNNY
ON
LIKES
SAN FRANCISCO | 10.22.2014
powered by
SAN FRANCISCO | 10.22.2014
powered by
Tom Hanks Hugo Weaving
Cloud AtlasThe Matrix
Lana Wachowski
ACTED_IN
ACTED_INACTED_IN
DIRECTED
DIRECTED
SAN FRANCISCO | 10.22.2014
powered by
Model����������� ������������������ Incrementally
SAN FRANCISCO | 10.22.2014
powered by
Tom Hanks Hugo Weaving
Cloud AtlasThe Matrix
Lana Wachowski
ACTED_IN
ACTED_INACTED_IN
DIRECTED
DIRECTED
SAN FRANCISCO | 10.22.2014
powered by
name: Tom Hanks nationality: USA won: Oscar, Emmy
name: Hugo Weaving nationality: Australia won: MTV Movie Award
title: Cloud Atlas genre: drama, sci-fi
title: The Matrix genre: sci-fi
name: Lana Wachowski nationality: USA won: Razzie, Hugo
ACTED_IN role: Zachry
ACTED_IN role: Bill Smoke
DIRECTED
DIRECTED
ACTED_IN role: Agent Smith
SAN FRANCISCO | 10.22.2014
powered by
Data����������� ������������������ Modeling����������� ������������������ Guidelines
SAN FRANCISCO | 10.22.2014
powered by
35
Symmetric����������� ������������������ Relationships
OR
SAN FRANCISCO | 10.22.2014
powered by
Infer����������� ������������������ Symmetric����������� ������������������ Relationship
Find child: MATCH (parent{name:'Sarah'}) -[:PARENT_OF]->(child) RETURN child
Find parent: MATCH (parent)-[:PARENT_OF]-> (child{name:'Eric'}) RETURN parent
36
SAN FRANCISCO | 10.22.2014
powered by
37
Bi-Directional����������� ������������������ Relationships
SAN FRANCISCO | 10.22.2014
powered by
Use����������� ������������������ Single����������� ������������������ Relationship����������� ������������������ and����������� ������������������ Ignore����������� ������������������ Relationship����������� ������������������ Direction����������� ������������������ in����������� ������������������ Queries
MATCH (p1{name:'Eric'}) -[:KNOWS]-(p2)RETURN p2
38
SAN FRANCISCO | 10.22.2014
powered by
39
Qualified����������� ������������������ Bi-Directional����������� ������������������ Relationships
OR
SAN FRANCISCO | 10.22.2014
powered by
40
The����������� ������������������ Skill����������� ������������������ Graph
SAN FRANCISCO | 10.22.2014
powered by
Use����������� ������������������ Relationships����������� ������������������ When
•Use����������� ������������������ Relationships:����������� ������������������
•You����������� ������������������ need����������� ������������������ to����������� ������������������ specify����������� ������������������ the����������� ������������������ weight,����������� ������������������ strength,����������� ������������������ or����������� ������������������ some����������� ������������������ other����������� ������������������ quality����������� ������������������ of����������� ������������������ the����������� ������������������ relationship����������� ������������������ and����������� ������������������ the����������� ������������������ nodes����������� ������������������ it����������� ������������������ connects����������� ������������������
•The����������� ������������������ property����������� ������������������ value����������� ������������������ comprises����������� ������������������ a����������� ������������������ complex����������� ������������������ value����������� ������������������ type����������� ������������������ (e.g.����������� ������������������ address)����������� ������������������
•Examples:����������� ������������������
•Find����������� ������������������ all����������� ������������������ my����������� ������������������ colleagues����������� ������������������ who����������� ������������������ are����������� ������������������ level����������� ������������������ 2����������� ������������������ or����������� ������������������ above����������� ������������������ in����������� ������������������ a����������� ������������������ skill����������� ������������������ (property����������� ������������������ value)����������� ������������������ we����������� ������������������ have����������� ������������������ in����������� ������������������ common����������� ������������������
•Find����������� ������������������ all����������� ������������������ recent����������� ������������������ orders����������� ������������������ delivered����������� ������������������ to����������� ������������������ the����������� ������������������ same����������� ������������������ delivery����������� ������������������ address����������� ������������������ (complex����������� ������������������ value����������� ������������������ type)
41
SAN FRANCISCO | 10.22.2014
powered by
42
HAS_SKILL����������� ������������������ describes����������� ������������������ a����������� ������������������ quality
SAN FRANCISCO | 10.22.2014
powered by
Use����������� ������������������ Properties
•Use����������� ������������������ a����������� ������������������ property����������� ������������������ on����������� ������������������ a����������� ������������������ node����������� ������������������ when:����������� ������������������
•There’s����������� ������������������ no����������� ������������������ need����������� ������������������ to����������� ������������������ qualify/weight����������� ������������������ the����������� ������������������ relationship����������� ������������������
•The����������� ������������������ property����������� ������������������ value����������� ������������������ comprises����������� ������������������ a����������� ������������������ simple����������� ������������������ value����������� ������������������ type����������� ������������������ (e.g.����������� ������������������ color)����������� ������������������
•Examples:����������� ������������������
•Find����������� ������������������ those����������� ������������������ projects����������� ������������������ written����������� ������������������ by����������� ������������������ contributors����������� ������������������ to����������� ������������������ my����������� ������������������ projects����������� ������������������ that����������� ������������������ use����������� ������������������ the����������� ������������������ same����������� ������������������ language����������� ������������������ as����������� ������������������ my����������� ������������������ projects
43
SAN FRANCISCO | 10.22.2014
powered by
44
Version����������� ������������������ Control����������� ������������������ -����������� ������������������ GitHub����������� ������������������ Projects
SAN FRANCISCO | 10.22.2014
powered by
45
Granularity
SAN FRANCISCO | 10.22.2014
powered by
General����������� ������������������ Relationships
46
SAN FRANCISCO | 10.22.2014
powered by
47
Specific����������� ������������������ Relationships
SAN FRANCISCO | 10.22.2014
powered by
General����������� ������������������ &����������� ������������������ Specific
48
SAN FRANCISCO | 10.22.2014
powered by
Intermediate����������� ������������������ Nodes
SAN FRANCISCO | 10.22.2014
powered by
Intermediate����������� ������������������ Nodes
•Connect����������� ������������������ more����������� ������������������ than����������� ������������������ 2����������� ������������������ nodes����������� ������������������ in����������� ������������������ a����������� ������������������ single����������� ������������������ context����������� ������������������
•Hyperedges����������� ������������������ (n-ary����������� ������������������ relationships)����������� ������������������
•Relate����������� ������������������ something����������� ������������������ to����������� ������������������ a����������� ������������������ relationship
50
SAN FRANCISCO | 10.22.2014
powered by
Intermediate����������� ������������������ Node����������� ������������������ Example
51
SAN FRANCISCO | 10.22.2014
powered by
Rich����������� ������������������ Context,����������� ������������������ Multiple����������� ������������������ Dimensions
52
SAN FRANCISCO | 10.22.2014
powered by
Intermediate����������� ������������������ Nodes����������� ������������������ Between����������� ������������������ Contexts
53
SAN FRANCISCO | 10.22.2014
powered by
Multiple����������� ������������������ Parties
54
SAN FRANCISCO | 10.22.2014
powered by
Thank����������� ������������������ You
SAN FRANCISCO | 10.22.2014
powered by
Follow����������� ������������������ !
@kennybastani����������� ������������������ ����������� ������������������ !
on����������� ������������������ Twitter