SlideShare a Scribd company logo
(Neo4j)-[:          ]->Cypher
   Michael Hunger - Neo Technology


                                     1
(Michael) -[:WORKS_ON]-> (Neo4j)
                                         console


Cypher             community
                     graph
                                   Community

                     ME

Server


          Spring               Cloud


                                               2
3
is a


       4
NOSQL       Neo4j




        5
Graph Database




                 6
7
We're talking about a
Property Graph




                        7
We're talking about a
Property Graph


     Nodes




                        7
We're talking about a
Property Graph


     Nodes


      Relationships




                        7
We're talking about a
Property Graph
                                             Em                                       Joh
                                                  il                                      a   n
                                   knows                                     knows
                      Alli                                         Tob                                    Lar

     Nodes
                             son                                       ias           knows                   s
                                                           knows
                                           And                                       And                  knows
                      knows                      rea                                       rés
                                                       s
                                                           knows             knows                knows
                      Pet                                          Miic
                                                                   Mc                knows                 Ian
                         er                knows                        a
                                                                        a
                                   knows                   knows
                                            De                                       Mic
                                               lia                                      h   ael

      Relationships

             Properties (each a key+value)

        + Indexes (for easy look-ups)
                                                                                                                  7
7
8
(Neo4j) -[:IS_A]-> (Graph Database)
                                                                                                    Lucene
Sharding                                      1 M/s

        Master/
                                                                                         Index




                                                      LS
         Slave




                                              TRAVERSA
                          HIG
                                                                    TES
                              H_A
                                 VA                               RA
                                                                 G
                                    IL.                       TE
                                                           IN
                                                                   PROVIDES                        ACID
        Server     RUN
                       S_A                                        LI                                TX
                          S                                         CE
                                                                         NS
                                                                              ED
                                                                                   _L
                                    ES_T
 Ruby                                                                                 IK



                                                           RU
            JS                                                                           E
                                                                                                 MySQL
                      S
                    _A




                                                             NS
                                  SC AL

                                          O

Clojure


                                                             _O
                    NS




           .net
                  RU




                                                               N                             Mongo
                            34bn
     embedded                                                     Heroku
                            Nodes                                                                   9
How do you query this
  graph database?

                   10
With a Graph Query
     Language:
     Cypher


                 11
What is Cypher?
๏Pattern-Matching Query Language
๏Humane language
๏Expressive
๏Declarative: Say what you want, not how
๏borrows from well known query langs
๏Aggregation, Ordering, Limit
๏Update the Graph


                                           12
Something new? Why?
๏ Existing Neo4j query mechanisms were not simple enough
   • Too verbose (Java API)
   • Too prescriptive (Gremlin)
๏ SQL: Unable to express paths
   • these are crucial for graph-based reasoning
   • Neo4j is schema/table free
๏ SPARQL: designed for a different data model
   • namespaces
   • properties as nodes
                                                           13
A Graph
Can‘t see the Patterns for the Trees




               http://maxdemarzi.com/2012/02/13/visualizing-a-network-with-cypher/

                                                                      14
It‘s all about Patterns

                 A



             B       C

We want to find this Pattern!
                               15
Patterns in a Graph




                      16
17
18
19
20
Patterns as ASCII-ART




                   21
Patterns as ASCII-ART



   () --> ()
                   21
Named Nodes

 A      B




              22
Named Nodes

 A      B


(A) --> (B)

              22
Named Directed Rels
        LOVES
    A           B




                    23
Named Directed Rels
        LOVES
    A           B


   A -[:LOVES]-> B


                     23
Paths

A     B     C




                24
Paths

A     B     C


A --> B --> C

                24
Cyclic-Path-Patterns
          A



      B       C




                   25
Cyclic-Path-Patterns
           A



       B       C

A --> B --> C, A --> C

                     25
Cyclic-Path-Patterns
           A



       B       C

A --> B --> C, A --> C
 A --> B --> C <-- A
                     25
Variable Length Paths
        A     B

    A             B

A                      B

        ...
    A -[*]-> B        26
Optional Relationships

     A         B




                    27
Optional Relationships

     A         B

   A -[?]-> B

                    27
28
How does it work?




                    28
How does it work?




                    28
How does it work?
// lookup starting point in an index
start n=node:People(name = ‘Andreas’)




                        And
                              rea
                                    s




                                        28
How does it work?
// lookup starting point in an index
   then traverse to find results
start n=node:People(name = ‘Andreas’)
  match (n)--()--(foaf) return foaf




                        And
                              rea
                                    s




                                        28
28
The Parts of Cypher


                  29
30
Cypher: START + RETURN
๏ START <lookup> RETURN <expressions>
๏ START binds terms using simple look-up
   •directly using known ids
   •or based on indexed Property
๏ RETURN expressions specify result set




                                           30
Cypher: START + RETURN
๏ START <lookup> RETURN <expressions>
๏ START binds terms using simple look-up
   •directly using known ids
   •or based on indexed Property
๏ RETURN expressions specify result set
  // lookup node id 0, return that node
  start n=node(0) return n
  // lookup node in Index, return that node
  start n=node:Person(name="Andreas") return n
  // lookup all nodes, return all name properties
  start n=node(*) return n.name



                                                    30
31
Cypher: MATCH
๏ START <lookup> MATCH <pattern> RETURN <expr>
๏ MATCH describes a pattern of nodes+relationships
   •node terms in optional parenthesis
   •lines with arrows for relationships




                                                 31
Cypher: MATCH
๏ START <lookup> MATCH <pattern> RETURN <expr>
๏ MATCH describes a pattern of nodes+relationships
   •node terms in optional parenthesis
   •lines with arrows for relationships
 // lookup 'n', traverse any relationship to some 'm'
 start n=node(0) match (n)--(m) return n,m
 // any outgoing relationship from 'n' to 'm'
 start n=node(0) match n-->m return n,m
 // only 'KNOWS' relationships from 'n' to 'm'
 start n=node(0) match n-[:KNOWS]->m return n,m
 // from 'n' to 'm' and capture the relationship as 'r'
 start n=node(0) match n-[r]->m return n,r,m
 // from 'n' outgoing to 'm', then incoming from 'o'
 start n=node(0) match n-->m<--o return n,m,o
                                                          31
32
Cypher: RETURN
๏ RETURN <expressions>, aggregation(expr) as alias
๏ RETURN nodes, rels, properties
๏ RETURN expressions of functions and operators
๏ RETURN aggregation functions on the above




                                                  32
Cypher: RETURN
๏ RETURN <expressions>, aggregation(expr) as alias
๏ RETURN nodes, rels, properties
๏ RETURN expressions of functions and operators
๏ RETURN aggregation functions on the above


  // aggregate on n, count the m‘s
  start n=node(0) match n--m return n,count(*)
  // alias n.name as name
  start n=node(0) return n.name as name
  // aggregate m‘s into list
  start n=node(*) match n--m return n,collect(m)
  // filter m‘s by name
  start n=node(*) match n--m return n,filter(x in collect(m):
    m.name ˜= /A.*/) as a_block
                                                        32
33
Cypher: WHERE
๏ START <lookup> [MATCH <pattern>]
 WHERE <condition> RETURN <expr>
๏ WHERE filters nodes or relationships
   •uses expressions to constrain elements




                                             33
Cypher: WHERE
๏ START <lookup> [MATCH <pattern>]
 WHERE <condition> RETURN <expr>
๏ WHERE filters nodes or relationships
   •uses expressions to constrain elements
  // lookup all nodes as 'n', constrained to name 'Andreas'
  start n=node(*) where n.name='Andreas' return n
  // filter nodes where age is less than 30
  start n=node(*) where n.age<30 return n
  // filter using a regular expression
  start n=node(*) where n.name =~ /Tob.*/ return n
  // filter for a property exists
  start n=node(*) where has(n.name) return n



                                                        33
