SlideShare uma empresa Scribd logo
1 de 128
Baixar para ler offline
Cypher Query Language
                                Michael Hunger
                                   @neo4j




Sunday, February 24, 13
The plan


                    • Why graphs?
                    • How graphs?
                    • Why Cypher?
                    • How Cypher - Cypher & SQL side by side



Sunday, 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 %$
                                           "J
8⚾]         "               ⚽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 %$                           "      ⚽ ! >             [ !
8
1⚾]         "
                   ,       ⚽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        ⛽       A
G☕"  ⛽
     ⛵             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                W
X
   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 1
U ✈ 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 %$
                                                                 J
8⚾]         "               ⚽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 graph




Sunday, 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 graphs




Sunday, February 24, 13
Some well-known graphs


                      diamond




Sunday, February 24, 13
Some well-known graphs


                      diamond   butterfly




Sunday, February 24, 13
Some well-known graphs


                      diamond   butterfly   star




Sunday, February 24, 13
Some well-known graphs


                      diamond   butterfly   star   bull




Sunday, February 24, 13
Some well-known graphs


                      diamond    butterfly   star   bull




                      franklin




Sunday, February 24, 13
Some well-known graphs


                      diamond    butterfly    star   bull




                      franklin   robertson




Sunday, February 24, 13
Some well-known graphs


                      diamond    butterfly     star    bull




                      franklin   robertson   horton




Sunday, February 24, 13
Some well-known graphs


                      diamond    butterfly     star     bull




                      franklin   robertson   horton   neo4j




Sunday, February 24, 13
Sunday, February 24, 13
Graphs are everywhere




Sunday, February 24, 13
The property graph model




Sunday, February 24, 13
The property graph model




Sunday, February 24, 13
The property graph model




Sunday, February 24, 13
The property graph model
                                 :LOVES

                                 :LOVES
                                              :KNOWS
                                     :KNOWS


                                     :KNOWS



Sunday, 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: 35




Sunday, February 24, 13
Sunday, February 24, 13
You know relational




Sunday, February 24, 13
You know relational




Sunday, February 24, 13
You know relational




                          foo

Sunday, February 24, 13
You know relational




                          foo   bar

Sunday, February 24, 13
You know relational




                          foo   foo_bar   bar

Sunday, February 24, 13
You know relational




                          foo   foo_bar   bar

Sunday, February 24, 13
You know relational




                          foo   foo_bar   bar

Sunday, February 24, 13
You know relational




                          foo   foo_bar   bar

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
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+ years



Sunday, February 24, 13
Why Cypher?



                    • Not only scale of size is hard
                    • Scale of complexity is pretty hard as well




Sunday, February 24, 13
Cypher attributes




Sunday, February 24, 13
Cypher attributes



                     #1 Declarative




Sunday, February 24, 13
Cypher attributes



                     #1 Declarative

                     You tell Cypher what you want, not how to get it




Sunday, February 24, 13
Cypher attributes




Sunday, February 24, 13
Cypher attributes



                     #2 Expressive




Sunday, February 24, 13
Cypher attributes



                     #2 Expressive

                     Optimize syntax for reading




Sunday, February 24, 13
Cypher attributes




Sunday, February 24, 13
Cypher attributes



                     #3 Pattern Matching




Sunday, February 24, 13
Cypher attributes



                     #3 Pattern Matching

                     Patterns are easy for your brain




Sunday, February 24, 13
Cypher attributes




Sunday, February 24, 13
Cypher attributes



                     #4 Idempotent




Sunday, February 24, 13
Cypher attributes



                     #4 Idempotent

                     State change should be expressed idempotently




Sunday, February 24, 13
2 Databases
                           5 Queries



Sunday, February 24, 13
Sunday, February 24, 13
Sunday, February 24, 13
Q1




                          Give me all persons older
                               than 30 years




Sunday, February 24, 13
Q1

                      START n=node:Person("name:*")
                      WHERE n.age>30
                      RETURN n

                                     VS


                          SELECT *
                          FROM Person
                          WHERE age > 30


Sunday, February 24, 13
Q1

                      START n=node:Person("name:*")
                      WHERE n.age>30
                      RETURN n

                                     VS


                          SELECT *
                          FROM Person
                          WHERE age > 30


