@lifeistooshort
"A collection of vertices and edges that join pairs of vertices"
In Neo4J this means Nodes and Relationships
The definition is G(V,E)
2|E|=Σdeg(v)
Cartography
Electrical Engineering
Physics
Biology
All bridges are crossed once and only once
Eulerian Circuits start and stop on same node
Depends on Degrees (0 or 2 odd)
Zombieland
Bill Murray
Bill Murray
ACTS_IN
ACTS_IN
Non-directed graphs do not have a start or end node.
We can also weight these relations
Directed graphs allow for a direction in a relationship.
Graphs can morph into many views
Great for inferring relationships
Quickest way to find related nodes
Tried and true technology for highly structured data.
Joins use keys
May require mapping tables
Finding friends of friends becomes memory intensive
Non-Native storage translates from relational to graph
SELECT p1.Person AS PERSON, p2.Person AS FRIEND_OF_FRIEND FROM PersonFriend pf1 JOIN Person p1 ON pf1.PersonID = p1.ID JOIN PersonFriend pf2 ON pf2.PersonID = pf1.FriendID JOIN Person p2 ON pf2.FriendID = p2.ID WHERE p1.Person = 'Alice' AND pf2.FriendID <> p1.ID
Describes storing data as documents, columns, key-value pairs and more
Less rigid
Can create a relationship by storing a document's ID field
Now the application is responsible for joins (map-reduce)
Can create models that more closely resemble the domain
Relationships are first-class citizens
No need to match means less resource usage
Use Native Storage
Nodes 9 bytes, Relationships are 33
IDs are based on position (exp 100*9)
InUse is like a delete field
"They (graph techniques) are especially useful when we want to gain insight into a new domain--or even understand what kind of insight it's possible to extract from a domain" -- Graph Databases
Pop items on stack till there is no place to go. Then we pop off
Once the stack is empty we are done.
All related nodes are added to a queue.
After all related nodes are visited the base node is popped off the queue.
Java based GraphDB
Native & REST Interfaces
Server & Embedded Versions
Supports Scaling and Sharding
Index-free adjacency allows for millisecond response.
Reduces object-relational impedance mismatch
Easy to change and adapt
ACID
You still want a relational store
Memory is more expensive than space
Lack of developers
Download Neo4J
Default port is 7474
Run Neo4J just like Tomcat
You can add JAX-RS endpoints
Listen directly for transactions
Only called on write transactions that will be commited
Can be used to prevent physical deletions
Java-Based
Allows for imperative declaration
Java-Based
Relationships are only traversed when accessed
You will need domain info in code
// Index lookup for the node representing the doctor is omitted for brevity
Iterable<Relationship> relationships = doctor.getRelationships(Direction.INCOMING, COMPANION_OF );
for ( Relationship rel : relationships )
{
Node companionNode = rel.getStartNode();
if ( companionNode.hasRelationship( Direction.OUTGOING, IS_A ) )
{
Relationship singleRelationship = companionNode.getSingleRelationship( IS_A, Direction.OUTGOING );
Node endNode = singleRelationship.getEndNode();
if ( endNode.equals( human ) )
{
// Found one!
}
}
}
Java-Based
Used to gain specific control over traversals
Declarative Interface
You can fall back to the Core APIs
Accessible Via Java or REST
Typically results in JSON
Query language
Most common way to interface
Match reads nodes/relationships
Creates a nodes/relationships
Creates nodes/relationships if none exist, otherwise it updates the existing one
Removes nodes/relationships
JackieRGleason.com
neo4j.com/graphacademy