34
Cypher: CREATE
๏ CREATE <node>[,node or relationship] RETURN <expr>
  •create nodes with optional properties
  •create relationship (must have a type)




                                               34
Cypher: CREATE
๏ CREATE <node>[,node or relationship] RETURN <expr>
  •create nodes with optional properties
  •create relationship (must have a type)

 // create an anonymous node
 create n
 // create node with a property, returning it
 create n={name:'Andreas'} return n
 // lookup 2 nodes, then create a relationship and return it
 start n=node(0),m=node(1) create n-[r:KNOWS]-m return r
 // lookup nodes, then create a relationship with properties
 start n=node(1),m=node(2) create n-[r:KNOWS {since:2008}]->m



                                                       34
35
Cypher: CREATE UNIQUE
๏ CREATE UNIQUE node-[rel]->(node {prop : value})
   •„fixes“ the graph
   •starts at bound nodes, properties rels and nodes by
     comparing types and
                           tries to find


   •if not found creates them




                                                    35
Cypher: CREATE UNIQUE
๏ CREATE UNIQUE node-[rel]->(node {prop : value})
   •„fixes“ the graph
   •starts at bound nodes, properties rels and nodes by
     comparing types and
                           tries to find


   •if not found creates them
 // create a new relationship
 start n=.., m=.. create unique n-[:KNOWS]->m
 // create a new node AND relationship
 start n=... create unique n-[:TAGGED]->(tag {name:“neo“})
 // matches the tag node by name only creates new relationship
 start n=... create unique n-[:TAGGED]->(tag {name:“neo“})



                                                       35
36
Cypher: SET
๏ SET [<node property>] [<relationship property>]
   •update a property on a node or relationship
   •must follow a START




                                                    36
Cypher: SET
๏ SET [<node property>] [<relationship property>]
   •update a property on a node or relationship
   •must follow a START

  // update the name property
  start n=node(0) set n.name='Peter'
  // update many nodes, using a calculation
  start n=node(*) set n.size=n.size+1
  // match & capture a relationship, update a property
  start n=node(1) match n-[r]-m set r.times=10




                                                         36
37
Cypher: DELETE
๏ DELETE [<node>|<relationship>|<property>]
  •delete a node, relationship or property
  •toall relationships must be deleted first
      delete a node,




                                              37
Cypher: DELETE
๏ DELETE [<node>|<relationship>|<property>]
  •delete a node, relationship or property
  •toall relationships must be deleted first
      delete a node,



 // delete a node
 start n=node(5) delete n
 // remove a node and all relationships
 start n=node(3) match n-[r]-() delete n, r
 // remove a property
 start n=node(3) delete n.age




                                              37
More Advanced
  Examples

                38
START user = node(1)
                                           MATCH user -[user_skill]-> skill
                                           RETURN skill, user_skill
SELECT skills.*, user_skill.*
FROM users
JOIN user_skill ON users.id = user_skill.user_id
JOIN skills ON user_skill.skill_id = skill.id WHERE users.id = 1


                                                                   39
Example:
               Old, Influential Friends
START me = node(...)
MATCH (me) - [f:FRIEND] - (old_friend)
           - [:FRIEND ] - (fof)
WHERE ({today}-f.begin) > 365*10

WITH  old_friend, collect(fof.name) as names

WHERE    length(names) > 100
RETURN   old_friend, names
ORDER BY old_friend.name ASC
          f:FRIEND            :FRIEND
     me              friend             fof
Example:
                     Simple Recommendation
START me = node(...)
MATCH (me) -[r1:RATED   ]->(thing)
          <-[r2:RATED   ]- (someone)
           -[r3:RATED   ]->(cool_thing)
WHERE ABS(r1.stars-r2.stars) <= 2
       AND r3.stars > 3
RETURN cool_thing, count(*) AS cnt
ORDER BY cnt DESC LIMIT 10
          r1:RATED     thing   r2:RATED
     me                                       so
                                        TED
                               r   3: RA
                       cool
                       thing                   41
Cypher Cheat Sheet
             http://neo4j.org/resources/cypher




                                       42
The Rabbithole




                  http://console.neo4j.org
                 This Graph: http://tinyurl.com/7cnvmlq
                                             43
How to use Cypher
in YOUR programs

                44
Neo4j API
 ExecutionEngine engine = new ExecutionEngine(graphDB);


 String query = „start n=node:Person(name={name})
  match n-[:ACTS_IN]->movie<-[:ACTS_IN]-friend
  return friend“;
 ExecutionResult result = engine.query(query, map(„name“, „Keanu“);


 for (Map<String,Object> row : result) {
     Node friend = row.get(„friend“);
 }


 Iterator<Node> friends = result.columnAs(„friend“);




http://bit.ly/cypher-queries


                                                                  45
How to get started?




                      46
How to get started?
๏ Documentation




                      46
How to get started?
๏ Documentation
    • docs.neo4j.org - tutorials+reference




                                             46
How to get started?
๏ Documentation
    • docs.neo4j.org - tutorials+reference
    • http://console.neo4j.org




                                             46
How to get started?
๏ Documentation
    • docs.neo4j.org - tutorials+reference
    • http://console.neo4j.org
    • Neo4j in Action




                                             46
How to get started?
๏ Documentation
    • docs.neo4j.org - tutorials+reference
    • http://console.neo4j.org
    • Neo4j in Action
    • Good Relationships




                                             46
How to get started?
๏ Documentation
    • docs.neo4j.org - tutorials+reference
    • http://console.neo4j.org
    • Neo4j in Action
    • Good Relationships
๏ Get Neo4j




                                             46
How to get started?
๏ Documentation
    • docs.neo4j.org - tutorials+reference
    • http://console.neo4j.org
    • Neo4j in Action
    • Good Relationships
๏ Get Neo4j
    • http://neo4j.org/download




                                             46
How to get started?
๏ Documentation
    • docs.neo4j.org - tutorials+reference
    • http://console.neo4j.org
    • Neo4j in Action
    • Good Relationships
๏ Get Neo4j
    • http://neo4j.org/download
    • http://addons.heroku.com/neo4j/
๏ Participate
    • http://groups.google.com/group/neo4j
    • http://neo4j.meetup.com
                                             46
How to get started?
๏ Documentation
    • docs.neo4j.org - tutorials+reference
    • http://console.neo4j.org
    • Neo4j in Action
    • Good Relationships
๏ Get Neo4j
    • http://neo4j.org/download
    • http://addons.heroku.com/neo4j/
๏ Participate
    • http://groups.google.com/group/neo4j
    • http://neo4j.meetup.com
    • a session like this one ;)
                                             46
http://console.neo4j.org/r/GoT
https://dl.dropbox.com/u/14493611/got.txt
                                        47
Neo4j-JDBC Driver & MovieDB Dataset




http://blog.neo4j.org/2012/06/wanted-your-
       help-in-testing-neo4j-jdbc.html
                                             48
Got a Conference? Need a Dataset?




http://blog.neo4j.org/2012/08/at-conference-
          need-dataset-neo4j-at.html
                                           49
Neo4j in Action
Software Metrics


                   50
Graphs in Software Technolgoy
๏ UML Diagrams are graphs
๏ dependencies between classes, packages, modules etc are graphs
๏ Software Metrics use dependency analysis
๏ Visualizations
๏ Cyclomatic Complexity,
๏ Fan-in (afferent-coupling) / Fan-out (efferent coupling) etc.




                                                            51
Code City




            52
Class Diagram is a Graph




                           53
