0221 Cypher for SQL Professionals
Upcoming SlideShare
Loading in...5
×
 

0221 Cypher for SQL Professionals

on

  • 528 views

 

Statistics

Views

Total Views
528
Views on SlideShare
528
Embed Views
0

Actions

Likes
1
Downloads
53
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

0221 Cypher for SQL Professionals 0221 Cypher for SQL Professionals Presentation Transcript

  • Cypher Query Language Michael Hunger @neo4jSunday, February 24, 13
  • The plan • Why graphs? • How graphs? • Why Cypher? • How Cypher - Cypher & SQL side by sideSunday, February 24, 13
  • Why graphs, why now?Sunday, February 24, 13
  • Why graphs, why now? • Big Data is the trend 9 Y P L 97 N W Y P L0 7 N W T5K 0 S @ . ; T5K Q S @ . ; Q B B & ⛽ !2 ? ⛽ !2 ? # O- 3⛵ RC - 3⛵ J X %$ RC 8 X %$ "J8⚾] " ⚽9 ! M DJ ⚾] [ [ ! , ⚽9 E >1 I 7+ O , > E > U A IR 7 + O > 1 WA W# : 34 S ✈✈ R34 S : X T 5U L < K T . I 50 L < H V ☕" I 0 &N . ⛽ K - ⛵ & N A -G☕" ⛽ ⛵ M UA ZG [< % BQ $ ,: 1 MP F ⚾ [< $ ,: 8 ; % BQ ☕4✈ F H Z GV 1⚾P ]8 ; F ☕F ✈ 4 H Z GV ] 2 ? E E⚽ @Y ⚽ @Y 2 ? + CD + CD Sunday, February 24, 13
  • Why graphs, why now? • Big Data is the trend P L 97 N W Y • NOSQL is the answer T5K 0 S @ . ; Q & ⛽ B O- 3⛵ !2 ? # X %$ J RC 8⚾] " , ⚽9 ! > [ D 1 M UJ I 7 + O >E X # :R34 5 ✈ S H V ☕⛵ G " I 0L < ⛽ U& N A [< Z ☕9 1MP F ⚾ 8 ; $ , 9 Y P L 97 N W P ✈ 47 Z GV ] 2 Y F Y L0 H N W @ P L0 7 N W 0 ⚽ T 5 K Q S @ .T 5 K + @ . ; Y ? T5K Q S @ . ; B & ⛽ B & ⛽; Q S CD B ⛽ !2 ? # O- 3⛵ !2 ?3⛵ O- !2 ? - 3⛵ J RC 8 J R X %$ # 8 C " X %$ J RC X %$ " ⚽ ! > [ !81⚾] " , ⚽9 ! M DJ ⚾] [ [ , M9 J ⚾] > E > U A IR 7 + O U E IR A + O > 1 > D 1 W7 , ⚽9 E > I 7+ O W# : 34 S ✈ ✈ 34 S WA✈ R34 S 5U L # :" TI 5U L < K T : X T I 50 L < H V ☕" I 0 H V[☕⛵ - . ⛽ K - ⛵ &X < K . 0 N &N -. &N A ⛽ AG☕" ⛽ ⛵ M UA ZG [< % BQ $ ,: 1MP ⚾F ZG; % BM P ]8 [ < % B 8✈ <$ ,: 1QF ⚾ $ , ;: ☕4✈ F H Z GV 1⚾P ]8 ; F ☕F ☕F ✈ 4 H Z GV ] 2 4 HE GV ? E ⚽ @Y 2 ? E⚽ CD @Y ⚽ Z C @Y 2 ? + CD Sunday, February 24, 13 + + D
  • T5K Q S @ & ⛽ ; !2 ? & ⛽ B # O- 3⛵ RC O- 3⛵ !2 ? X %$ J # X %$ M DJ ⚾] " , ⚽9 ! > J RC8 [ P L 978N] " , ⚽9 ! > IR 7 + > E Y WA Y⚾ W 1 [ 9 Y 1 > E 7 : W 4 S O L 97 N T U ✈ M UJ I . +P D T 5 K 0 S @34; T O L0 # N@ I 5U L 0 7S 3 WA . T &P W Q # :RB 5 5 KX VS T B ; 0 K Q S @. ; Why graphs, why now? ✈ " N 5 < K -. & ⛽ H V X ! I 0 L H<ZG☕⛵ &⚾⛽A 8 [ < % B Q "2 & U ? ⛽ ⛽ RO A & N Q K ⛽ . M - 2 OP ] F $ ,: B ; ! # O- 3⛵ J ZG☕⛵ 1⚾P 3⛵ [ <☕4! QR C 3⛵ X %$ M - 8 ; ⚽FB # ?- C F ,: ✈ 1 $ % H Z GV 2 ? E RC 8 ⚾] " ✈ ⚽9 !#> ⚾ ]" 2 %$[ ! 8 D Y 2 $[ ! , ☕4[ F Z GV > D 1@8 XJ ? ⚽E ⚽ H E J I Y , +9 DJC ] ⚾ @" J ?⚽ X % U ✈ R 7 + O U CWA 7 + OM U 1 A 7 + O 9 E > DJ I 1 S + M ] D >E > I , > # : 34 5 R ✈ T 34 S ✈ W3 S R 4 WX V ☕⛵ G " I 0 L X # :" I 50 L X<#K" . I 50 L < K T ⛽ U& N < K - A H[V %⛵ . & H V N :T &N Z ☕ MP F ⚾ $G☕⛽ Q M U , : 9 Y ; LB < A ⛽ ⛵- G9 Y M P [ < % B Q⚾ :☕ U A : - [< % ✈BigH Z GV the trend F 7 1⚾W P8 Z$ F N W 9 ]8 ; F 1 ]8PZ ☕ 0 • ⚽4 Data is @ T 5 ⚽4 H Z GV. 2✈ E ? , N P ] L☕ 7 1 F F ✈ ; $ , + 9 Y D Y C @Y; 2 04 P G. 7 N 2 E K Q S @ B T 5 K? S Z LV @Y W ⚽ H @ Y ? P L0 7 is the answer • NOSQL N@ . - 3⛵X & W O⛽ + C& ? D !2 ⛽ + Q T5 B D 0 C ; @ . K Q? S T5K Q S # J %$[ ! # O- 3⛵ & ⛽ !2R C RC X B ; B8; " ⚾] J %$[ ⚽9 8 > "# O- 3⛵ ! !2 ? & •⛽ Big X M !2in complexity DJ ⚾] WA , ⚽9 J >$[ !R C 1 DJ ? O- 3⛵in size and R C 7 + M U E I I U ✈ R , O > 1 X 8 O > E % WA "# J %$[ ! : 34 S 7 +⚾] 5U L # :KM4 ✈ R 7 + O . E , ⚽9 > 8 ⚾] " , ⚽9 # > X < ✈ R3 UJ I TD S 1 T>DJ I 1U ✈ R 7 + O ZG H > E☕" WA M 0 H V[ :% . #0 L34 5K - V ⛵ I &X G$⛽ - 5U ⛽ N A ⛵ XIQ & " B : N <S #: 34 5 S ☕4 T F Z , ;< M A 1⚾P ]8 ☕ H 1⚾P " 8 [ <& B Q ☕ F ☕⛵ I ;U% :L < $ N ,A 0 I 0 L < F H- GV @ ✈ ? H EV V ⛽ & N ✈ K Z ⚽ . 24F ZG G ] MP E [ Z ☕9 $ , V ☕" 9 M P G ⛽ ⛵ UA [< BQ 9 Y ,:P $ % CD + ⚽ @Y W FY 1⚾ ✈ D H Z GV F 2? ]8 ; < Z L 1⚾ W ]8 ; ☕4 7 F P✈ F 0 Z GV Y L0 7 N W C 0 7 N + P L4 ⚽ @Y 2 ? N ? E . C. T 5 K S C @Y;2 T 5 K Q S @ B T 5 K + S @ B ; ⚽ H + Q @B . ; Q D D & ⛽ !& ⛽3⛵ ? !2 ? ⛽ !2 ? # O- 3⛵ 2R C O- RC - 3⛵ J X %$ RC 8 X %$ # 8 "J X %$ J8⚾] " ⚽9 ! M DJ ⚾] [ ⚽9 ! ⚾ " , ⚽9 ! > [ , M UJ I > [1 I 7+ O , > E > U A IR 7 + O D E ]WA + O > E 1 > 1 ✈ R34 S7 WA✈ R34 S W# : 34 S ✈ : X T 5U L # :" TI 5U L < K T &X < K . 0 . I 50 L < H V ☕" I 0 H V[☕⛵ - & N . ⛽ K - ⛵ N A ⛽ & N A -G☕" ⛽ ⛵ M UA ZG [< % BQ $ ,: 1MP F ⚾ ZG; % BM P ]8 [ < % B 8✈ <$ ,: 1⚾ QF $ , ;: ☕4✈ F H Z GV 1⚾P ]8 ; F ☕F ☕F ✈ 4 H Z GV ] 2 4 HE GV ? E ⚽ @Y 2 ? E⚽ CD @Y ⚽ Z C @Y 2 ? + CD Sunday, February 24, 13 + + D
  • A graph? Yes, a graphSunday, February 24, 13
  • A graph database... • Mathematical graphs • remember linked lists, trees? • the general-purpose data structure • “A relational database may tell you the average age of everyone in this room, but a graph database will tell you who is most likely to buy you a beer.”Sunday, February 24, 13
  • Some well-known graphsSunday, February 24, 13
  • Some well-known graphs diamondSunday, February 24, 13
  • Some well-known graphs diamond butterflySunday, February 24, 13
  • Some well-known graphs diamond butterfly starSunday, February 24, 13
  • Some well-known graphs diamond butterfly star bullSunday, February 24, 13
  • Some well-known graphs diamond butterfly star bull franklinSunday, February 24, 13
  • Some well-known graphs diamond butterfly star bull franklin robertsonSunday, February 24, 13
  • Some well-known graphs diamond butterfly star bull franklin robertson hortonSunday, February 24, 13
  • Some well-known graphs diamond butterfly star bull franklin robertson horton neo4jSunday, February 24, 13
  • Sunday, February 24, 13
  • Graphs are everywhereSunday, February 24, 13
  • The property graph modelSunday, February 24, 13
  • The property graph modelSunday, February 24, 13
  • The property graph modelSunday, February 24, 13
  • The property graph model :LOVES :LOVES :KNOWS :KNOWS :KNOWSSunday, February 24, 13
  • The property graph model name: “A” age: 35 :LOVES name: “B” age: 35 :LOVES since: 2012 :KNOWS :KNOWS since: 2008 name: “D” age: 35 name: “C” :KNOWS age: 35Sunday, February 24, 13
  • Sunday, February 24, 13
  • You know relationalSunday, February 24, 13
  • You know relationalSunday, February 24, 13
  • You know relational fooSunday, February 24, 13
  • You know relational foo barSunday, February 24, 13
  • You know relational foo foo_bar barSunday, February 24, 13
  • You know relational foo foo_bar barSunday, February 24, 13
  • You know relational foo foo_bar barSunday, February 24, 13
  • You know relational foo foo_bar barSunday, February 24, 13
  • You know relational now consider relationships...Sunday, February 24, 13
  • You know relational now consider relationships...Sunday, February 24, 13
  • You know relational now consider relationships...Sunday, February 24, 13
  • You know relational now consider relationships...Sunday, February 24, 13
  • You know relational now consider relationships...Sunday, February 24, 13
  • You know relational now consider relationships...Sunday, February 24, 13
  • Neo4j is a graph database • Open Source • High Availability • Backed by Neo Technology • In production for 10+ yearsSunday, February 24, 13
  • Why Cypher? • Not only scale of size is hard • Scale of complexity is pretty hard as wellSunday, February 24, 13
  • Cypher attributesSunday, February 24, 13
  • Cypher attributes #1 DeclarativeSunday, February 24, 13
  • Cypher attributes #1 Declarative You tell Cypher what you want, not how to get itSunday, February 24, 13
  • Cypher attributesSunday, February 24, 13
  • Cypher attributes #2 ExpressiveSunday, February 24, 13
  • Cypher attributes #2 Expressive Optimize syntax for readingSunday, February 24, 13
  • Cypher attributesSunday, February 24, 13
  • Cypher attributes #3 Pattern MatchingSunday, February 24, 13
  • Cypher attributes #3 Pattern Matching Patterns are easy for your brainSunday, February 24, 13
  • Cypher attributesSunday, February 24, 13
  • Cypher attributes #4 IdempotentSunday, February 24, 13
  • Cypher attributes #4 Idempotent State change should be expressed idempotentlySunday, February 24, 13
  • 2 Databases 5 QueriesSunday, February 24, 13
  • Sunday, February 24, 13
  • Sunday, February 24, 13
  • Q1 Give me all persons older than 30 yearsSunday, February 24, 13
  • Q1 START n=node:Person("name:*") WHERE n.age>30 RETURN n VS SELECT * FROM Person WHERE age > 30Sunday, February 24, 13
  • Q1 START n=node:Person("name:*") WHERE n.age>30 RETURN n VS SELECT * FROM Person WHERE age > 30Sunday, February 24, 13
  • Q1 START n=node:Person("name:*") WHERE n.age>30 RETURN n VS SELECT * FROM Person WHERE age > 30Sunday, February 24, 13
  • Q1 START n=node:Person("name:*") WHERE n.age>30 RETURN n VS SELECT * FROM Person WHERE age > 30Sunday, February 24, 13
  • Q2 Show me all actors, and which movies they starred inSunday, February 24, 13
  • Neo4j is whiteboard friendlySunday, February 24, 13
  • Neo4j is whiteboard friendly (actor)-[:ACTS_IN]->(movie)Sunday, February 24, 13
  • Neo4j is whiteboard friendly (actor)-[:ACTS_IN]->(movie)Sunday, February 24, 13
  • Q2 START actor=node:Person("name:*") MATCH (actor)-[:ACTS_IN]->(movie) RETURN actor.name, movie.title VS SELECT Person.name, Movie.title FROM Person JOIN Actor on Person.person_id = Actor.person_id JOIN Movie on Movie.movie_id = Actor.movie_idSunday, February 24, 13
  • Q2 START actor=node:Person("name:*") MATCH (actor)-[:ACTS_IN]->(movie) RETURN actor.name, movie.title VS SELECT Person.name, Movie.title FROM Person JOIN Actor on Person.person_id = Actor.person_id JOIN Movie on Movie.movie_id = Actor.movie_idSunday, February 24, 13
  • Q2 START actor=node:Person("name:*") MATCH (actor)-[:ACTS_IN]->(movie) RETURN actor.name, movie.title VS SELECT Person.name, Movie.title FROM Person JOIN Actor on Person.person_id = Actor.person_id JOIN Movie on Movie.movie_id = Actor.movie_idSunday, February 24, 13
  • Q2 START actor=node:Person("name:*") MATCH (actor)-[:ACTS_IN]->(movie) RETURN actor.name, movie.title VS SELECT Person.name, Movie.title FROM Person JOIN Actor on Person.person_id = Actor.person_id JOIN Movie on Movie.movie_id = Actor.movie_idSunday, February 24, 13
  • Q2 START actor=node:Person("name:*") MATCH (actor)-[:ACTS_IN]->(movie) RETURN actor.name, movie.title VS SELECT Person.name, Movie.title FROM Person JOIN Actor on Person.person_id = Actor.person_id JOIN Movie on Movie.movie_id = Actor.movie_idSunday, February 24, 13
  • Q2 START actor=node:Person("name:*") MATCH (actor)-[:ACTS_IN]->(movie) RETURN actor.name, movie.title VS SELECT Person.name, Movie.title FROM Person JOIN Actor on Person.person_id = Actor.person_id JOIN Movie on Movie.movie_id = Actor.movie_idSunday, February 24, 13
  • Q3 Show me all persons that are both actors and directorsSunday, February 24, 13
  • Q3 START person=node:Person("name:*") WHERE (person)-[:ACTS_IN]->() AND (person)-[:DIRECTED]->() RETURN person.name VS SELECT name FROM Person WHERE person_id IN ( SELECT person_id FROM Actor) AND person_id IN ( SELECT person_id FROM Director)Sunday, February 24, 13
  • Q3 START person=node:Person("name:*") WHERE (person)-[:ACTS_IN]->() AND (person)-[:DIRECTED]->() RETURN person.name VS SELECT name FROM Person WHERE person_id IN ( SELECT person_id FROM Actor) AND person_id IN ( SELECT person_id FROM Director)Sunday, February 24, 13
  • Q3 START person=node:Person("name:*") WHERE (person)-[:ACTS_IN]->() AND (person)-[:DIRECTED]->() RETURN person.name VS SELECT name FROM Person WHERE person_id IN ( SELECT person_id FROM Actor) AND person_id IN ( SELECT person_id FROM Director)Sunday, February 24, 13
  • Q3 START person=node:Person("name:*") WHERE (person)-[:ACTS_IN]->() AND (person)-[:DIRECTED]->() RETURN person.name VS SELECT name FROM Person WHERE person_id IN ( SELECT person_id FROM Actor) AND person_id IN ( SELECT person_id FROM Director)Sunday, February 24, 13
  • Q3 START person=node:Person("name:*") WHERE (person)-[:ACTS_IN]->() AND (person)-[:DIRECTED]->() RETURN person.name VS SELECT name FROM Person WHERE person_id IN ( SELECT person_id FROM Actor) AND person_id IN ( SELECT person_id FROM Director)Sunday, February 24, 13
  • Q4 Show me all Lucy’s co-actorsSunday, February 24, 13
  • Q4 START lucy=node:Person(name="Lucy Liu") MATCH lucy-[:ACTS_IN]->movie, co_actor-[:ACTS_IN]->movie RETURN DISTINCT co_actor.name VS SELECT DISTINCT co_actor.name FROM Person lucy JOIN Actor a1 ON lucy.person_id = a1.person_id JOIN Actor a2 ON a1.movie_id = a2.movie_id JOIN Person co_actor ON co_actor.person.id = a2.person_id WHERE lucy.name = "Lucy Liu"Sunday, February 24, 13
  • Q4 START lucy=node:Person(name="Lucy Liu") MATCH lucy-[:ACTS_IN]->movie, co_actor-[:ACTS_IN]->movie RETURN DISTINCT co_actor.name VS SELECT DISTINCT co_actor.name FROM Person lucy JOIN Actor a1 ON lucy.person_id = a1.person_id JOIN Actor a2 ON a1.movie_id = a2.movie_id JOIN Person co_actor ON co_actor.person.id = a2.person_id WHERE lucy.name = "Lucy Liu"Sunday, February 24, 13
  • Q4 START lucy=node:Person(name="Lucy Liu") MATCH lucy-[:ACTS_IN]->movie, co_actor-[:ACTS_IN]->movie RETURN DISTINCT co_actor.name VS SELECT DISTINCT co_actor.name FROM Person lucy JOIN Actor a1 ON lucy.person_id = a1.person_id JOIN Actor a2 ON a1.movie_id = a2.movie_id JOIN Person co_actor ON co_actor.person.id = a2.person_id WHERE lucy.name = "Lucy Liu"Sunday, February 24, 13
  • Q4 START lucy=node:Person(name="Lucy Liu") MATCH lucy-[:ACTS_IN]->movie, co_actor-[:ACTS_IN]->movie RETURN DISTINCT co_actor.name VS SELECT DISTINCT co_actor.name FROM Person lucy JOIN Actor a1 ON lucy.person_id = a1.person_id JOIN Actor a2 ON a1.movie_id = a2.movie_id JOIN Person co_actor ON co_actor.person.id = a2.person_id WHERE lucy.name = "Lucy Liu"Sunday, February 24, 13
  • Q4 START lucy=node:Person(name="Lucy Liu") MATCH lucy-[:ACTS_IN]->movie, co_actor-[:ACTS_IN]->movie RETURN DISTINCT co_actor.name VS SELECT DISTINCT co_actor.name FROM Person lucy JOIN Actor a1 ON lucy.person_id = a1.person_id JOIN Actor a2 ON a1.movie_id = a2.movie_id JOIN Person co_actor ON co_actor.person.id = a2.person_id WHERE lucy.name = "Lucy Liu"Sunday, February 24, 13
  • Q4 START lucy=node:Person(name="Lucy Liu" MATCH lucy-[:ACTS_IN]->movie, co_actor-[:ACTS_IN]->movie RETURN DISTINCT co_actor.name; VS SELECT DISTINCT co_actor.name FROM Person lucy JOIN Actor a1 ON lucy.person_id = a1.person_id JOIN Actor a2 ON a1.movie_id = a2.movie_id JOIN Person co_actor ON co_actor.person.id = a2.person_id WHERE lucy.name = "Lucy Liu"Sunday, February 24, 13
  • Q5 Show me Lucy’s favorite directorsSunday, February 24, 13
  • Q5 START lucy=node:Person(name="Lucy Liu") MATCH lucy-[:ACTS_IN]->movie, director-[:DIRECTED]->movie RETURN director.name, count(*) ORDER BY count(*) desc VS SELECT dir.name, count(*) FROM Person lucy JOIN Actor on Person.person_id = Actor.person_id JOIN Director on Actor.movie_id = Director.movie_id JOIN Person dir on Director.person.id = dir.person_id WHERE lucy.name = "Lucy Liu" GROUP BY dir.name ORDER BY count(*) DESCSunday, February 24, 13
  • Q5 START lucy=node:Person(name="Lucy Liu") MATCH lucy-[:ACTS_IN]->movie, director-[:DIRECTED]->movie RETURN director.name, count(*) ORDER BY count(*) desc VS SELECT dir.name, count(*) FROM Person lucy JOIN Actor on Person.person_id = Actor.person_id JOIN Director on Actor.movie_id = Director.movie_id JOIN Person dir on Director.person.id = dir.person_id WHERE lucy.name = "Lucy Liu" GROUP BY dir.name ORDER BY count(*) DESCSunday, February 24, 13
  • Q5 START lucy=node:Person(name="Lucy Liu") MATCH lucy-[:ACTS_IN]->movie, director-[:DIRECTED]->movie RETURN director.name, count(*) ORDER BY count(*) desc VS SELECT dir.name, count(*) FROM Person lucy JOIN Actor on Person.person_id = Actor.person_id JOIN Director on Actor.movie_id = Director.movie_id JOIN Person dir on Director.person.id = dir.person_id WHERE lucy.name = "Lucy Liu" GROUP BY dir.name ORDER BY count(*) DESCSunday, February 24, 13
  • Q5 START lucy=node:Person(name="Lucy Liu") MATCH lucy-[:ACTS_IN]->movie, director-[:DIRECTED]->movie RETURN director.name, count(*) ORDER BY count(*) desc VS SELECT dir.name, count(*) FROM Person lucy JOIN Actor on Person.person_id = Actor.person_id JOIN Director on Actor.movie_id = Director.movie_id JOIN Person dir on Director.person.id = dir.person_id WHERE lucy.name = "Lucy Liu" GROUP BY dir.name ORDER BY count(*) DESCSunday, February 24, 13
  • Q5 START lucy=node:Person(name="Lucy Liu") MATCH lucy-[:ACTS_IN]->movie, director-[:DIRECTED]->movie RETURN director.name, count(*) ORDER BY count(*) desc VS SELECT dir.name, count(*) FROM Person lucy JOIN Actor on Person.person_id = Actor.person_id JOIN Director on Actor.movie_id = Director.movie_id JOIN Person dir on Director.person.id = dir.person_id WHERE lucy.name = "Lucy Liu" GROUP BY dir.name ORDER BY count(*) DESCSunday, February 24, 13
  • Q5 START lucy=node:Person(name="Lucy Liu") MATCH lucy-[:ACTS_IN]->movie, director-[:DIRECTED]->movie RETURN director.name, count(*) ORDER BY count(*) desc VS SELECT dir.name, count(*) FROM Person lucy JOIN Actor on Person.person_id = Actor.person_id JOIN Director on Actor.movie_id = Director.movie_id JOIN Person dir on Director.person.id = dir.person_id WHERE lucy.name = "Lucy Liu" GROUP BY dir.name ORDER BY count(*) DESCSunday, February 24, 13
  • Q5 START lucy=node:Person(name="Lucy Liu") MATCH lucy-[:ACTS_IN]->movie, director-[:DIRECTED]->movie RETURN director.name, count(*) ORDER BY count(*) desc VS SELECT dir.name, count(*) FROM Person lucy JOIN Actor on Person.person_id = Actor.person_id JOIN Director on Actor.movie_id = Director.movie_id JOIN Person dir on Director.person.id = dir.person_id WHERE lucy.name = "Lucy Liu" GROUP BY dir.name ORDER BY count(*) DESCSunday, February 24, 13
  • Q5 START lucy=node:Person(name="Lucy Liu") MATCH lucy-[:ACTS_IN]->movie, director-[:DIRECTED]->movie RETURN director.name, count(*) ORDER BY count(*) desc VS SELECT dir.name, count(*) FROM Person lucy JOIN Actor on Person.person_id = Actor.person_id JOIN Director on Actor.movie_id = Director.movie_id JOIN Person dir on Director.person.id = dir.person_id WHERE lucy.name = "Lucy Liu" GROUP BY dir.name ORDER BY count(*) DESCSunday, February 24, 13
  • ...fasten your seat belt Dorothy, cause Kansas is going bye-byeSunday, February 24, 13
  • Q4’ Show me all Lucy’s co-actorsSunday, February 24, 13
  • Q4 START lucy=node:Person(name="Lucy Liu") MATCH lucy-[:ACTS_IN]->movie, co_actor-[:ACTS_IN]->movie RETURN DISTINCT co_actor.nameSunday, February 24, 13
  • Q4’ START lucy=node:Person(name="Lucy Liu") MATCH lucy-[:ACTS_IN*2..2]-co_actor RETURN DISTINCT co_actor.nameSunday, February 24, 13
  • Q4’ START lucy=node:Person(name="Lucy Liu") MATCH lucy-[:ACTS_IN*2..2]-co_actor RETURN DISTINCT co_actor.nameSunday, February 24, 13
  • Q6 Bacon LucySunday, February 24, 13
  • START lucy=node:Person(name="Lucy Liu"), kevin=node:Person(name="Kevin Bacon") MATCH p = shortestPath( lucy-[:ACTS_IN*]-kevin ) RETURN EXTRACT(n in NODES(p) : COALESCE(n.name?, n.title?))Sunday, February 24, 13
  • START lucy=node:Person(name="Lucy Liu"), kevin=node:Person(name="Kevin Bacon") MATCH p = shortestPath( lucy-[:ACTS_IN*]-kevin ) RETURN EXTRACT(n in NODES(p) : COALESCE(n.name?, n.title?))Sunday, February 24, 13
  • START lucy=node:Person(name="Lucy Liu"), kevin=node:Person(name="Kevin Bacon") MATCH p = shortestPath( lucy-[:ACTS_IN*]-kevin ) RETURN EXTRACT(n in NODES(p) : COALESCE(n.name?, n.title?))Sunday, February 24, 13
  • Q6 START lucy=node:Person(name="Lucy Liu"), kevin=node:Person(name="Kevin Bacon") MATCH p = shortestPath( lucy-[:ACTS_IN*]-kevin ) RETURN EXTRACT(n in NODES(p) : COALESCE(n.name?, n.title?))Sunday, February 24, 13
  • START lucy=node:Person(name="Lucy Liu"), kevin=node:Person(name="Kevin Bacon") MATCH p = shortestPath( lucy-[:ACTS_IN*]-kevin ) RETURN EXTRACT(n in NODES(p) : COALESCE(n.name?, n.title?))Sunday, February 24, 13
  • START lucy=node:Person(name="Lucy Liu"), kevin=node:Person(name="Kevin Bacon") MATCH p = shortestPath( lucy-[:ACTS_IN*]-kevin ) RETURN EXTRACT(n in NODES(p) : COALESCE(n.name?, n.title?))Sunday, February 24, 13
  • START lucy=node:Person(name="Lucy Liu"), kevin=node:Person(name="Kevin Bacon") MATCH p = shortestPath( lucy-[:ACTS_IN*]-kevin ) RETURN EXTRACT(n in NODES(p) : COALESCE(n.name?, n.title?))Sunday, February 24, 13
  • Create Cypher 2 (the movie)Sunday, February 24, 13
  • START lucy = node:Person(name="Lucy Liu"), david = node:Person(name="David Lynch") CREATE andres={name:"Andrés Taylor"}, cypher2={title:"Cypher 2"}, lucy-[:ACTS_IN {name:"Rita Foster"}]->cypher2, andres-[:ACTS_IN {name:"Manuel"}]->cypher2, david-[:DIRECTED]->cypher2 RETURN cypher2Sunday, February 24, 13
  • START lucy = node:Person(name="Lucy Liu"), david = node:Person(name="David Lynch") CREATE andres={name:"Andrés Taylor"}, cypher2={title:"Cypher 2"}, lucy-[:ACTS_IN {name:"Rita Foster"}]->cypher2, andres-[:ACTS_IN {name:"Manuel"}]->cypher2, david-[:DIRECTED]->cypher2 RETURN cypher2Sunday, February 24, 13
  • START lucy = node:Person(name="Lucy Liu"), david = node:Person(name="David Lynch") CREATE andres={name:"Andrés Taylor"}, cypher2={title:"Cypher 2"}, lucy-[:ACTS_IN {name:"Rita Foster"}]->cypher2, andres-[:ACTS_IN {name:"Manuel"}]->cypher2, david-[:DIRECTED]->cypher2 RETURN cypher2Sunday, February 24, 13
  • START lucy = node:Person(name="Lucy Liu"), david = node:Person(name="David Lynch") CREATE andres={name:"Andrés Taylor"}, cypher2={title:"Cypher 2"}, lucy-[:ACTS_IN {name:"Rita Foster"}]->cypher2, andres-[:ACTS_IN {name:"Manuel"}]->cypher2, david-[:DIRECTED]->cypher2 RETURN cypher2Sunday, February 24, 13
  • START lucy = node:Person(name="Lucy Liu"), david = node:Person(name="David Lynch") CREATE andres={name:"Andrés Taylor"}, cypher2={title:"Cypher 2"}, lucy-[:ACTS_IN {name:"Rita Foster"}]->cypher2, andres-[:ACTS_IN {name:"Manuel"}]->cypher2, david-[:DIRECTED]->cypher2 RETURN cypher2Sunday, February 24, 13
  • START lucy = node:Person(name="Lucy Liu"), david = node:Person(name="David Lynch") CREATE andres={name:"Andrés Taylor"}, cypher2={title:"Cypher 2"}, lucy-[:ACTS_IN {name:"Rita Foster"}]->cypher2, andres-[:ACTS_IN {name:"Manuel"}]->cypher2, david-[:DIRECTED]->cypher2 RETURN cypher2Sunday, February 24, 13
  • Add genre nodesSunday, February 24, 13
  • Person :DIRECTED :ACTS_IN Movie Genre :GENRE :IS_GENRE RootSunday, February 24, 13
  • Movie Movie title:"Highlander" title:"The Matrix" genre: "Action" genre: "Action" :GENRE :GENRE Genre name: "Action" :IS_GENRE RootSunday, February 24, 13
  • START ref=node(0), movie=node:Movie("title:*") WHERE HAS(movie.genre) CREATE UNIQUE ref<-[:IS_GENRE]->(genre {name:movie.genre}) genre-[:GENRE]->movieSunday, February 24, 13
  • START ref=node(0), movie=node:Movie("title:*") WHERE HAS(movie.genre) CREATE UNIQUE ref<-[:IS_GENRE]->(genre {name:movie.genre}) genre-[:GENRE]->movieSunday, February 24, 13
  • START ref=node(0), movie=node:Movie("title:*") WHERE HAS(movie.genre) CREATE UNIQUE ref<-[:IS_GENRE]->(genre {name:movie.genre}) genre-[:GENRE]->movieSunday, February 24, 13
  • START ref=node(0), movie=node:Movie("title:*") WHERE HAS(movie.genre) CREATE UNIQUE ref<-[:IS_GENRE]->(genre {name:movie.genre}) genre-[:GENRE]->movieSunday, February 24, 13
  • RehashSunday, February 24, 13
  • START designates the start pointsSunday, February 24, 13
  • MATCH describes the patternSunday, February 24, 13
  • WHERE filters the result setSunday, February 24, 13
  • CREATE creates nodes and relationshipsSunday, February 24, 13
  • CREATE UNIQUE creates unique patternsSunday, February 24, 13
  • RETURN creates the result tableSunday, February 24, 13
  • QUESTION ALL THE THINGS!Sunday, February 24, 13