relationship counselling with neo4j
TRANSCRIPT
4
SuperFace
MEMBER_OF
TOO
K_PA
RT_INW
AS_I
N
Characters
Events
Teams
Stories
CONSISTS_OF
FR
IEN
D_O
F
5
Queries with lots of joins to get to the final answer
Similar data models
Configuration
Security
Navigation
8
Graph databases
MEM
BER
_OF
MEM
BER
_OF
FRIEND_OF
WA
S_I
N
TOOK_PART_IN
• Since: 14 Feb 2001
• Eyes: Blue
• Hair: None
• Citizenship: Canada
10
Impedance mismatch
Character_Team
Character_Event
Team_Event
Character_Story
Team_Story
Event_Story
FriendsMarvelCharacter
Team
Event
Story
12
Impedance mismatch
MEMBER_OF
TOO
K_PA
RT_IN
WA
S_I
N
Characters
Events
Teams
Stories
CONSISTS_OF
FR
IEN
D_O
F
26
Friends of friends
Possible friend recommendations for Deadpool
Name Number friends in
common
Vision 51
Wolfsbane 38
Punisher 33
Rage 38
Shard 25
Wind Dancer 25
27
Sooo many joins
SELECT FriendOfFriend.Name, COUNT(*)
FROM MarvelCharacter deadpool
INNER JOIN Friends DeadpoolFriends
ON deadpool.Id = DeadpoolFriends.CharacterId1
INNER JOIN Friends FriendsFriends
ON DeadpoolFriends.CharacterId2 = FriendsFriends.CharacterId1
INNER JOIN MarvelCharacter FriendOfFriend
ON FriendsFriends.CharacterId2 = FriendOfFriend.Id
WHERE deadpool.Name = 'Deadpool'
AND FriendsFriends.CharacterId2 NOT IN( SELECT CharacterId2
FROM MarvelCharacter
INNER JOIN Friends
ON MarvelCharacter.Id = CharacterId1
WHERE Name = 'Deadpool')
GROUP BY FriendOfFriend.Name
ORDER BY COUNT(*) DESC
28
Sooo many joins
MATCH (deadpool:Character)-[:FRIEND_OF*2]->(FriendOfFriend)
WHERE deadpool.name = 'Deadpool'
AND NOT (deadpool)-[:FRIEND_OF]->(FriendOfFriend)
AND NOT deadpool = FriendOfFriend
RETURN FriendOfFriend.name, COUNT(*)
ORDER BY COUNT(*) DESC, FriendOfFriend.name
29
Sooo many joins
MATCH (deadpool:Character)-[:FRIEND_OF*2]->(FriendOfFriend)
FROM MarvelCharacter deadpool
INNER JOIN Friends DeadpoolFriends
ON deadpool.Id = DeadpoolFriends.CharacterId1
INNER JOIN Friends FriendsFriends
ON DeadpoolFriends.CharacterId2 = FriendsFriends.CharacterId1
INNER JOIN MarvelCharacter FriendOfFriend
ON FriendsFriends.CharacterId2 = FriendOfFriend.Id
32
Shortest path
MATCH (deadpool:Character { name:"Deadpool" }),
(other:Character { name:"Ultron" }),
path = shortestPath((deadpool)-[*]-(other))
RETURN path
33
Shortest path
MATCH (deadpool:Character { name:"Deadpool" }),
(other:Character { name:"Ultron" }),
path = shortestPath((deadpool)-[*]-(other))
RETURN path
34
Shortest path
MATCH (deadpool:Character { name:"Deadpool" }),
(other:Character { name:"Ultron" }),
path = shortestPath((deadpool)-[*]-(other))
RETURN path
35
Shortest path
MATCH (deadpool:Character { name:"Deadpool" }),
(other:Character { name:"Ultron" }),
path = shortestPath((deadpool)-[*]-(other))
RETURN path
36
Shortest path
MATCH (deadpool:Character { name:"Deadpool" }),
(other:Character { name:"Ultron" }),
path = shortestPath((deadpool)-[*]-(other))
RETURN path