SonarJ




         54
But there is more
๏Visualize & query Method, Field
   dependencies
๏Collaborative filtering (co-usage)
๏Ranking
๏God classes
๏Paths between classes

                                     55
Welcome to Class-Graph
๏take a JAR
๏put it under ASM
๏scan it superfast
๏pull everything into Neo4j
๏add categories, indexes
๏Have Fun

     http://github.com/jexp/class-graph   56
Welcome to Class-Graph




                         57
Interactive Hands-On Session
๏Lots of tasks
๏use Cypher to solve them
   http://neo4j.org/resources/cypher
๏be creative, work together
๏ask !
๏Server http://bit.ly/innoq-neo4j
๏just the beginning
                                       58
Task: Find java.lang.Number and return it




                                            59
Task: Find java.lang.Number and return it


START o=node:types(name="java.lang.Number") 
RETURN o;




                                             59
Task: Subclasses of Number?




•Return just the name
•Order them alphabetically

                              60
Task: Subclasses of Number?


START n=node:types(name="java.lang.Number") 
 MATCH n<-[:SUPER_TYPE]-s
 RETURN s.name
 ORDER BY s.name;



•Return just the name
•Order them alphabetically

                                       60
Task: Which Methods does it have / how many




•Find the top 5 classes with the most members


                                                61
Task: Which Methods does it have / how many


START n=node:types(name="java.lang.Number") 
MATCH n-[:METHOD_OF|FIELD_OF]->m
RETURN m;




•Find the top 5 classes with the most members


                                                61
Task: Calculate the fan-out of
java.lang.StringBuilder




•Calculate fan-in
•Which class has the highest fan-out
•What about package-level?             62
Task: Calculate the fan-out of
 java.lang.StringBuilder
START o=node:types(name="j.l.StringBuilder")
MATCH o-[:FIELD_OF]->f-[:FIELD_TYPE]->tf,
      o-[:METHOD_OF]->m-[:PARAM_TYPE]->tp,
      m-[:RETURN_TYPE]->tr
RETURN o,count(distinct tf)
       + count(distinct tp)
       + count(distinct tr) as fan_out;

•Calculate fan-in
•Which class has the highest fan-out
•What about package-level?             62
Task: Find longest Inheritance Path




                                      63
Task: Find longest Inheritance Path


start c=node:types(name="java.lang.Object") 
match path=p<-[:SUPER_TYPE*]-c 
return extract(n in nodes(path) : n.name),
length(path) as len
order by len desc 
limit 5;




                                       63
Task: Find the class that used IOException
most often




                                             64
Task: Find the class that used IOException
most often

START ex=node:types(name="java.io.IOException"
MATCH ex<-[:THROWS]-m<-[:METHOD_OF]-c
RETURN c, count(*)
ORDER BY count(*)
LIMIT 5;




                                             64
Task: Which other classes did classes that
 threw IOException use most often?




•What could be a source of IOExceptions
                                              65
Task: Which other classes did classes that
 threw IOException use most often?
START ex=node:types(name="java.io.IOException")
MATCH ex<-[:THROWS]-m<-[:METHOD_OF]-c,
      mbr<-[:METHOD_OF|FIELD_OF]-c,
      mbr-[:FIELD_TYPE|PARAM_TYPE|
            RETURN_TYPE|THROWS]->other_type
WHERE other_type.name =~ /.+[.].+/
RETURN other_type.name, count(*)
ORDER BY count(*) desc
LIMIT 10;
•What could be a source of IOExceptions
                                              65
Task: Find a class you like and add a field with
your name and some type




                                            66
Task: Find a class you like and add a field with
 your name and some type
START c=node:types(name="void"),
 t=node:types(name="java.lang.reflect.Proxy") 
CREATE c-[:FIELD_OF]->(field {name:“Michael“})
       -[:FIELD_TYPE]->t;




                                             66
Task: Delete the most annoying class and all its
methods, fields and their relationships




                                           67
Task: Delete the most annoying class and all its
 methods, fields and their relationships
START c=node:types(name="java.awt.List"),
MATCH c-[r1:FIELD_OF|METHOD_OF]->mbr-[r2]-()
      c-[r]-()
DELETE c,mbr,r1,r2,r;




                                            67

More Related Content

Viewers also liked

Introduction to graph databases, Neo4j and Spring Data - English 2015 Edition
Introduction to graph databases, Neo4j and Spring Data - English 2015 EditionIntroduction to graph databases, Neo4j and Spring Data - English 2015 Edition
Introduction to graph databases, Neo4j and Spring Data - English 2015 Edition
Aleksander Stensby
 
Understanding Graph Databases with Neo4j and Cypher
Understanding Graph Databases with Neo4j and CypherUnderstanding Graph Databases with Neo4j and Cypher
Understanding Graph Databases with Neo4j and Cypher
Ruhaim Izmeth
 
Optimizing Cypher Queries in Neo4j
Optimizing Cypher Queries in Neo4jOptimizing Cypher Queries in Neo4j
Optimizing Cypher Queries in Neo4j
Neo4j
 
Graphdatenbanken mit Neo4j
Graphdatenbanken mit Neo4jGraphdatenbanken mit Neo4j
Graphdatenbanken mit Neo4j
Java Usergroup Berlin-Brandenburg
 
Building a Graph-based Analytics Platform
Building a Graph-based Analytics PlatformBuilding a Graph-based Analytics Platform
Building a Graph-based Analytics Platform
Kenny Bastani
 
Neo4j Use Cases - Graphdatenbanken im Einsatz
Neo4j Use Cases - Graphdatenbanken im EinsatzNeo4j Use Cases - Graphdatenbanken im Einsatz
Neo4j Use Cases - Graphdatenbanken im Einsatz
Neo4j
 
Introduction to Neo4j and .Net
Introduction to Neo4j and .NetIntroduction to Neo4j and .Net
Introduction to Neo4j and .Net
Neo4j
 
Caesar cipher
Caesar cipherCaesar cipher
Caesar cipher
Ramadhi Irawan
 
Building Cloud Native Architectures with Spring
Building Cloud Native Architectures with SpringBuilding Cloud Native Architectures with Spring
Building Cloud Native Architectures with Spring
Kenny Bastani
 
Big Graph Analytics on Neo4j with Apache Spark
Big Graph Analytics on Neo4j with Apache SparkBig Graph Analytics on Neo4j with Apache Spark
Big Graph Analytics on Neo4j with Apache Spark
Kenny Bastani
 
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH)
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH) Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH)
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH)
David Fombella Pombal
 
Webinar: Stop Complex Fraud in its Tracks with Neo4j
Webinar: Stop Complex Fraud in its Tracks with Neo4jWebinar: Stop Complex Fraud in its Tracks with Neo4j
Webinar: Stop Complex Fraud in its Tracks with Neo4j
Neo4j
 
Neo4j Partner Tag Berlin - Investigating the Panama Papers connections with n...
Neo4j Partner Tag Berlin - Investigating the Panama Papers connections with n...Neo4j Partner Tag Berlin - Investigating the Panama Papers connections with n...
Neo4j Partner Tag Berlin - Investigating the Panama Papers connections with n...
Neo4j
 
Neo4j Partner Tag Berlin - Potential für System-Integratoren und Berater
Neo4j Partner Tag Berlin - Potential für System-Integratoren und Berater Neo4j Partner Tag Berlin - Potential für System-Integratoren und Berater
Neo4j Partner Tag Berlin - Potential für System-Integratoren und Berater
Neo4j
 
Webinar: RDBMS to Graphs
Webinar: RDBMS to GraphsWebinar: RDBMS to Graphs
Webinar: RDBMS to Graphs
Neo4j
 