Sunday, February 24, 13
Q1

                      START n=node:Person("name:*")
                      WHERE n.age>30
                      RETURN n

                                     VS


                          SELECT *
                          FROM Person
                          WHERE age > 30


Sunday, February 24, 13
Q1

                      START n=node:Person("name:*")
                      WHERE n.age>30
                      RETURN n

                                     VS


                          SELECT *
                          FROM Person
                          WHERE age > 30


Sunday, February 24, 13
Q2




                 Show me all actors, and which
                    movies they starred in




Sunday, February 24, 13
Neo4j is whiteboard friendly




Sunday, 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_id
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_id
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_id
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_id
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_id
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_id
Sunday, February 24, 13
Q3




                    Show me all persons that are
                     both actors and directors




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
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-actors




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
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 directors




Sunday, 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(*) DESC
Sunday, 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(*) DESC
Sunday, 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(*) DESC
Sunday, 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(*) DESC
Sunday, 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(*) DESC
Sunday, 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(*) DESC
Sunday, 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(*) DESC
Sunday, 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(*) DESC
Sunday, February 24, 13
...fasten your seat belt Dorothy,
     'cause Kansas is going bye-bye



Sunday, February 24, 13
Q4’




                           Show me all
                          Lucy’s co-actors




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



Sunday, February 24, 13
Q4’




   START
     lucy=node:Person(name="Lucy Liu")
   MATCH
     lucy-[:ACTS_IN*2..2]-co_actor
   RETURN
     DISTINCT co_actor.name




Sunday, February 24, 13
Q4’




   START
     lucy=node:Person(name="Lucy Liu")
   MATCH
     lucy-[:ACTS_IN*2..2]-co_actor
   RETURN
     DISTINCT co_actor.name




Sunday, February 24, 13
Q6




                          Bacon Lucy



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
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 cypher2




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 cypher2




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 cypher2




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 cypher2




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 cypher2




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 cypher2




Sunday, February 24, 13
Add genre nodes



Sunday, February 24, 13
Person


                     :DIRECTED   :ACTS_IN


                             Movie             Genre
                                      :GENRE

                                                 :IS_GENRE

                                               Root




Sunday, February 24, 13
Movie                                 Movie
                title:"Highlander"                    title:"The Matrix"
                  genre: "Action"                       genre: "Action"



                          :GENRE                  :GENRE

                                        Genre
                                     name: "Action"



                                             :IS_GENRE

                                         Root

Sunday, 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]->movie




Sunday, 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]->movie




Sunday, 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]->movie




Sunday, 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]->movie




Sunday, February 24, 13
Rehash




Sunday, February 24, 13
START
                          designates the start points




Sunday, February 24, 13
MATCH
                          describes the pattern




Sunday, February 24, 13
WHERE
                          filters the result set




Sunday, February 24, 13
CREATE
                          creates nodes and relationships




Sunday, February 24, 13
CREATE UNIQUE
                          creates unique patterns




Sunday, February 24, 13
RETURN
                          creates the result table




Sunday, February 24, 13
QUESTION




                          ALL THE THINGS!
Sunday, February 24, 13

Mais conteúdo relacionado

Semelhante a 0221 Cypher for SQL Professionals

NoSQL Now! Introduction to Graph Databases
NoSQL Now! Introduction to Graph DatabasesNoSQL Now! Introduction to Graph Databases
NoSQL Now! Introduction to Graph Databasesakollegger
 
Bhart rahari 01-06
Bhart rahari 01-06Bhart rahari 01-06
Bhart rahari 01-06venkatesha9
 
Webcast4 t06port2
Webcast4 t06port2Webcast4 t06port2
Webcast4 t06port2Petrobras
 
持续集成中心:新时代的软件研发管理体系
持续集成中心:新时代的软件研发管理体系持续集成中心:新时代的软件研发管理体系
持续集成中心:新时代的软件研发管理体系gigix1980
 
