SlideShare ist ein Scribd-Unternehmen logo
1 von 118
(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

Weitere ähnliche Inhalte

Andere mochten auch

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 EditionAleksander 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 CypherRuhaim Izmeth
 
Optimizing Cypher Queries in Neo4j
Optimizing Cypher Queries in Neo4jOptimizing Cypher Queries in Neo4j
Optimizing Cypher Queries in Neo4jNeo4j
 
Building a Graph-based Analytics Platform
Building a Graph-based Analytics PlatformBuilding a Graph-based Analytics Platform
Building a Graph-based Analytics PlatformKenny Bastani
 
Neo4j Use Cases - Graphdatenbanken im Einsatz
Neo4j Use Cases - Graphdatenbanken im EinsatzNeo4j Use Cases - Graphdatenbanken im Einsatz
Neo4j Use Cases - Graphdatenbanken im EinsatzNeo4j
 
Introduction to Neo4j and .Net
Introduction to Neo4j and .NetIntroduction to Neo4j and .Net
Introduction to Neo4j and .NetNeo4j
 
Building Cloud Native Architectures with Spring
Building Cloud Native Architectures with SpringBuilding Cloud Native Architectures with Spring
Building Cloud Native Architectures with SpringKenny 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 SparkKenny 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 Neo4jNeo4j
 
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 GraphsNeo4j
 
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/functionalityCurtis Mosters
 

Andere mochten auch (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
 

Mehr von 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.pdfjexp
 
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 toolsjexp
 
Looming Marvelous - Virtual Threads in Java
Looming Marvelous - Virtual Threads in JavaLooming Marvelous - Virtual Threads in Java
Looming Marvelous - Virtual Threads in Javajexp
 
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.pptxjexp
 
Neo4j Connector Apache Spark FiNCENFiles
Neo4j Connector Apache Spark FiNCENFilesNeo4j Connector Apache Spark FiNCENFiles
Neo4j Connector Apache Spark FiNCENFilesjexp
 
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 Dotsjexp
 
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 GraalVMjexp
 
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 Kafkajexp
 
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 Libraryjexp
 
Refactoring, 2nd Edition
Refactoring, 2nd EditionRefactoring, 2nd Edition
Refactoring, 2nd Editionjexp
 
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-Developmentjexp
 
A whirlwind tour of graph databases
A whirlwind tour of graph databasesA whirlwind tour of graph databases
A whirlwind tour of graph databasesjexp
 
Practical Graph Algorithms with Neo4j
Practical Graph Algorithms with Neo4jPractical Graph Algorithms with Neo4j
Practical Graph Algorithms with Neo4jjexp
 
A Game of Data and GraphQL
A Game of Data and GraphQLA Game of Data and GraphQL
A Game of Data and GraphQLjexp
 
Querying Graphs with GraphQL
Querying Graphs with GraphQLQuerying Graphs with GraphQL
Querying Graphs with GraphQLjexp
 
Graphs & Neo4j - Past Present Future
Graphs & Neo4j - Past Present FutureGraphs & Neo4j - Past Present Future
Graphs & Neo4j - Past Present Futurejexp
 
Intro to Graphs and Neo4j
Intro to Graphs and Neo4jIntro to Graphs and Neo4j
Intro to Graphs and Neo4jjexp
 

Mehr von 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
 

Kürzlich hochgeladen

Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 

Kürzlich hochgeladen (20)

Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 

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

Hinweis der Redaktion

  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