OrientDB vs Neo4j - Comparison of query/speed/functionality
OrientDB vs Neo4j - Comparison of query/speed/functionalityOrientDB vs Neo4j - Comparison of query/speed/functionality
OrientDB vs Neo4j - Comparison of query/speed/functionality
Curtis Mosters
 

Viewers also liked (16)

Introduction to graph databases, Neo4j and Spring Data - English 2015 Edition
Introduction to graph databases, Neo4j and Spring Data - English 2015 EditionIntroduction to graph databases, Neo4j and Spring Data - English 2015 Edition
Introduction to graph databases, Neo4j and Spring Data - English 2015 Edition
 
Understanding Graph Databases with Neo4j and Cypher
Understanding Graph Databases with Neo4j and CypherUnderstanding Graph Databases with Neo4j and Cypher
Understanding Graph Databases with Neo4j and Cypher
 
Optimizing Cypher Queries in Neo4j
Optimizing Cypher Queries in Neo4jOptimizing Cypher Queries in Neo4j
Optimizing Cypher Queries in Neo4j
 
Graphdatenbanken mit Neo4j
Graphdatenbanken mit Neo4jGraphdatenbanken mit Neo4j
Graphdatenbanken mit Neo4j
 
Building a Graph-based Analytics Platform
Building a Graph-based Analytics PlatformBuilding a Graph-based Analytics Platform
Building a Graph-based Analytics Platform
 
Neo4j Use Cases - Graphdatenbanken im Einsatz
Neo4j Use Cases - Graphdatenbanken im EinsatzNeo4j Use Cases - Graphdatenbanken im Einsatz
Neo4j Use Cases - Graphdatenbanken im Einsatz
 
Introduction to Neo4j and .Net
Introduction to Neo4j and .NetIntroduction to Neo4j and .Net
Introduction to Neo4j and .Net
 
Caesar cipher
Caesar cipherCaesar cipher
Caesar cipher
 
Building Cloud Native Architectures with Spring
Building Cloud Native Architectures with SpringBuilding Cloud Native Architectures with Spring
Building Cloud Native Architectures with Spring
 
Big Graph Analytics on Neo4j with Apache Spark
Big Graph Analytics on Neo4j with Apache SparkBig Graph Analytics on Neo4j with Apache Spark
Big Graph Analytics on Neo4j with Apache Spark
 
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH)
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH) Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH)
Neo4j Introduction (Basics, Cypher, RDBMS to GRAPH)
 
Webinar: Stop Complex Fraud in its Tracks with Neo4j
Webinar: Stop Complex Fraud in its Tracks with Neo4jWebinar: Stop Complex Fraud in its Tracks with Neo4j
Webinar: Stop Complex Fraud in its Tracks with Neo4j
 
Neo4j Partner Tag Berlin - Investigating the Panama Papers connections with n...
Neo4j Partner Tag Berlin - Investigating the Panama Papers connections with n...Neo4j Partner Tag Berlin - Investigating the Panama Papers connections with n...
Neo4j Partner Tag Berlin - Investigating the Panama Papers connections with n...
 
Neo4j Partner Tag Berlin - Potential für System-Integratoren und Berater
Neo4j Partner Tag Berlin - Potential für System-Integratoren und Berater Neo4j Partner Tag Berlin - Potential für System-Integratoren und Berater
Neo4j Partner Tag Berlin - Potential für System-Integratoren und Berater
 
Webinar: RDBMS to Graphs
Webinar: RDBMS to GraphsWebinar: RDBMS to Graphs
Webinar: RDBMS to Graphs
 
OrientDB vs Neo4j - Comparison of query/speed/functionality
OrientDB vs Neo4j - Comparison of query/speed/functionalityOrientDB vs Neo4j - Comparison of query/speed/functionality
OrientDB vs Neo4j - Comparison of query/speed/functionality
 

More from jexp

Looming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfLooming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdf
jexp
 
Easing the daily grind with the awesome JDK command line tools
Easing the daily grind with the awesome JDK command line toolsEasing the daily grind with the awesome JDK command line tools
Easing the daily grind with the awesome JDK command line tools
jexp
 
Looming Marvelous - Virtual Threads in Java
Looming Marvelous - Virtual Threads in JavaLooming Marvelous - Virtual Threads in Java
Looming Marvelous - Virtual Threads in Java
jexp
 
GraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptx
GraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptxGraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptx
GraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptx
jexp
 
Neo4j Connector Apache Spark FiNCENFiles
Neo4j Connector Apache Spark FiNCENFilesNeo4j Connector Apache Spark FiNCENFiles
Neo4j Connector Apache Spark FiNCENFiles
jexp
 
How Graphs Help Investigative Journalists to Connect the Dots
How Graphs Help Investigative Journalists to Connect the DotsHow Graphs Help Investigative Journalists to Connect the Dots
How Graphs Help Investigative Journalists to Connect the Dots
jexp
 
The Home Office. Does it really work?
The Home Office. Does it really work?The Home Office. Does it really work?
The Home Office. Does it really work?
jexp
 
Polyglot Applications with GraalVM
Polyglot Applications with GraalVMPolyglot Applications with GraalVM
Polyglot Applications with GraalVM
jexp
 
Neo4j Graph Streaming Services with Apache Kafka
Neo4j Graph Streaming Services with Apache KafkaNeo4j Graph Streaming Services with Apache Kafka
Neo4j Graph Streaming Services with Apache Kafka
jexp
 
How Graph Databases efficiently store, manage and query connected data at s...
How Graph Databases efficiently  store, manage and query  connected data at s...How Graph Databases efficiently  store, manage and query  connected data at s...
How Graph Databases efficiently store, manage and query connected data at s...
jexp
 
APOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures Library
APOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures LibraryAPOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures Library
APOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures Library
jexp
 
Refactoring, 2nd Edition
Refactoring, 2nd EditionRefactoring, 2nd Edition
Refactoring, 2nd Edition
jexp
 
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...
jexp
 
GraphQL - The new "Lingua Franca" for API-Development
GraphQL - The new "Lingua Franca" for API-DevelopmentGraphQL - The new "Lingua Franca" for API-Development
GraphQL - The new "Lingua Franca" for API-Development
jexp
 
A whirlwind tour of graph databases
A whirlwind tour of graph databasesA whirlwind tour of graph databases
A whirlwind tour of graph databases
jexp
 
Practical Graph Algorithms with Neo4j
Practical Graph Algorithms with Neo4jPractical Graph Algorithms with Neo4j
Practical Graph Algorithms with Neo4j
jexp
 
A Game of Data and GraphQL
A Game of Data and GraphQLA Game of Data and GraphQL
A Game of Data and GraphQL
jexp
 
Querying Graphs with GraphQL
Querying Graphs with GraphQLQuerying Graphs with GraphQL
Querying Graphs with GraphQL
jexp
 
Graphs & Neo4j - Past Present Future
Graphs & Neo4j - Past Present FutureGraphs & Neo4j - Past Present Future
Graphs & Neo4j - Past Present Future
jexp
 
Intro to Graphs and Neo4j
Intro to Graphs and Neo4jIntro to Graphs and Neo4j
Intro to Graphs and Neo4j
jexp
 

More from jexp (20)

Looming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdfLooming Marvelous - Virtual Threads in Java Javaland.pdf
Looming Marvelous - Virtual Threads in Java Javaland.pdf
 
Easing the daily grind with the awesome JDK command line tools
Easing the daily grind with the awesome JDK command line toolsEasing the daily grind with the awesome JDK command line tools
Easing the daily grind with the awesome JDK command line tools
 