From Japanese mobile-web world, to Latin-1 developers. (a part of "East Meets...
From Japanese mobile-web world, to Latin-1 developers. (a part of "East Meets...From Japanese mobile-web world, to Latin-1 developers. (a part of "East Meets...
From Japanese mobile-web world, to Latin-1 developers. (a part of "East Meets...Yoji Shidara
 
理想のガイガーカウンター vs 私のガイガーカウンター
理想のガイガーカウンター vs 私のガイガーカウンター理想のガイガーカウンター vs 私のガイガーカウンター
理想のガイガーカウンター vs 私のガイガーカウンターgcmorg
 
قانون تنظيم الجامعات
قانون تنظيم الجامعاتقانون تنظيم الجامعات
قانون تنظيم الجامعاتManar Hassan
 
les petites villes surprennent :Dossier baromètre des villes marocaines 2011 ...
les petites villes surprennent :Dossier baromètre des villes marocaines 2011 ...les petites villes surprennent :Dossier baromètre des villes marocaines 2011 ...
les petites villes surprennent :Dossier baromètre des villes marocaines 2011 ...Tizart Lab
 

Semelhante a 0221 Cypher for SQL Professionals (12)

NoSQL Now! Introduction to Graph Databases
NoSQL Now! Introduction to Graph DatabasesNoSQL Now! Introduction to Graph Databases
NoSQL Now! Introduction to Graph Databases
 
Bhart rahari 01-06
Bhart rahari 01-06Bhart rahari 01-06
Bhart rahari 01-06
 
Webcast4 t06port2
Webcast4 t06port2Webcast4 t06port2
Webcast4 t06port2
 
持续集成中心:新时代的软件研发管理体系
持续集成中心:新时代的软件研发管理体系持续集成中心:新时代的软件研发管理体系
持续集成中心:新时代的软件研发管理体系
 
Bocham
BochamBocham
Bocham
 
From Japanese mobile-web world, to Latin-1 developers. (a part of "East Meets...
From Japanese mobile-web world, to Latin-1 developers. (a part of "East Meets...From Japanese mobile-web world, to Latin-1 developers. (a part of "East Meets...
From Japanese mobile-web world, to Latin-1 developers. (a part of "East Meets...
 
Iuml mankada mandalam commitee
Iuml mankada mandalam commiteeIuml mankada mandalam commitee
Iuml mankada mandalam commitee
 
理想のガイガーカウンター vs 私のガイガーカウンター
理想のガイガーカウンター vs 私のガイガーカウンター理想のガイガーカウンター vs 私のガイガーカウンター
理想のガイガーカウンター vs 私のガイガーカウンター
 
قانون تنظيم الجامعات
قانون تنظيم الجامعاتقانون تنظيم الجامعات
قانون تنظيم الجامعات
 
ICT Computer Market 2008 V1
ICT Computer Market 2008 V1ICT Computer Market 2008 V1
ICT Computer Market 2008 V1
 
Shakespeare henrique-viii
Shakespeare henrique-viiiShakespeare henrique-viii
Shakespeare henrique-viii
 
les petites villes surprennent :Dossier baromètre des villes marocaines 2011 ...
les petites villes surprennent :Dossier baromètre des villes marocaines 2011 ...les petites villes surprennent :Dossier baromètre des villes marocaines 2011 ...
les petites villes surprennent :Dossier baromètre des villes marocaines 2011 ...
 

Último

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 

Último (20)

Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 

0221 Cypher for SQL Professionals

  • 1. Cypher Query Language Michael Hunger @neo4j Sunday, February 24, 13
  • 2. The plan • Why graphs? • How graphs? • Why Cypher? • How Cypher - Cypher & SQL side by side Sunday, February 24, 13
  • 3. Why graphs, why now? Sunday, February 24, 13
  • 4. 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 %$ "J 8⚾] " ⚽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
  • 5. 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 %$ " ⚽ ! > [ ! 8 1⚾] " , ⚽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 ⛽ A G☕" ⛽ ⛵ 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
  • 6. 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 W X 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 1 U ✈ 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 %$ J 8⚾] " ⚽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
  • 7. A graph? Yes, a graph Sunday, February 24, 13
  • 8. 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
  • 10. Some well-known graphs diamond Sunday, February 24, 13
  • 11. Some well-known graphs diamond butterfly Sunday, February 24, 13
  • 12. Some well-known graphs diamond butterfly star Sunday, February 24, 13
  • 13. Some well-known graphs diamond butterfly star bull Sunday, February 24, 13
  • 14. Some well-known graphs diamond butterfly star bull franklin Sunday, February 24, 13
  • 15. Some well-known graphs diamond butterfly star bull franklin robertson Sunday, February 24, 13
  • 16. Some well-known graphs diamond butterfly star bull franklin robertson horton Sunday, February 24, 13
  • 17. Some well-known graphs diamond butterfly star bull franklin robertson horton neo4j Sunday, February 24, 13
  • 19. Graphs are everywhere Sunday, February 24, 13
  • 20. The property graph model Sunday, February 24, 13
  • 21. The property graph model Sunday, February 24, 13
  • 22. The property graph model Sunday, February 24, 13
  • 23. The property graph model :LOVES :LOVES :KNOWS :KNOWS :KNOWS Sunday, February 24, 13
  • 24. 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: 35 Sunday, February 24, 13
  • 26. You know relational Sunday, February 24, 13
  • 27. You know relational Sunday, February 24, 13
  • 28. You know relational foo Sunday, February 24, 13
  • 29. You know relational foo bar Sunday, February 24, 13
  • 30. You know relational foo foo_bar bar Sunday, February 24, 13
  • 31. You know relational foo foo_bar bar Sunday, February 24, 13
  • 32. You know relational foo foo_bar bar Sunday, February 24, 13
  • 33. You know relational foo foo_bar bar Sunday, February 24, 13
  • 34. You know relational now consider relationships... Sunday, February 24, 13
  • 35. You know relational now consider relationships... Sunday, February 24, 13
  • 36. You know relational now consider relationships... Sunday, February 24, 13
  • 37. You know relational now consider relationships... Sunday, February 24, 13
  • 38. You know relational now consider relationships... Sunday, February 24, 13
  • 39. You know relational now consider relationships... Sunday, February 24, 13
  • 40. Neo4j is a graph database • Open Source • High Availability • Backed by Neo Technology • In production for 10+ years Sunday, February 24, 13
  • 41. Why Cypher? • Not only scale of size is hard • Scale of complexity is pretty hard as well Sunday, February 24, 13
  • 43. Cypher attributes #1 Declarative Sunday, February 24, 13
  • 44. Cypher attributes #1 Declarative You tell Cypher what you want, not how to get it Sunday, February 24, 13
  • 46. Cypher attributes #2 Expressive Sunday, February 24, 13
  • 47. Cypher attributes #2 Expressive Optimize syntax for reading Sunday, February 24, 13
  • 49. Cypher attributes #3 Pattern Matching Sunday, February 24, 13
  • 50. Cypher attributes #3 Pattern Matching Patterns are easy for your brain Sunday, February 24, 13
  • 52. Cypher attributes #4 Idempotent Sunday, February 24, 13
  • 53. Cypher attributes #4 Idempotent State change should be expressed idempotently Sunday, February 24, 13
  • 54. 2 Databases 5 Queries Sunday, February 24, 13
  • 57. Q1 Give me all persons older than 30 years Sunday, February 24, 13
  • 58. Q1 START n=node:Person("name:*") WHERE n.age>30 RETURN n VS SELECT * FROM Person WHERE age > 30 Sunday, February 24, 13
  • 59. Q1 START n=node:Person("name:*") WHERE n.age>30 RETURN n VS SELECT * FROM Person WHERE age > 30 Sunday, February 24, 13
  • 60. Q1 START n=node:Person("name:*") WHERE n.age>30 RETURN n VS SELECT * FROM Person WHERE age > 30 Sunday, February 24, 13
  • 61. Q1 START n=node:Person("name:*") WHERE n.age>30 RETURN n VS SELECT * FROM Person WHERE age > 30 Sunday, February 24, 13
  • 62. Q2 Show me all actors, and which movies they starred in Sunday, February 24, 13
  • 63. Neo4j is whiteboard friendly Sunday, February 24, 13
  • 64. Neo4j is whiteboard friendly (actor)-[:ACTS_IN]->(movie) Sunday, February 24, 13
  • 65. Neo4j is whiteboard friendly (actor)-[:ACTS_IN]->(movie) Sunday, February 24, 13
  • 66. 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_id Sunday, February 24, 13
  • 67. 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_id Sunday, February 24, 13
  • 68. 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_id Sunday, February 24, 13
  • 69. 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_id Sunday, February 24, 13
  • 70. 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_id Sunday, February 24, 13
  • 71. 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_id Sunday, February 24, 13
  • 72. Q3 Show me all persons that are both actors and directors Sunday, February 24, 13
  • 73. 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
  • 74. 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
  • 75. 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
  • 76. 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
  • 77. 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
  • 78. Q4 Show me all Lucy’s co-actors Sunday, February 24, 13
  • 79. 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
  • 80. 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
  • 81. 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
  • 82. 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
  • 83. 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
  • 84. 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
  • 85. Q5 Show me Lucy’s favorite directors Sunday, February 24, 13
  • 86. 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(*) DESC Sunday, February 24, 13
  • 87. 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(*) DESC Sunday, February 24, 13
  • 88. 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(*) DESC Sunday, February 24, 13
  • 89. 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(*) DESC Sunday, February 24, 13
  • 90. 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(*) DESC Sunday, February 24, 13
  • 91. 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(*) DESC Sunday, February 24, 13
  • 92. 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(*) DESC Sunday, February 24, 13
  • 93. 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(*) DESC Sunday, February 24, 13
  • 94. ...fasten your seat belt Dorothy, 'cause Kansas is going bye-bye Sunday, February 24, 13
  • 95. Q4’ Show me all Lucy’s co-actors Sunday, February 24, 13
  • 96. Q4 START lucy=node:Person(name="Lucy Liu") MATCH lucy-[:ACTS_IN]->movie, co_actor-[:ACTS_IN]->movie RETURN DISTINCT co_actor.name Sunday, February 24, 13
  • 97. Q4’ START lucy=node:Person(name="Lucy Liu") MATCH lucy-[:ACTS_IN*2..2]-co_actor RETURN DISTINCT co_actor.name Sunday, February 24, 13
  • 98. Q4’ START lucy=node:Person(name="Lucy Liu") MATCH lucy-[:ACTS_IN*2..2]-co_actor RETURN DISTINCT co_actor.name Sunday, February 24, 13
  • 99. Q6 Bacon Lucy Sunday, February 24, 13
  • 100. 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
  • 101. 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
  • 102. 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
  • 103. 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
  • 104. 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
  • 105. 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
  • 106. 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
  • 107. Create Cypher 2 (the movie) Sunday, February 24, 13
  • 108. 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 cypher2 Sunday, February 24, 13
  • 109. 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 cypher2 Sunday, February 24, 13
  • 110. 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 cypher2 Sunday, February 24, 13
  • 111. 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 cypher2 Sunday, February 24, 13
  • 112. 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 cypher2 Sunday, February 24, 13
  • 113. 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 cypher2 Sunday, February 24, 13
  • 114. Add genre nodes Sunday, February 24, 13
  • 115. Person :DIRECTED :ACTS_IN Movie Genre :GENRE :IS_GENRE Root Sunday, February 24, 13
  • 116. Movie Movie title:"Highlander" title:"The Matrix" genre: "Action" genre: "Action" :GENRE :GENRE Genre name: "Action" :IS_GENRE Root Sunday, February 24, 13
  • 117. START ref=node(0), movie=node:Movie("title:*") WHERE HAS(movie.genre) CREATE UNIQUE ref<-[:IS_GENRE]->(genre {name:movie.genre}) genre-[:GENRE]->movie Sunday, February 24, 13
  • 118. START ref=node(0), movie=node:Movie("title:*") WHERE HAS(movie.genre) CREATE UNIQUE ref<-[:IS_GENRE]->(genre {name:movie.genre}) genre-[:GENRE]->movie Sunday, February 24, 13
  • 119. START ref=node(0), movie=node:Movie("title:*") WHERE HAS(movie.genre) CREATE UNIQUE ref<-[:IS_GENRE]->(genre {name:movie.genre}) genre-[:GENRE]->movie Sunday, February 24, 13
  • 120. START ref=node(0), movie=node:Movie("title:*") WHERE HAS(movie.genre) CREATE UNIQUE ref<-[:IS_GENRE]->(genre {name:movie.genre}) genre-[:GENRE]->movie Sunday, February 24, 13
  • 122. START designates the start points Sunday, February 24, 13
  • 123. MATCH describes the pattern Sunday, February 24, 13
  • 124. WHERE filters the result set Sunday, February 24, 13
  • 125. CREATE creates nodes and relationships Sunday, February 24, 13
  • 126. CREATE UNIQUE creates unique patterns Sunday, February 24, 13
  • 127. RETURN creates the result table Sunday, February 24, 13
  • 128. QUESTION ALL THE THINGS! Sunday, February 24, 13