Upload
thoughtworks
View
1.553
Download
2
Tags:
Embed Size (px)
Citation preview
Neo4j Introduction
the basic stuff
Agenda
● What / Why
● Learn through an FoF example
● More involved problem: Which airport
performans better
● Advance modeling topics
What is it?
A Graph Database
A Graph Database
Relational Model
In Graph
Why Graph Database
● Wicked fast on a type of problem
● Scale up independent of amount of data
● Intuitive modeling
● Fun and Freedom (embedded mode)
Setup (on a mac)
$> brew update
$> brew install neo4j
$> neo4j start
$> open http://localhost:7474
3 way to use
* Standalone with Cypher *
* Server plugin
* Embedded
Cypher
is the way get stuff out from Neo4j graph
A FoF example covers
Create
Match
Where
Count
Order by
Create node/relationship
create(joe:Person {name: Joe” })
create(sara:Person {name: “Sara” })
create joe-[:knows]->sara
Who is Joe’s friend?
MATCH (joe { name: 'Joe' })-[:knows]-(friends)
RETURN joe, friends
Joe’s friends of friends
MATCH (joe { name: 'Joe' })-[:knows*2..2]-(fof)
RETURN fof
Wait, Joe already knows sara
MATCH (joe { name: 'Joe' })-[:knows*2..2]-(fof)
WHERE NOT(joe-[:knows]-fof)
RETURN fof
Who is more likely to be Joe's
friend?
MATCH (joe { name: 'Joe' })-[:knows*2..2]-(fof)
WHERE NOT(joe-[:knows]-fof)
RETURN fof.name, count(*)
ORDER BY count(*) DESC, fof.name
A flight/airport example
http://gist.neo4j.org/?6619085
Data From
http://www.transtats.bts.gov/DL_SelectFields.a
sp?Table_ID=236&DB_Short_Name=On-Time
Data model
Ask questions
● How many flight canceled
● How many flight delayed
● Average taxi waiting time
● Shortest path between
Other way to use neo4j
● Embedded (CTA)
● Server plugin (Grok)
Neo4j modeling tips
● Understand the performance character○ Traversing is fast
○ IO is slow
○ Node properties are lazy loaded/cached
● Normalization verse denormalization in
relational database performance tuning