Looming Marvelous - Virtual Threads in Java
Looming Marvelous - Virtual Threads in JavaLooming Marvelous - Virtual Threads in Java
Looming Marvelous - Virtual Threads in Java
 
GraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptx
GraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptxGraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptx
GraphConnect 2022 - Top 10 Cypher Tuning Tips & Tricks.pptx
 
Neo4j Connector Apache Spark FiNCENFiles
Neo4j Connector Apache Spark FiNCENFilesNeo4j Connector Apache Spark FiNCENFiles
Neo4j Connector Apache Spark FiNCENFiles
 
How Graphs Help Investigative Journalists to Connect the Dots
How Graphs Help Investigative Journalists to Connect the DotsHow Graphs Help Investigative Journalists to Connect the Dots
How Graphs Help Investigative Journalists to Connect the Dots
 
The Home Office. Does it really work?
The Home Office. Does it really work?The Home Office. Does it really work?
The Home Office. Does it really work?
 
Polyglot Applications with GraalVM
Polyglot Applications with GraalVMPolyglot Applications with GraalVM
Polyglot Applications with GraalVM
 
Neo4j Graph Streaming Services with Apache Kafka
Neo4j Graph Streaming Services with Apache KafkaNeo4j Graph Streaming Services with Apache Kafka
Neo4j Graph Streaming Services with Apache Kafka
 
How Graph Databases efficiently store, manage and query connected data at s...
How Graph Databases efficiently  store, manage and query  connected data at s...How Graph Databases efficiently  store, manage and query  connected data at s...
How Graph Databases efficiently store, manage and query connected data at s...
 
APOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures Library
APOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures LibraryAPOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures Library
APOC Pearls - Whirlwind Tour Through the Neo4j APOC Procedures Library
 
Refactoring, 2nd Edition
Refactoring, 2nd EditionRefactoring, 2nd Edition
Refactoring, 2nd Edition
 
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...
New Features in Neo4j 3.4 / 3.3 - Graph Algorithms, Spatial, Date-Time & Visu...
 
GraphQL - The new "Lingua Franca" for API-Development
GraphQL - The new "Lingua Franca" for API-DevelopmentGraphQL - The new "Lingua Franca" for API-Development
GraphQL - The new "Lingua Franca" for API-Development
 
A whirlwind tour of graph databases
A whirlwind tour of graph databasesA whirlwind tour of graph databases
A whirlwind tour of graph databases
 
Practical Graph Algorithms with Neo4j
Practical Graph Algorithms with Neo4jPractical Graph Algorithms with Neo4j
Practical Graph Algorithms with Neo4j
 
A Game of Data and GraphQL
A Game of Data and GraphQLA Game of Data and GraphQL
A Game of Data and GraphQL
 
Querying Graphs with GraphQL
Querying Graphs with GraphQLQuerying Graphs with GraphQL
Querying Graphs with GraphQL
 
Graphs & Neo4j - Past Present Future
Graphs & Neo4j - Past Present FutureGraphs & Neo4j - Past Present Future
Graphs & Neo4j - Past Present Future
 
Intro to Graphs and Neo4j
Intro to Graphs and Neo4jIntro to Graphs and Neo4j
Intro to Graphs and Neo4j
 

Recently uploaded

Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptxUse Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
SynapseIndia
 
How to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptxHow to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptx
Adam Dunkels
 
(CISOPlatform Summit & SACON 2024) Gen AI & Deepfake In Overall Security.pdf
(CISOPlatform Summit & SACON 2024) Gen AI & Deepfake In Overall Security.pdf(CISOPlatform Summit & SACON 2024) Gen AI & Deepfake In Overall Security.pdf
(CISOPlatform Summit & SACON 2024) Gen AI & Deepfake In Overall Security.pdf
Priyanka Aash
 
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
Priyanka Aash
 
Acumatica vs. Sage Intacct _Construction_July (1).pptx
Acumatica vs. Sage Intacct _Construction_July (1).pptxAcumatica vs. Sage Intacct _Construction_July (1).pptx
Acumatica vs. Sage Intacct _Construction_July (1).pptx
BrainSell Technologies
 
WhatsApp Spy Online Trackers and Monitoring Apps
WhatsApp Spy Online Trackers and Monitoring AppsWhatsApp Spy Online Trackers and Monitoring Apps
WhatsApp Spy Online Trackers and Monitoring Apps
HackersList
 
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
Priyanka Aash
 
Evolution of iPaaS - simplify IT workloads to provide a unified view of data...
Evolution of iPaaS - simplify IT workloads to provide a unified view of  data...Evolution of iPaaS - simplify IT workloads to provide a unified view of  data...
Evolution of iPaaS - simplify IT workloads to provide a unified view of data...
Torry Harris
 
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
sunilverma7884
 
Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024
aakash malhotra
 
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
shanihomely
 
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptxDublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
Kunal Gupta
 
The importance of Quality Assurance for ICT Standardization
The importance of Quality Assurance for ICT StandardizationThe importance of Quality Assurance for ICT Standardization
The importance of Quality Assurance for ICT Standardization
Axel Rennoch
 
Sonkoloniya documentation - ONEprojukti.pdf
Sonkoloniya documentation - ONEprojukti.pdfSonkoloniya documentation - ONEprojukti.pdf
Sonkoloniya documentation - ONEprojukti.pdf
SubhamMandal40
 
Vulnerability Management: A Comprehensive Overview
Vulnerability Management: A Comprehensive OverviewVulnerability Management: A Comprehensive Overview
Vulnerability Management: A Comprehensive Overview
Steven Carlson
 
Computer HARDWARE presenattion by CWD students class 10
Computer HARDWARE presenattion by CWD students class 10Computer HARDWARE presenattion by CWD students class 10
Computer HARDWARE presenattion by CWD students class 10
ankush9927
 
Using LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and MilvusUsing LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and Milvus
Zilliz
 
Opencast Summit 2024 — Opencast @ University of Münster
Opencast Summit 2024 — Opencast @ University of MünsterOpencast Summit 2024 — Opencast @ University of Münster
Opencast Summit 2024 — Opencast @ University of Münster
Matthias Neugebauer
 
What's new in android: jetpack compose 2024
What's new in android: jetpack compose 2024What's new in android: jetpack compose 2024
What's new in android: jetpack compose 2024
Toru Wonyoung Choi
 
Google I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged SlidesGoogle I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged Slides
Google Developer Group - Harare
 

Recently uploaded (20)

Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptxUse Cases & Benefits of RPA in Manufacturing in 2024.pptx
Use Cases & Benefits of RPA in Manufacturing in 2024.pptx
 
How to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptxHow to Build a Profitable IoT Product.pptx
How to Build a Profitable IoT Product.pptx
 
(CISOPlatform Summit & SACON 2024) Gen AI & Deepfake In Overall Security.pdf
(CISOPlatform Summit & SACON 2024) Gen AI & Deepfake In Overall Security.pdf(CISOPlatform Summit & SACON 2024) Gen AI & Deepfake In Overall Security.pdf
(CISOPlatform Summit & SACON 2024) Gen AI & Deepfake In Overall Security.pdf
 
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
(CISOPlatform Summit & SACON 2024) Keynote _ Power Digital Identities With AI...
 
Acumatica vs. Sage Intacct _Construction_July (1).pptx
Acumatica vs. Sage Intacct _Construction_July (1).pptxAcumatica vs. Sage Intacct _Construction_July (1).pptx
Acumatica vs. Sage Intacct _Construction_July (1).pptx
 
WhatsApp Spy Online Trackers and Monitoring Apps
WhatsApp Spy Online Trackers and Monitoring AppsWhatsApp Spy Online Trackers and Monitoring Apps
WhatsApp Spy Online Trackers and Monitoring Apps
 
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
(CISOPlatform Summit & SACON 2024) Digital Personal Data Protection Act.pdf
 
Evolution of iPaaS - simplify IT workloads to provide a unified view of data...
Evolution of iPaaS - simplify IT workloads to provide a unified view of  data...Evolution of iPaaS - simplify IT workloads to provide a unified view of  data...
Evolution of iPaaS - simplify IT workloads to provide a unified view of data...
 
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
Girls call Kolkata 👀 XXXXXXXXXXX 👀 Rs.9.5 K Cash Payment With Room Delivery
 
Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024Three New Criminal Laws in India 1 July 2024
Three New Criminal Laws in India 1 July 2024
 
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
Premium Girls Call Mumbai 9920725232 Unlimited Short Providing Girls Service ...
 
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptxDublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
Dublin_mulesoft_meetup_Mulesoft_Salesforce_Integration (1).pptx
 
The importance of Quality Assurance for ICT Standardization
The importance of Quality Assurance for ICT StandardizationThe importance of Quality Assurance for ICT Standardization
The importance of Quality Assurance for ICT Standardization
 
Sonkoloniya documentation - ONEprojukti.pdf
Sonkoloniya documentation - ONEprojukti.pdfSonkoloniya documentation - ONEprojukti.pdf
Sonkoloniya documentation - ONEprojukti.pdf
 
Vulnerability Management: A Comprehensive Overview
Vulnerability Management: A Comprehensive OverviewVulnerability Management: A Comprehensive Overview
Vulnerability Management: A Comprehensive Overview
 
Computer HARDWARE presenattion by CWD students class 10
Computer HARDWARE presenattion by CWD students class 10Computer HARDWARE presenattion by CWD students class 10
Computer HARDWARE presenattion by CWD students class 10
 
Using LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and MilvusUsing LLM Agents with Llama 3, LangGraph and Milvus
Using LLM Agents with Llama 3, LangGraph and Milvus
 
Opencast Summit 2024 — Opencast @ University of Münster
Opencast Summit 2024 — Opencast @ University of MünsterOpencast Summit 2024 — Opencast @ University of Münster
Opencast Summit 2024 — Opencast @ University of Münster
 
What's new in android: jetpack compose 2024
What's new in android: jetpack compose 2024What's new in android: jetpack compose 2024
What's new in android: jetpack compose 2024
 
Google I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged SlidesGoogle I/O Extended Harare Merged Slides
Google I/O Extended Harare Merged Slides
 

Intro to Cypher

  • 1. (Neo4j)-[: ]->Cypher Michael Hunger - Neo Technology 1
  • 2. (Michael) -[:WORKS_ON]-> (Neo4j) console Cypher community graph Community ME Server Spring Cloud 2
  • 3. 3
  • 4. is a 4
  • 5. NOSQL Neo4j 5
  • 7. 7
  • 8. We're talking about a Property Graph 7
  • 9. We're talking about a Property Graph Nodes 7
  • 10. We're talking about a Property Graph Nodes Relationships 7
  • 11. We're talking about a Property Graph Em Joh il a n knows knows Alli Tob Lar Nodes son ias knows s knows And And knows knows rea rés s knows knows knows Pet Miic Mc knows Ian er knows a a knows knows De Mic lia h ael Relationships Properties (each a key+value) + Indexes (for easy look-ups) 7
  • 12. 7
  • 13. 8
  • 14. (Neo4j) -[:IS_A]-> (Graph Database) Lucene Sharding 1 M/s Master/ Index LS Slave TRAVERSA HIG TES H_A VA RA G IL. TE IN PROVIDES ACID Server RUN S_A LI TX S CE NS ED _L ES_T Ruby IK RU JS E MySQL S _A NS SC AL O Clojure _O NS .net RU N Mongo 34bn embedded Heroku Nodes 9
  • 15. How do you query this graph database? 10
  • 16. With a Graph Query Language: Cypher 11
  • 17. What is Cypher? ๏Pattern-Matching Query Language ๏Humane language ๏Expressive ๏Declarative: Say what you want, not how ๏borrows from well known query langs ๏Aggregation, Ordering, Limit ๏Update the Graph 12
  • 18. Something new? Why? ๏ Existing Neo4j query mechanisms were not simple enough • Too verbose (Java API) • Too prescriptive (Gremlin) ๏ SQL: Unable to express paths • these are crucial for graph-based reasoning • Neo4j is schema/table free ๏ SPARQL: designed for a different data model • namespaces • properties as nodes 13
  • 19. A Graph Can‘t see the Patterns for the Trees http://maxdemarzi.com/2012/02/13/visualizing-a-network-with-cypher/ 14
  • 20. It‘s all about Patterns A B C We want to find this Pattern! 15
  • 21. Patterns in a Graph 16
  • 22. 17
  • 23. 18
  • 24. 19
  • 25. 20
  • 27. Patterns as ASCII-ART () --> () 21
  • 29. Named Nodes A B (A) --> (B) 22
  • 30. Named Directed Rels LOVES A B 23
  • 31. Named Directed Rels LOVES A B A -[:LOVES]-> B 23
  • 32. Paths A B C 24
  • 33. Paths A B C A --> B --> C 24
  • 35. Cyclic-Path-Patterns A B C A --> B --> C, A --> C 25
  • 36. Cyclic-Path-Patterns A B C A --> B --> C, A --> C A --> B --> C <-- A 25
  • 37. Variable Length Paths A B A B A B ... A -[*]-> B 26
  • 39. Optional Relationships A B A -[?]-> B 27
  • 40. 28
  • 41. How does it work? 28
  • 42. How does it work? 28
  • 43. How does it work? // lookup starting point in an index start n=node:People(name = ‘Andreas’) And rea s 28
  • 44. How does it work? // lookup starting point in an index then traverse to find results start n=node:People(name = ‘Andreas’) match (n)--()--(foaf) return foaf And rea s 28
  • 45. 28
  • 46. The Parts of Cypher 29
  • 47. 30
  • 48. Cypher: START + RETURN ๏ START <lookup> RETURN <expressions> ๏ START binds terms using simple look-up •directly using known ids •or based on indexed Property ๏ RETURN expressions specify result set 30
  • 49. Cypher: START + RETURN ๏ START <lookup> RETURN <expressions> ๏ START binds terms using simple look-up •directly using known ids •or based on indexed Property ๏ RETURN expressions specify result set // lookup node id 0, return that node start n=node(0) return n // lookup node in Index, return that node start n=node:Person(name="Andreas") return n // lookup all nodes, return all name properties start n=node(*) return n.name 30
  • 50. 31
  • 51. Cypher: MATCH ๏ START <lookup> MATCH <pattern> RETURN <expr> ๏ MATCH describes a pattern of nodes+relationships •node terms in optional parenthesis •lines with arrows for relationships 31
  • 52. Cypher: MATCH ๏ START <lookup> MATCH <pattern> RETURN <expr> ๏ MATCH describes a pattern of nodes+relationships •node terms in optional parenthesis •lines with arrows for relationships // lookup 'n', traverse any relationship to some 'm' start n=node(0) match (n)--(m) return n,m // any outgoing relationship from 'n' to 'm' start n=node(0) match n-->m return n,m // only 'KNOWS' relationships from 'n' to 'm' start n=node(0) match n-[:KNOWS]->m return n,m // from 'n' to 'm' and capture the relationship as 'r' start n=node(0) match n-[r]->m return n,r,m // from 'n' outgoing to 'm', then incoming from 'o' start n=node(0) match n-->m<--o return n,m,o 31
  • 53. 32
  • 54. Cypher: RETURN ๏ RETURN <expressions>, aggregation(expr) as alias ๏ RETURN nodes, rels, properties ๏ RETURN expressions of functions and operators ๏ RETURN aggregation functions on the above 32
  • 55. Cypher: RETURN ๏ RETURN <expressions>, aggregation(expr) as alias ๏ RETURN nodes, rels, properties ๏ RETURN expressions of functions and operators ๏ RETURN aggregation functions on the above // aggregate on n, count the m‘s start n=node(0) match n--m return n,count(*) // alias n.name as name start n=node(0) return n.name as name // aggregate m‘s into list start n=node(*) match n--m return n,collect(m) // filter m‘s by name start n=node(*) match n--m return n,filter(x in collect(m): m.name ˜= /A.*/) as a_block 32
  • 56. 33
  • 57. Cypher: WHERE ๏ START <lookup> [MATCH <pattern>] WHERE <condition> RETURN <expr> ๏ WHERE filters nodes or relationships •uses expressions to constrain elements 33
  • 58. Cypher: WHERE ๏ START <lookup> [MATCH <pattern>] WHERE <condition> RETURN <expr> ๏ WHERE filters nodes or relationships •uses expressions to constrain elements // lookup all nodes as 'n', constrained to name 'Andreas' start n=node(*) where n.name='Andreas' return n // filter nodes where age is less than 30 start n=node(*) where n.age<30 return n // filter using a regular expression start n=node(*) where n.name =~ /Tob.*/ return n // filter for a property exists start n=node(*) where has(n.name) return n 33
  • 59. 34
  • 60. Cypher: CREATE ๏ CREATE <node>[,node or relationship] RETURN <expr> •create nodes with optional properties •create relationship (must have a type) 34
  • 61. Cypher: CREATE ๏ CREATE <node>[,node or relationship] RETURN <expr> •create nodes with optional properties •create relationship (must have a type) // create an anonymous node create n // create node with a property, returning it create n={name:'Andreas'} return n // lookup 2 nodes, then create a relationship and return it start n=node(0),m=node(1) create n-[r:KNOWS]-m return r // lookup nodes, then create a relationship with properties start n=node(1),m=node(2) create n-[r:KNOWS {since:2008}]->m 34
  • 62. 35
  • 63. Cypher: CREATE UNIQUE ๏ CREATE UNIQUE node-[rel]->(node {prop : value}) •„fixes“ the graph •starts at bound nodes, properties rels and nodes by comparing types and tries to find •if not found creates them 35
  • 64. Cypher: CREATE UNIQUE ๏ CREATE UNIQUE node-[rel]->(node {prop : value}) •„fixes“ the graph •starts at bound nodes, properties rels and nodes by comparing types and tries to find •if not found creates them // create a new relationship start n=.., m=.. create unique n-[:KNOWS]->m // create a new node AND relationship start n=... create unique n-[:TAGGED]->(tag {name:“neo“}) // matches the tag node by name only creates new relationship start n=... create unique n-[:TAGGED]->(tag {name:“neo“}) 35
  • 65. 36
  • 66. Cypher: SET ๏ SET [<node property>] [<relationship property>] •update a property on a node or relationship •must follow a START 36
  • 67. Cypher: SET ๏ SET [<node property>] [<relationship property>] •update a property on a node or relationship •must follow a START // update the name property start n=node(0) set n.name='Peter' // update many nodes, using a calculation start n=node(*) set n.size=n.size+1 // match & capture a relationship, update a property start n=node(1) match n-[r]-m set r.times=10 36
  • 68. 37
  • 69. Cypher: DELETE ๏ DELETE [<node>|<relationship>|<property>] •delete a node, relationship or property •toall relationships must be deleted first delete a node, 37
  • 70. Cypher: DELETE ๏ DELETE [<node>|<relationship>|<property>] •delete a node, relationship or property •toall relationships must be deleted first delete a node, // delete a node start n=node(5) delete n // remove a node and all relationships start n=node(3) match n-[r]-() delete n, r // remove a property start n=node(3) delete n.age 37
  • 71. More Advanced Examples 38
  • 72. START user = node(1) MATCH user -[user_skill]-> skill RETURN skill, user_skill SELECT skills.*, user_skill.* FROM users JOIN user_skill ON users.id = user_skill.user_id JOIN skills ON user_skill.skill_id = skill.id WHERE users.id = 1 39
  • 73. Example: Old, Influential Friends START me = node(...) MATCH (me) - [f:FRIEND] - (old_friend) - [:FRIEND ] - (fof) WHERE ({today}-f.begin) > 365*10 WITH  old_friend, collect(fof.name) as names WHERE length(names) > 100 RETURN old_friend, names ORDER BY old_friend.name ASC f:FRIEND :FRIEND me friend fof
  • 74. Example: Simple Recommendation START me = node(...) MATCH (me) -[r1:RATED ]->(thing) <-[r2:RATED ]- (someone) -[r3:RATED ]->(cool_thing) WHERE ABS(r1.stars-r2.stars) <= 2 AND r3.stars > 3 RETURN cool_thing, count(*) AS cnt ORDER BY cnt DESC LIMIT 10 r1:RATED thing r2:RATED me so TED r 3: RA cool thing 41
  • 75. Cypher Cheat Sheet http://neo4j.org/resources/cypher 42
  • 76. The Rabbithole http://console.neo4j.org This Graph: http://tinyurl.com/7cnvmlq 43
  • 77. How to use Cypher in YOUR programs 44
  • 78. Neo4j API ExecutionEngine engine = new ExecutionEngine(graphDB); String query = „start n=node:Person(name={name}) match n-[:ACTS_IN]->movie<-[:ACTS_IN]-friend return friend“; ExecutionResult result = engine.query(query, map(„name“, „Keanu“); for (Map<String,Object> row : result) { Node friend = row.get(„friend“); } Iterator<Node> friends = result.columnAs(„friend“); http://bit.ly/cypher-queries 45
  • 79. How to get started? 46
  • 80. How to get started? ๏ Documentation 46
  • 81. How to get started? ๏ Documentation • docs.neo4j.org - tutorials+reference 46
  • 82. How to get started? ๏ Documentation • docs.neo4j.org - tutorials+reference • http://console.neo4j.org 46
  • 83. How to get started? ๏ Documentation • docs.neo4j.org - tutorials+reference • http://console.neo4j.org • Neo4j in Action 46
  • 84. How to get started? ๏ Documentation • docs.neo4j.org - tutorials+reference • http://console.neo4j.org • Neo4j in Action • Good Relationships 46
  • 85. How to get started? ๏ Documentation • docs.neo4j.org - tutorials+reference • http://console.neo4j.org • Neo4j in Action • Good Relationships ๏ Get Neo4j 46
  • 86. How to get started? ๏ Documentation • docs.neo4j.org - tutorials+reference • http://console.neo4j.org • Neo4j in Action • Good Relationships ๏ Get Neo4j • http://neo4j.org/download 46
  • 87. How to get started? ๏ Documentation • docs.neo4j.org - tutorials+reference • http://console.neo4j.org • Neo4j in Action • Good Relationships ๏ Get Neo4j • http://neo4j.org/download • http://addons.heroku.com/neo4j/ ๏ Participate • http://groups.google.com/group/neo4j • http://neo4j.meetup.com 46
  • 88. How to get started? ๏ Documentation • docs.neo4j.org - tutorials+reference • http://console.neo4j.org • Neo4j in Action • Good Relationships ๏ Get Neo4j • http://neo4j.org/download • http://addons.heroku.com/neo4j/ ๏ Participate • http://groups.google.com/group/neo4j • http://neo4j.meetup.com • a session like this one ;) 46
  • 90. Neo4j-JDBC Driver & MovieDB Dataset http://blog.neo4j.org/2012/06/wanted-your- help-in-testing-neo4j-jdbc.html 48
  • 91. Got a Conference? Need a Dataset? http://blog.neo4j.org/2012/08/at-conference- need-dataset-neo4j-at.html 49
  • 93. Graphs in Software Technolgoy ๏ UML Diagrams are graphs ๏ dependencies between classes, packages, modules etc are graphs ๏ Software Metrics use dependency analysis ๏ Visualizations ๏ Cyclomatic Complexity, ๏ Fan-in (afferent-coupling) / Fan-out (efferent coupling) etc. 51
  • 94. Code City 52
  • 95. Class Diagram is a Graph 53
  • 96. SonarJ 54
  • 97. But there is more ๏Visualize & query Method, Field dependencies ๏Collaborative filtering (co-usage) ๏Ranking ๏God classes ๏Paths between classes 55
  • 98. Welcome to Class-Graph ๏take a JAR ๏put it under ASM ๏scan it superfast ๏pull everything into Neo4j ๏add categories, indexes ๏Have Fun http://github.com/jexp/class-graph 56
  • 100. Interactive Hands-On Session ๏Lots of tasks ๏use Cypher to solve them http://neo4j.org/resources/cypher ๏be creative, work together ๏ask ! ๏Server http://bit.ly/innoq-neo4j ๏just the beginning 58
  • 101. Task: Find java.lang.Number and return it 59
  • 102. Task: Find java.lang.Number and return it START o=node:types(name="java.lang.Number")  RETURN o; 59
  • 103. Task: Subclasses of Number? •Return just the name •Order them alphabetically 60
  • 104. Task: Subclasses of Number? START n=node:types(name="java.lang.Number")  MATCH n<-[:SUPER_TYPE]-s RETURN s.name ORDER BY s.name; •Return just the name •Order them alphabetically 60
  • 105. Task: Which Methods does it have / how many •Find the top 5 classes with the most members 61
  • 106. Task: Which Methods does it have / how many START n=node:types(name="java.lang.Number")  MATCH n-[:METHOD_OF|FIELD_OF]->m RETURN m; •Find the top 5 classes with the most members 61
  • 107. Task: Calculate the fan-out of java.lang.StringBuilder •Calculate fan-in •Which class has the highest fan-out •What about package-level? 62
  • 108. Task: Calculate the fan-out of java.lang.StringBuilder START o=node:types(name="j.l.StringBuilder") MATCH o-[:FIELD_OF]->f-[:FIELD_TYPE]->tf, o-[:METHOD_OF]->m-[:PARAM_TYPE]->tp, m-[:RETURN_TYPE]->tr RETURN o,count(distinct tf) + count(distinct tp) + count(distinct tr) as fan_out; •Calculate fan-in •Which class has the highest fan-out •What about package-level? 62
  • 109. Task: Find longest Inheritance Path 63
  • 110. Task: Find longest Inheritance Path start c=node:types(name="java.lang.Object")  match path=p<-[:SUPER_TYPE*]-c  return extract(n in nodes(path) : n.name), length(path) as len order by len desc  limit 5; 63
  • 111. Task: Find the class that used IOException most often 64
  • 112. Task: Find the class that used IOException most often START ex=node:types(name="java.io.IOException" MATCH ex<-[:THROWS]-m<-[:METHOD_OF]-c RETURN c, count(*) ORDER BY count(*) LIMIT 5; 64
  • 113. Task: Which other classes did classes that threw IOException use most often? •What could be a source of IOExceptions 65
  • 114. Task: Which other classes did classes that threw IOException use most often? START ex=node:types(name="java.io.IOException") MATCH ex<-[:THROWS]-m<-[:METHOD_OF]-c,  mbr<-[:METHOD_OF|FIELD_OF]-c, mbr-[:FIELD_TYPE|PARAM_TYPE| RETURN_TYPE|THROWS]->other_type WHERE other_type.name =~ /.+[.].+/ RETURN other_type.name, count(*) ORDER BY count(*) desc LIMIT 10; •What could be a source of IOExceptions 65
  • 115. Task: Find a class you like and add a field with your name and some type 66
  • 116. Task: Find a class you like and add a field with your name and some type START c=node:types(name="void"), t=node:types(name="java.lang.reflect.Proxy")  CREATE c-[:FIELD_OF]->(field {name:“Michael“}) -[:FIELD_TYPE]->t; 66
  • 117. Task: Delete the most annoying class and all its methods, fields and their relationships 67
  • 118. Task: Delete the most annoying class and all its methods, fields and their relationships START c=node:types(name="java.awt.List"), MATCH c-[r1:FIELD_OF|METHOD_OF]->mbr-[r2]-() c-[r]-() DELETE c,mbr,r1,r2,r; 67

Editor's Notes

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. There existed a number of different ways to query a graph database. This one aims to make querying easy, and to produce queries that are readable.\n\nWe looked at alternatives - SPARQL, SQL, Gremlin and other...\n
  22. There existed a number of different ways to query a graph database. This one aims to make querying easy, and to produce queries that are readable.\n\nWe looked at alternatives - SPARQL, SQL, Gremlin and other...\n
  23. There existed a number of different ways to query a graph database. This one aims to make querying easy, and to produce queries that are readable.\n\nWe looked at alternatives - SPARQL, SQL, Gremlin and other...\n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. There existed a number of different ways to query a graph database. This one aims to make querying easy, and to produce queries that are readable.\n\nWe looked at alternatives - SPARQL, SQL, Gremlin and other...\n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n
  73. \n
  74. \n
  75. \n
  76. \n
  77. \n
  78. \n
  79. \n
  80. \n
  81. \n
  82. \n
  83. \n
  84. \n
  85. \n
  86. \n
  87. \n
  88. \n
  89. \n
  90. \n
  91. \n
  92. \n
  93. \n
  94. \n
  95. \n
  96. \n
  97. \n
  98. \n
  99. \n
  100. \n
  101. \n
  102. \n
  103. \n
  104. \n
  105. \n
  106. \n
  107. \n
  108. There existed a number of different ways to query a graph database. This one aims to make querying easy, and to produce queries that are readable.\n\nWe looked at alternatives - SPARQL, SQL, Gremlin and other...\n
  109. \n
  110. \n
  111. 3rd minute\n
  112. \n
  113. \n
  114. \n
  115. \n
  116. \n
  117. \n
  118. \n
  119. \n
  120. \n
  121. \n
  122. 5th minute\n
  123. \n
  124. Life-Console\n&amp;#x2022;In Memory GDBs in Web Session\n&amp;#x2022;Set up with mutating Cypher (or Geoff)\n&amp;#x2022;Executes Cypher (also mutating)\n&amp;#x2022;Visualizes Graph &amp; Query Results (d3)\n&amp;#x2022;Multiple Cypher Versions\n&amp;#x2022;Share: short link, tweet, yUML\n&amp;#x2022;Embeddable &lt;iframe&gt;\n&amp;#x2022;Live Console for Docs\n
  125. \n
  126. \n
  127. \n
  128. \n
  129. \n
  130. \n
  131. \n
  132. \n
  133. \n
  134. \n
  135. \n
  136. \n
  137. \n
  138. \n
  139. \n
  140. \n
  141. \n
  142. \n
  143. \n
  144. \n
  145. \n
  146. \n
  147. \n
  148. \n
  149. \n
  150. \n
  151. \n
  152. \n
  153. \n
  154. \n
  155. \n
  156. \n
  157. \n
  158. \n
  159. \n
  160. \n
  161. \n
  162. \n
  163. \n
  164. \n