SlideShare una empresa de Scribd logo
1 de 100
Geekout
                             Tallin
                             Estonia


Got a Graph Database?
     Need a Query
      Language!
     (Neo4j) -[:LOVES]-> (Cypher)
(Michael) -[:WORKS_ON]-> (Neo4j)
                                          console


Cypher
                   community
                     graph
                                  Community

                     ME

Server


          Spring               Cloud
YOU
      ?
     SQL
   NOSQL
Graph Database
Graphs are
everywhere
(Neo4j) -[:IS_A]-> (Graph Database)
                                                                                                           Lucene
  Sharding                                     1 M/s

     Master/
                                                                                               Index
      Slave




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




                                                             RU
            JS                                                                             E
                                                                                                       MySQL
                          S




                                                               NS
                        _A




                                                               _O
                                       SC AL




Clojure
                        NS




           .net

                                                                 N
                      RU




                                                                                                   Mongo

          embedded                34bn                              Heroku
            Java                  Nodes
Homework
- so Pay Attention
• Go To http://bit.ly/geekout-cypher
• With your Cypher knowledge
 • Add yourself to the graph
 • Determine a path from you to me
• Share the console on Twitter by
  Monday
• Win this AR-Drone
Query a Graph
                        with


  ___ _____ _____ _____ _____          ___ ______ _____
 / _ / ___/ __ _      _|_     _|    / _ | ___ _    _|
/ /_  `--.| / / | |      | |      / /_  |_/ / | |
| _ |`--.  |       | |     | |      | _ |      / | |
| | | /__/ / __/_| |_ _| |_       | | | | |  | |
_| |_|____/ ____/___/ ___/       _| |_|_| _| _/




Whirlwind Tour
A Graph
 Can‘t see the Patterns for the Trees




             http://maxdemarzi.com/2012/02/13/visualizing-a-network-with-cypher/
Patterns?
 Where?
Patterns?
 Describe them!
Patterns?
 Find them on bound nodes
Patterns?
 There are more !
Patterns?
 Make them visible!
How ?

A Graph Query Language
         with
   Pattern Matching
SparQL, SQL ?

         No,
      Cypher
developed by and for
      Neo4j
Can I draw Patterns?



             A


         B       C
Sure, with ASCII ART!


             A


         B       C
Sure, with ASCII ART!


             A


         B       C

  A --> B --> C, A --> C
Sure, with ASCII ART!


             A


         B       C

  A --> B --> C, A --> C
   A --> B --> C <-- A
Example
    Directed Relationship


      A             B
Example
    Directed Relationship


      A             B

   (A) --> (B)
Example
Labeled Directed Relationship

            LOVES
       A             B
Example
Labeled Directed Relationship

            LOVES
       A             B

  (A) -[:LOVES]-> (B)
Example
Transitive Relationship Path


  A           B          C
Example
Transitive Relationship Path


  A           B          C


(A)-->(B)-->(C)
Example
Variable Length Path

            A         B

        A                 B

    A                         B
                ...
Example
Variable Length Path

            A         B

        A                 B

    A                         B
                ...

 (A) -[*]-> (B)
Real World
 Examples
Give me: JOINS
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




                START user = node(1)
                MATCH user -[r:USER_SKILL]-> skill
                RETURN skill, r
Give me:
              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
Give me:
                       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
                                 r3:RATED
                         cool
                         thing
Results ?


 • Tables:
  for Human Brainz & Tools

 • Graphs:
  to highlight, visualize,
  export & refining queries
One Step Back
• Goals / Intent
• Origins
• Decisions
• Implementation
• Future
What is Cypher?


• Graph Query Language for Neo4j
• Querying for Humans
Goals, Origins & Design
 Picking good ideas and having some of our own
Cypher: Some Goals

                                     ASCII-art
   Pattern
                                     patterns
   Matching


              Declarative
                                         External
                                           DSL

   Closures
                         SQL
                       Familiarity
Something new?

  • Existing Neo4j query mechanisms were not
    simple enough

   • Too verbose (Java API)
   • Too prescriptive (Gremlin)
  • Other query languages
Java API?
   • Object oriented
   • Node, Relationship, Path objects
   • Imperative
   • Verbose
   • Traversers, for-loops, Index
   • mostly lazy-eval
Gremlin?

  • DSL for pipes
  • imperative
  • a single path expression
    • loop constructs
    • side-effects
  • lots of closures
SQL?

  • Well known and understood
  • Unable to express paths
    • these are crucial for graph-based
       reasoning

  • Cumbersome Mutation
  • Neo4j is schema/table free
SPARQL?
  • SPARQL designed for a different data model
    • namespaces / URI‘s
    • reified properties as nodes
  • SPARQL/RDF mostly in academia
    • developers don‘t get it
  • Pattern matching is cool
Cypher: Some Goals

                                     ASCII-art
   Pattern
                                     patterns
   Matching


              Declarative
                                         External
                                           DSL

   Closures
                         SQL
                       Familiarity
Cypher: Some Goals

                                     ASCII-art
   Pattern
                                     patterns
   Matching


              Declarative
                                         External
                                           DSL

   Closures
                         SQL
                       Familiarity
Design Decisions
   Closures / Quantifiers

   START london = node(1), moscow = node(2)
   MATCH path = london -[*]-> moscow
   WHERE all(city in nodes(path) where city.capital)
   RETURN path
Cypher: Some Goals

                                     ASCII-art
   Pattern
                                     patterns
   Matching


              Declarative
                                         External
                                           DSL

   Closures
                         SQL
                       Familiarity
Design Decisions
   Parsed, not an internal DSL



    Execution Semantics   Serialisation

       Type System        Portability
Cypher: Some Goals

                                     ASCII-art
   Pattern
                                     patterns
   Matching


              Declarative
                                         External
                                           DSL

   Closures
                         SQL
                       Familiarity
Design Decisions
   Familiar for SQL users

       select           start
        from           match
       where           where
      group by         return
      order by        order by
                        skip
                        limit
Design Decisions
   Database vs Application
     Design Goal: single user
    interaction expressible as
           single query


                         Queries have enough logic to
                           find required data, not
                            enough to process it
Implementation
             Docs from
Execution      Tests
                                   Java Bridge
  Plan

                Pattern
                Matching

   Parsing

                           Scala
CODE
Scala

• Parser Combinator
• Query Object Creation
• Combining Pipes
• Pattern Matching
• Lazy Evaluation
Example: Pipes
START n=node(0)
MATCH n-[*]->m
RETURN n, count(*)
ORDER BY n.name


Resulting Pipes:

Parameters()
Nodes(n)                                  // Identifier n
PatternMatch(n-[*]->m)                    // Identifier m
Extract([n,n.name])
Sort(n.name ASC)
EagerAggregation( keys: [n], aggregates: [count(*)])
ColumnFilter([n.name,n,count(*)])
Why Scala?
• Fun Language
• Parser Combinators
• Functional Concepts
• Collection library
• Immutable Values
• Scala Pattern Matching
Problems with Scala?
• Scala versions
• Slow compilation
• Low Collection Write Throughput
• Code gets easily complicated
• Hard to ramp up for other devs
• Big separate library
Implementation
        Query Parts
• START
• MATCH
 • Pattern Matching
• WHERE
 • Expressions, Predicates
• RETURN
START
                                                 WHERE
                                                                           Aggregation
                   BINDS
                                                     FILTERS
DELETE                                                                  RESTRUCTURES


                           Identifier
REMOVE_FROM                                                    Result


                BOUND_TO               USED_IN                            PAGINATES
                                                      BUILDS_UP
                                                                                 SKIP/LIMIT
     Graph                  FOUND_IN              Pattern


                                                             DESCRIBES
                 ADD_TO            CREATES


                                                                            MATCH
         FIX                                     COMPLETES
                             CREATE


         RELATE
START
START dev=node:user(name=“Andres“)


 • lazy source of identifiers bound to nodes
   and relationships
 • each identifier is an iterable
 • spawns execution per value
 • cross product between multiple
 • index lookup or direct lookup
MATCH
MATCH dev-[:WORKED_ON]->project

• describe patterns with ASCII art
• declare identifiers
 • paths
 • var. length paths
 • graph algorithms
 • optional relationships
• expands results with each found subgraph
Core Acitvity:
     Pattern Matching
• Match clause with ASCII-art
• derive pattern description
• bound Nodes and Relationships
• finds patterns attached to bound entities
• each found Pattern spawns Subgraph Result
• recursive PM with Backtracking
Pattern Matching
• Scala
 • incremental search with backtracking
 • allows:
   • Variable length paths
   • Filter during matching
   • optional relationships
 • powerful but slower
Pattern Matching
• Java
 • existing graph matching libray
 • fast but less capable
 • integrated with lazy Scala API
• NEW Traversal Framework approach
 • for one or two bound nodes
 • use Neo4j traversal framework
• pattern description & complexity
  determine Pattern Matcher selection
Implementation
      • Recursive matching with backtracking
START x=... MATCH x-->y, x-->z, y-->z, z-->a-->b, z-->b
Implementation
      • Recursive matching with backtracking
START x=... MATCH x-->y, x-->z, y-->z, z-->a-->b, z-->b
Implementation
      • Recursive matching with backtracking
START x=... MATCH x-->y, x-->z, y-->z, z-->a-->b, z-->b
Implementation
      • Recursive matching with backtracking
START x=... MATCH x-->y, x-->z, y-->z, z-->a-->b, z-->b
Implementation
      • Recursive matching with backtracking
START x=... MATCH x-->y, x-->z, y-->z, z-->a-->b, z-->b
Implementation
      • Recursive matching with backtracking
START x=... MATCH x-->y, x-->z, y-->z, z-->a-->b, z-->b
Implementation
      • Recursive matching with backtracking
START x=... MATCH x-->y, x-->z, y-->z, z-->a-->b, z-->b
Implementation
      • Recursive matching with backtracking
START x=... MATCH x-->y, x-->z, y-->z, z-->a-->b, z-->b
Implementation
      • Recursive matching with backtracking
START x=... MATCH x-->y, x-->z, y-->z, z-->a-->b, z-->b
WHERE
WHERE project.name = „Cypher“




• filters results
• single big boolean expression
• needs existing identifiers to work with
• much like SQL
Expressions
• expressions compute values
 • composite Specification Pattern
 • input is ExecutionContext Map
• have name
• declare symbolic dependencies
 • self & composite
• directly derived from parser
 • probably rewritten in between
Predicates
• WHERE clause filters results with a single
  composed predicate
• boolean expressions
 • composable boolean algebra
• Patterns as predicates
• Quantifiers (ALL, NONE, SINGLE)
• Collections as predicates
RETURN
RETURN project, collect(idea),count(fun)


    • determines what to return
    • column names or aliases with AS
    • automatic aggregation
     • when aggregation function exists
     • all non-aggregated values are grouping
     • lazyness is killed with aggregation
SKIP LIMIT ORDER BY
        SKIP 5 LIMIT 10
  ORDER by length(ideas) DESC




  • the usual suspects
  • lazyness is killed with ordering
Mutation
                Transaction
   WITH                                   Idem-
(Separation)                             potence


                      DRY

   Mass Data
   Handling

                              Lazyness
Mutation
• need transactions
• must not disturb reads / traversals
 • separation of read and write query parts
• explicit context change and scope: WITH
 • implicit split for simple queries
• granularity of mutation aligned with # of
  executions
• work with parameters
Mutation - Impl.
• Query Builder create UpdateCommands
• UpdatePipe ??
• Transaction Scope for whole Query
• collect statistics
• create new entities
 • add identifiers to the ExecutionContext
• need to iterate through to get all updates
  executed (no lazyness), special Pipe
• have to track already deleted entities
Implementation
Mutating Query Parts
• WITH
• CREATE
• RELATE
• SET, DELETE
• FOREACH
START
                                                 WHERE
                                                                           Aggregation
                   BINDS
                                                     FILTERS
DELETE                                                                  RESTRUCTURES


                           Identifier
REMOVE_FROM                                                    Result


                BOUND_TO               USED_IN                            PAGINATES
                                                      BUILDS_UP
                                                                                 SKIP/LIMIT
     Graph                  FOUND_IN              Pattern


                                                             DESCRIBES
                 ADD_TO            CREATES


                                                                            MATCH
         FIX                                     COMPLETES
                             CREATE


         RELATE
WITH
WITH me, count(friend) as friends

  • syntax like RETURN
  • separate query parts like a pipe
  • declares a new scope with new identifiers
  • all other ids will be gone
  • useful for HAVING
  • spawns a new ExecutionContext
  • continue with read or write part
CREATE
CREATE me = {name: „Michael“}



• create new nodes or relationships
• can work with map params (or Iterables
  thereof)
• assign new identifiers
• can create full paths
RELATE
RELATE posts-[:POST]->(p {title: „..“}


     • FIX the graph
     • construct missing relationships and nodes
     • need at least one bound node
     • match given properties
     • try to advance (from multiple sides) and
       create missing stuff then iterate
DELETE
    DELETE n, rel, m.prop

• as expected
• idempotent deletion
• can only delete unconnected nodes
 • so delete relationships first
   START n=node(*)
   MATCH n-[r?]-()
   DELETE n,r
SET
SET n.name = „Father of “+m.name


   • can work with arbitrary expressions
   • use coalesce for idempotent defaults
   • can mass assign with map-parameters
FOREACH
FOREACH ( f in new_friends :
          RELATE me-[:FRIEND]->f)


    • iterable loop for mutating operations
    • saves a lot of repetetive code
    • wraps current execution context in a
      temporary proxy
Self Documenting Tests

• Provides
 • Title & Description
 • Define Sample Graph
 • Declare & Execute Query
 • Results
Self Documenting Tests
• Asserts
 • No Syntax Errors
   • Multiple Cypher Versions
 • No Execution Errors
 • Results
 • Resulting graph
Self Documenting Tests

• Generates
 • Graph Rendering Graph-Viz
 • Tabular Results
 • Ascii-doc for Documentation
 • Live-Console Integration
Self Documenting Tests

 • Good enough for
  • Fun to write
  • Integration Tests
  • Manual
  • Blog-ready Cookbook Examples
Self Documenting
Tests
Cypher Console(s)
• Integrated in Neo4j-Shell
• Integrated in Webadmin (Shell & Search)
• REPL & GIST - console.neo4j.org
• Interactive learning GCLI
• Scala spray-can & cypher = bansky
• py2neo, bash
• Google Document
Live Console
• In Memory GDBs in Web Session
• Set up with mutating Cypher (or Geoff)
• Executes Cypher (also mutating)
• Visualizes Graph & Query Results (d3)
• Multiple Cypher Versions
• Share: short link, tweet, yUML
• Embeddable <iframe>
• Live Console for Docs
The Rabbithole




            http://console.neo4j.org
           This Graph: http://tinyurl.com/7cnvmlq
Homework
- Apply your Wits
• Go To http://bit.ly/geekout-cypher
• With your new Cypher knowledge
 • Add yourself to the graph
 • Determine a path from you to me
• Share the console on Twitter by
  Monday
• Win this AR-Drone
Graph your World
• Neo4j.org
• Google Group
• Grab your own ego-Graph
Thanks for Listening!
   Questions?
michael.hunger@neotechnology.com
              @mesirii

Más contenido relacionado

Destacado

Neo4j - 5 cool graph examples
Neo4j - 5 cool graph examplesNeo4j - 5 cool graph examples
Neo4j - 5 cool graph examples
Peter Neubauer
 
Why relationships are cool but join sucks - Big Data & Graphs in Rome
Why relationships are cool but join sucks - Big Data & Graphs in RomeWhy relationships are cool but join sucks - Big Data & Graphs in Rome
Why relationships are cool but join sucks - Big Data & Graphs in Rome
Luca Garulli
 

Destacado (20)

Intro to Neo4j presentation
Intro to Neo4j presentationIntro to Neo4j presentation
Intro to Neo4j presentation
 
Webinar: RDBMS to Graphs
Webinar: RDBMS to GraphsWebinar: RDBMS to Graphs
Webinar: RDBMS to Graphs
 
Neo4j - 5 cool graph examples
Neo4j - 5 cool graph examplesNeo4j - 5 cool graph examples
Neo4j - 5 cool graph examples
 
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
 
Cypher Query Language
Cypher Query Language Cypher Query Language
Cypher Query Language
 
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
 
OrientDB
OrientDBOrientDB
OrientDB
 
OrientDB - the 2nd generation of (Multi-Model) NoSQL
OrientDB - the 2nd generation  of  (Multi-Model) NoSQLOrientDB - the 2nd generation  of  (Multi-Model) NoSQL
OrientDB - the 2nd generation of (Multi-Model) NoSQL
 
Graphdatenbanken mit Neo4j
Graphdatenbanken mit Neo4jGraphdatenbanken mit Neo4j
Graphdatenbanken mit Neo4j
 
How the IBM Platform LSF Architecture Accelerates Technical Computing
How the IBM Platform LSF Architecture Accelerates Technical ComputingHow the IBM Platform LSF Architecture Accelerates Technical Computing
How the IBM Platform LSF Architecture Accelerates Technical Computing
 
Optimizing Cypher Queries in Neo4j
Optimizing Cypher Queries in Neo4jOptimizing Cypher Queries in Neo4j
Optimizing Cypher Queries in Neo4j
 
Cypher
CypherCypher
Cypher
 
ETL into Neo4j
ETL into Neo4jETL into Neo4j
ETL into Neo4j
 
OrientDB introduction - NoSQL
OrientDB introduction - NoSQLOrientDB introduction - NoSQL
OrientDB introduction - NoSQL
 
Webinar: Large Scale Graph Processing with IBM Power Systems & Neo4j
Webinar: Large Scale Graph Processing with IBM Power Systems & Neo4jWebinar: Large Scale Graph Processing with IBM Power Systems & Neo4j
Webinar: Large Scale Graph Processing with IBM Power Systems & Neo4j
 
Why relationships are cool but join sucks - Big Data & Graphs in Rome
Why relationships are cool but join sucks - Big Data & Graphs in RomeWhy relationships are cool but join sucks - Big Data & Graphs in Rome
Why relationships are cool but join sucks - Big Data & Graphs in Rome
 
Leveraging relations at scale with Neo4j
Leveraging relations at scale with Neo4jLeveraging relations at scale with Neo4j
Leveraging relations at scale with Neo4j
 
OrientDB vs Neo4j - and an introduction to NoSQL databases
OrientDB vs Neo4j - and an introduction to NoSQL databasesOrientDB vs Neo4j - and an introduction to NoSQL databases
OrientDB vs Neo4j - and an introduction to NoSQL databases
 
Deploying Massive Scale Graphs for Realtime Insights
Deploying Massive Scale Graphs for Realtime InsightsDeploying Massive Scale Graphs for Realtime Insights
Deploying Massive Scale Graphs for Realtime Insights
 
Introduction to Neo4j and .Net
Introduction to Neo4j and .NetIntroduction to Neo4j and .Net
Introduction to Neo4j and .Net
 

Más de 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
 

Más de 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
 

Último

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Último (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 

Neo4j -[:LOVES]-> Cypher

  • 1.
  • 2. Geekout Tallin Estonia Got a Graph Database? Need a Query Language! (Neo4j) -[:LOVES]-> (Cypher)
  • 3. (Michael) -[:WORKS_ON]-> (Neo4j) console Cypher community graph Community ME Server Spring Cloud
  • 4. YOU ? SQL NOSQL Graph Database
  • 6.
  • 7. (Neo4j) -[:IS_A]-> (Graph Database) Lucene Sharding 1 M/s Master/ Index Slave LS TRAVERSA HIG S H_A TE VA RA IL. TEG IN PROVIDES Server ACID TX RUN LI S_A CE S NS ED O _L Ruby IK ES_T RU JS E MySQL S NS _A _O SC AL Clojure NS .net N RU Mongo embedded 34bn Heroku Java Nodes
  • 8. Homework - so Pay Attention • Go To http://bit.ly/geekout-cypher • With your Cypher knowledge • Add yourself to the graph • Determine a path from you to me • Share the console on Twitter by Monday • Win this AR-Drone
  • 9. Query a Graph with ___ _____ _____ _____ _____ ___ ______ _____ / _ / ___/ __ _ _|_ _| / _ | ___ _ _| / /_ `--.| / / | | | | / /_ |_/ / | | | _ |`--. | | | | | | _ | / | | | | | /__/ / __/_| |_ _| |_ | | | | | | | _| |_|____/ ____/___/ ___/ _| |_|_| _| _/ Whirlwind Tour
  • 10. A Graph Can‘t see the Patterns for the Trees http://maxdemarzi.com/2012/02/13/visualizing-a-network-with-cypher/
  • 13. Patterns? Find them on bound nodes
  • 16. How ? A Graph Query Language with Pattern Matching
  • 17. SparQL, SQL ? No, Cypher developed by and for Neo4j
  • 18. Can I draw Patterns? A B C
  • 19. Sure, with ASCII ART! A B C
  • 20. Sure, with ASCII ART! A B C A --> B --> C, A --> C
  • 21. Sure, with ASCII ART! A B C A --> B --> C, A --> C A --> B --> C <-- A
  • 22. Example Directed Relationship A B
  • 23. Example Directed Relationship A B (A) --> (B)
  • 25. Example Labeled Directed Relationship LOVES A B (A) -[:LOVES]-> (B)
  • 27. Example Transitive Relationship Path A B C (A)-->(B)-->(C)
  • 28. Example Variable Length Path A B A B A B ...
  • 29. Example Variable Length Path A B A B A B ... (A) -[*]-> (B)
  • 31. Give me: JOINS 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 START user = node(1) MATCH user -[r:USER_SKILL]-> skill RETURN skill, r
  • 32. Give me: 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
  • 33. Give me: 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 r3:RATED cool thing
  • 34. Results ? • Tables: for Human Brainz & Tools • Graphs: to highlight, visualize, export & refining queries
  • 35. One Step Back • Goals / Intent • Origins • Decisions • Implementation • Future
  • 36. What is Cypher? • Graph Query Language for Neo4j • Querying for Humans
  • 37. Goals, Origins & Design Picking good ideas and having some of our own
  • 38. Cypher: Some Goals ASCII-art Pattern patterns Matching Declarative External DSL Closures SQL Familiarity
  • 39. Something new? • Existing Neo4j query mechanisms were not simple enough • Too verbose (Java API) • Too prescriptive (Gremlin) • Other query languages
  • 40. Java API? • Object oriented • Node, Relationship, Path objects • Imperative • Verbose • Traversers, for-loops, Index • mostly lazy-eval
  • 41. Gremlin? • DSL for pipes • imperative • a single path expression • loop constructs • side-effects • lots of closures
  • 42. SQL? • Well known and understood • Unable to express paths • these are crucial for graph-based reasoning • Cumbersome Mutation • Neo4j is schema/table free
  • 43. SPARQL? • SPARQL designed for a different data model • namespaces / URI‘s • reified properties as nodes • SPARQL/RDF mostly in academia • developers don‘t get it • Pattern matching is cool
  • 44. Cypher: Some Goals ASCII-art Pattern patterns Matching Declarative External DSL Closures SQL Familiarity
  • 45. Cypher: Some Goals ASCII-art Pattern patterns Matching Declarative External DSL Closures SQL Familiarity
  • 46. Design Decisions Closures / Quantifiers START london = node(1), moscow = node(2) MATCH path = london -[*]-> moscow WHERE all(city in nodes(path) where city.capital) RETURN path
  • 47. Cypher: Some Goals ASCII-art Pattern patterns Matching Declarative External DSL Closures SQL Familiarity
  • 48. Design Decisions Parsed, not an internal DSL Execution Semantics Serialisation Type System Portability
  • 49. Cypher: Some Goals ASCII-art Pattern patterns Matching Declarative External DSL Closures SQL Familiarity
  • 50. Design Decisions Familiar for SQL users select start from match where where group by return order by order by skip limit
  • 51. Design Decisions Database vs Application Design Goal: single user interaction expressible as single query Queries have enough logic to find required data, not enough to process it
  • 52. Implementation Docs from Execution Tests Java Bridge Plan Pattern Matching Parsing Scala
  • 53. CODE
  • 54. Scala • Parser Combinator • Query Object Creation • Combining Pipes • Pattern Matching • Lazy Evaluation
  • 55. Example: Pipes START n=node(0) MATCH n-[*]->m RETURN n, count(*) ORDER BY n.name Resulting Pipes: Parameters() Nodes(n) // Identifier n PatternMatch(n-[*]->m) // Identifier m Extract([n,n.name]) Sort(n.name ASC) EagerAggregation( keys: [n], aggregates: [count(*)]) ColumnFilter([n.name,n,count(*)])
  • 56. Why Scala? • Fun Language • Parser Combinators • Functional Concepts • Collection library • Immutable Values • Scala Pattern Matching
  • 57. Problems with Scala? • Scala versions • Slow compilation • Low Collection Write Throughput • Code gets easily complicated • Hard to ramp up for other devs • Big separate library
  • 58. Implementation Query Parts • START • MATCH • Pattern Matching • WHERE • Expressions, Predicates • RETURN
  • 59. START WHERE Aggregation BINDS FILTERS DELETE RESTRUCTURES Identifier REMOVE_FROM Result BOUND_TO USED_IN PAGINATES BUILDS_UP SKIP/LIMIT Graph FOUND_IN Pattern DESCRIBES ADD_TO CREATES MATCH FIX COMPLETES CREATE RELATE
  • 60. START START dev=node:user(name=“Andres“) • lazy source of identifiers bound to nodes and relationships • each identifier is an iterable • spawns execution per value • cross product between multiple • index lookup or direct lookup
  • 61. MATCH MATCH dev-[:WORKED_ON]->project • describe patterns with ASCII art • declare identifiers • paths • var. length paths • graph algorithms • optional relationships • expands results with each found subgraph
  • 62. Core Acitvity: Pattern Matching • Match clause with ASCII-art • derive pattern description • bound Nodes and Relationships • finds patterns attached to bound entities • each found Pattern spawns Subgraph Result • recursive PM with Backtracking
  • 63. Pattern Matching • Scala • incremental search with backtracking • allows: • Variable length paths • Filter during matching • optional relationships • powerful but slower
  • 64. Pattern Matching • Java • existing graph matching libray • fast but less capable • integrated with lazy Scala API • NEW Traversal Framework approach • for one or two bound nodes • use Neo4j traversal framework • pattern description & complexity determine Pattern Matcher selection
  • 65. Implementation • Recursive matching with backtracking START x=... MATCH x-->y, x-->z, y-->z, z-->a-->b, z-->b
  • 66. Implementation • Recursive matching with backtracking START x=... MATCH x-->y, x-->z, y-->z, z-->a-->b, z-->b
  • 67. Implementation • Recursive matching with backtracking START x=... MATCH x-->y, x-->z, y-->z, z-->a-->b, z-->b
  • 68. Implementation • Recursive matching with backtracking START x=... MATCH x-->y, x-->z, y-->z, z-->a-->b, z-->b
  • 69. Implementation • Recursive matching with backtracking START x=... MATCH x-->y, x-->z, y-->z, z-->a-->b, z-->b
  • 70. Implementation • Recursive matching with backtracking START x=... MATCH x-->y, x-->z, y-->z, z-->a-->b, z-->b
  • 71. Implementation • Recursive matching with backtracking START x=... MATCH x-->y, x-->z, y-->z, z-->a-->b, z-->b
  • 72. Implementation • Recursive matching with backtracking START x=... MATCH x-->y, x-->z, y-->z, z-->a-->b, z-->b
  • 73. Implementation • Recursive matching with backtracking START x=... MATCH x-->y, x-->z, y-->z, z-->a-->b, z-->b
  • 74. WHERE WHERE project.name = „Cypher“ • filters results • single big boolean expression • needs existing identifiers to work with • much like SQL
  • 75. Expressions • expressions compute values • composite Specification Pattern • input is ExecutionContext Map • have name • declare symbolic dependencies • self & composite • directly derived from parser • probably rewritten in between
  • 76. Predicates • WHERE clause filters results with a single composed predicate • boolean expressions • composable boolean algebra • Patterns as predicates • Quantifiers (ALL, NONE, SINGLE) • Collections as predicates
  • 77. RETURN RETURN project, collect(idea),count(fun) • determines what to return • column names or aliases with AS • automatic aggregation • when aggregation function exists • all non-aggregated values are grouping • lazyness is killed with aggregation
  • 78. SKIP LIMIT ORDER BY SKIP 5 LIMIT 10 ORDER by length(ideas) DESC • the usual suspects • lazyness is killed with ordering
  • 79. Mutation Transaction WITH Idem- (Separation) potence DRY Mass Data Handling Lazyness
  • 80. Mutation • need transactions • must not disturb reads / traversals • separation of read and write query parts • explicit context change and scope: WITH • implicit split for simple queries • granularity of mutation aligned with # of executions • work with parameters
  • 81. Mutation - Impl. • Query Builder create UpdateCommands • UpdatePipe ?? • Transaction Scope for whole Query • collect statistics • create new entities • add identifiers to the ExecutionContext • need to iterate through to get all updates executed (no lazyness), special Pipe • have to track already deleted entities
  • 82. Implementation Mutating Query Parts • WITH • CREATE • RELATE • SET, DELETE • FOREACH
  • 83. START WHERE Aggregation BINDS FILTERS DELETE RESTRUCTURES Identifier REMOVE_FROM Result BOUND_TO USED_IN PAGINATES BUILDS_UP SKIP/LIMIT Graph FOUND_IN Pattern DESCRIBES ADD_TO CREATES MATCH FIX COMPLETES CREATE RELATE
  • 84. WITH WITH me, count(friend) as friends • syntax like RETURN • separate query parts like a pipe • declares a new scope with new identifiers • all other ids will be gone • useful for HAVING • spawns a new ExecutionContext • continue with read or write part
  • 85. CREATE CREATE me = {name: „Michael“} • create new nodes or relationships • can work with map params (or Iterables thereof) • assign new identifiers • can create full paths
  • 86. RELATE RELATE posts-[:POST]->(p {title: „..“} • FIX the graph • construct missing relationships and nodes • need at least one bound node • match given properties • try to advance (from multiple sides) and create missing stuff then iterate
  • 87. DELETE DELETE n, rel, m.prop • as expected • idempotent deletion • can only delete unconnected nodes • so delete relationships first START n=node(*) MATCH n-[r?]-() DELETE n,r
  • 88. SET SET n.name = „Father of “+m.name • can work with arbitrary expressions • use coalesce for idempotent defaults • can mass assign with map-parameters
  • 89. FOREACH FOREACH ( f in new_friends : RELATE me-[:FRIEND]->f) • iterable loop for mutating operations • saves a lot of repetetive code • wraps current execution context in a temporary proxy
  • 90. Self Documenting Tests • Provides • Title & Description • Define Sample Graph • Declare & Execute Query • Results
  • 91. Self Documenting Tests • Asserts • No Syntax Errors • Multiple Cypher Versions • No Execution Errors • Results • Resulting graph
  • 92. Self Documenting Tests • Generates • Graph Rendering Graph-Viz • Tabular Results • Ascii-doc for Documentation • Live-Console Integration
  • 93. Self Documenting Tests • Good enough for • Fun to write • Integration Tests • Manual • Blog-ready Cookbook Examples
  • 95. Cypher Console(s) • Integrated in Neo4j-Shell • Integrated in Webadmin (Shell & Search) • REPL & GIST - console.neo4j.org • Interactive learning GCLI • Scala spray-can & cypher = bansky • py2neo, bash • Google Document
  • 96. Live Console • In Memory GDBs in Web Session • Set up with mutating Cypher (or Geoff) • Executes Cypher (also mutating) • Visualizes Graph & Query Results (d3) • Multiple Cypher Versions • Share: short link, tweet, yUML • Embeddable <iframe> • Live Console for Docs
  • 97. The Rabbithole http://console.neo4j.org This Graph: http://tinyurl.com/7cnvmlq
  • 98. Homework - Apply your Wits • Go To http://bit.ly/geekout-cypher • With your new Cypher knowledge • Add yourself to the graph • Determine a path from you to me • Share the console on Twitter by Monday • Win this AR-Drone
  • 99. Graph your World • Neo4j.org • Google Group • Grab your own ego-Graph
  • 100. Thanks for Listening! Questions? michael.hunger@neotechnology.com @mesirii

Notas del editor

  1. \n
  2. Want to focus on implementation and design decisions, not so much usage\n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. For an overview of the language &amp; some basic examples\n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. first minute\n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. second minute\n
  23. second minute\n
  24. \n
  25. \n
  26. \n
  27. \n
  28. 3rd minute\n
  29. \n
  30. \n
  31. 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
  32. \n
  33. Java API\n&amp;#x2022;Object oriented\n&amp;#x2022;Node, Relationship, Path objects \n&amp;#x2022;Imperative\n&amp;#x2022;Verbose\n&amp;#x2022;Traversers, for-loops, Index\n&amp;#x2022;mostly lazy-eval\n\nGremlin\n&amp;#x2022;DSL for pipes\n&amp;#x2022;imperative\n&amp;#x2022;a single path expression\n&amp;#x2022;loop constructs\n&amp;#x2022;side-effects\n&amp;#x2022;lots of closures\n\nSQL\n&amp;#x2022;Well known and understood\n&amp;#x2022;Unable to express paths\n&amp;#x2022;these are crucial for graph-based reasoning\n&amp;#x2022;Cumbersome Mutation\n&amp;#x2022;Neo4j is schema/table free\n\n\nSPARQL\n&amp;#x2022;SPARQL designed for a different data model\n&amp;#x2022;namespaces / URI&amp;#x2018;s\n&amp;#x2022;reified properties as nodes\n&amp;#x2022;SPARQL/RDF mostly in academia\n&amp;#x2022;developers don&amp;#x2018;t get it\n&amp;#x2022;Pattern matching is cool\n\n
  34. Java API\n&amp;#x2022;Object oriented\n&amp;#x2022;Node, Relationship, Path objects \n&amp;#x2022;Imperative\n&amp;#x2022;Verbose\n&amp;#x2022;Traversers, for-loops, Index\n&amp;#x2022;mostly lazy-eval\n\nGremlin\n&amp;#x2022;DSL for pipes\n&amp;#x2022;imperative\n&amp;#x2022;a single path expression\n&amp;#x2022;loop constructs\n&amp;#x2022;side-effects\n&amp;#x2022;lots of closures\n\nSQL\n&amp;#x2022;Well known and understood\n&amp;#x2022;Unable to express paths\n&amp;#x2022;these are crucial for graph-based reasoning\n&amp;#x2022;Cumbersome Mutation\n&amp;#x2022;Neo4j is schema/table free\n\n\nSPARQL\n&amp;#x2022;SPARQL designed for a different data model\n&amp;#x2022;namespaces / URI&amp;#x2018;s\n&amp;#x2022;reified properties as nodes\n&amp;#x2022;SPARQL/RDF mostly in academia\n&amp;#x2022;developers don&amp;#x2018;t get it\n&amp;#x2022;Pattern matching is cool\n\n
  35. \n
  36. \n
  37. \n
  38. \n
  39. Java API\n&amp;#x2022;Object oriented\n&amp;#x2022;Node, Relationship, Path objects \n&amp;#x2022;Imperative\n&amp;#x2022;Verbose\n&amp;#x2022;Traversers, for-loops, Index\n&amp;#x2022;mostly lazy-eval\n\nGremlin\n&amp;#x2022;DSL for pipes\n&amp;#x2022;imperative\n&amp;#x2022;a single path expression\n&amp;#x2022;loop constructs\n&amp;#x2022;side-effects\n&amp;#x2022;lots of closures\n\nSQL\n&amp;#x2022;Well known and understood\n&amp;#x2022;Unable to express paths\n&amp;#x2022;these are crucial for graph-based reasoning\n&amp;#x2022;Cumbersome Mutation\n&amp;#x2022;Neo4j is schema/table free\n\n\nSPARQL\n&amp;#x2022;SPARQL designed for a different data model\n&amp;#x2022;namespaces / URI&amp;#x2018;s\n&amp;#x2022;reified properties as nodes\n&amp;#x2022;SPARQL/RDF mostly in academia\n&amp;#x2022;developers don&amp;#x2018;t get it\n&amp;#x2022;Pattern matching is cool\n\n
  40. \n
  41. Java API\n&amp;#x2022;Object oriented\n&amp;#x2022;Node, Relationship, Path objects \n&amp;#x2022;Imperative\n&amp;#x2022;Verbose\n&amp;#x2022;Traversers, for-loops, Index\n&amp;#x2022;mostly lazy-eval\n\nGremlin\n&amp;#x2022;DSL for pipes\n&amp;#x2022;imperative\n&amp;#x2022;a single path expression\n&amp;#x2022;loop constructs\n&amp;#x2022;side-effects\n&amp;#x2022;lots of closures\n\nSQL\n&amp;#x2022;Well known and understood\n&amp;#x2022;Unable to express paths\n&amp;#x2022;these are crucial for graph-based reasoning\n&amp;#x2022;Cumbersome Mutation\n&amp;#x2022;Neo4j is schema/table free\n\n\nSPARQL\n&amp;#x2022;SPARQL designed for a different data model\n&amp;#x2022;namespaces / URI&amp;#x2018;s\n&amp;#x2022;reified properties as nodes\n&amp;#x2022;SPARQL/RDF mostly in academia\n&amp;#x2022;developers don&amp;#x2018;t get it\n&amp;#x2022;Pattern matching is cool\n\n
  42. \n
  43. Java API\n&amp;#x2022;Object oriented\n&amp;#x2022;Node, Relationship, Path objects \n&amp;#x2022;Imperative\n&amp;#x2022;Verbose\n&amp;#x2022;Traversers, for-loops, Index\n&amp;#x2022;mostly lazy-eval\n\nGremlin\n&amp;#x2022;DSL for pipes\n&amp;#x2022;imperative\n&amp;#x2022;a single path expression\n&amp;#x2022;loop constructs\n&amp;#x2022;side-effects\n&amp;#x2022;lots of closures\n\nSQL\n&amp;#x2022;Well known and understood\n&amp;#x2022;Unable to express paths\n&amp;#x2022;these are crucial for graph-based reasoning\n&amp;#x2022;Cumbersome Mutation\n&amp;#x2022;Neo4j is schema/table free\n\n\nSPARQL\n&amp;#x2022;SPARQL designed for a different data model\n&amp;#x2022;namespaces / URI&amp;#x2018;s\n&amp;#x2022;reified properties as nodes\n&amp;#x2022;SPARQL/RDF mostly in academia\n&amp;#x2022;developers don&amp;#x2018;t get it\n&amp;#x2022;Pattern matching is cool\n\n
  44. \n
  45. Java API\n&amp;#x2022;Object oriented\n&amp;#x2022;Node, Relationship, Path objects \n&amp;#x2022;Imperative\n&amp;#x2022;Verbose\n&amp;#x2022;Traversers, for-loops, Index\n&amp;#x2022;mostly lazy-eval\n\nGremlin\n&amp;#x2022;DSL for pipes\n&amp;#x2022;imperative\n&amp;#x2022;a single path expression\n&amp;#x2022;loop constructs\n&amp;#x2022;side-effects\n&amp;#x2022;lots of closures\n\nSQL\n&amp;#x2022;Well known and understood\n&amp;#x2022;Unable to express paths\n&amp;#x2022;these are crucial for graph-based reasoning\n&amp;#x2022;Cumbersome Mutation\n&amp;#x2022;Neo4j is schema/table free\n\n\nSPARQL\n&amp;#x2022;SPARQL designed for a different data model\n&amp;#x2022;namespaces / URI&amp;#x2018;s\n&amp;#x2022;reified properties as nodes\n&amp;#x2022;SPARQL/RDF mostly in academia\n&amp;#x2022;developers don&amp;#x2018;t get it\n&amp;#x2022;Pattern matching is cool\n\n
  46. \n
  47. \n
  48. \n
  49. Parser Combinators\n&amp;#x2022;Scala Library - DSL for parsable Patterns\n&amp;#x2022;Composable parsers\n&amp;#x2022;Literals and expressions become AST values\n&amp;#x2022;additional checking and differentiation with match\n&amp;#x2022;esp. for better error messages\n&amp;#x2022;modularized parsers with traits\n&amp;#x2022;Tokens, Expressions, Patterns, Where, ....\n&amp;#x2022;combine traits for parser availability\n\nQuery Builders\n&amp;#x2022;input: parsed query AST\n&amp;#x2022;builder for each kind of pipe\n&amp;#x2022;incrementally ask most suitable builder\n&amp;#x2022; to add a fragment to the pipe construction\n&amp;#x2022;or rewrite existing pipes\n&amp;#x2022;error \n&amp;#x2022;when leftover input and incomplete output\n&amp;#x2022;when cannot advance due missing deps.\n\nCombining Pipes\n&amp;#x2022;Each step in the execution is a Pipe\n&amp;#x2022;has a sourcePipe\n&amp;#x2022;is a TraversableLike[Map,Any]\n&amp;#x2022;ExecutionContext holds (mutable) query state\n&amp;#x2022;Pipes declare symbol dependencies\n&amp;#x2022;from their expressions\n\nLazy Evaluation\n&amp;#x2022;Match clause with ASCII-art\n&amp;#x2022;derive pattern description\n&amp;#x2022;bound Nodes and Relationships\n&amp;#x2022;finds patterns attached to bound entities\n&amp;#x2022;each found Pattern spawns Subgraph Result\n
  50. Parser Combinators\n&amp;#x2022;Scala Library - DSL for parsable Patterns\n&amp;#x2022;Composable parsers\n&amp;#x2022;Literals and expressions become AST values\n&amp;#x2022;additional checking and differentiation with match\n&amp;#x2022;esp. for better error messages\n&amp;#x2022;modularized parsers with traits\n&amp;#x2022;Tokens, Expressions, Patterns, Where, ....\n&amp;#x2022;combine traits for parser availability\n\nQuery Builders\n&amp;#x2022;input: parsed query AST\n&amp;#x2022;builder for each kind of pipe\n&amp;#x2022;incrementally ask most suitable builder\n&amp;#x2022; to add a fragment to the pipe construction\n&amp;#x2022;or rewrite existing pipes\n&amp;#x2022;error \n&amp;#x2022;when leftover input and incomplete output\n&amp;#x2022;when cannot advance due missing deps.\n\nCombining Pipes\n&amp;#x2022;Each step in the execution is a Pipe\n&amp;#x2022;has a sourcePipe\n&amp;#x2022;is a TraversableLike[Map,Any]\n&amp;#x2022;ExecutionContext holds (mutable) query state\n&amp;#x2022;Pipes declare symbol dependencies\n&amp;#x2022;from their expressions\n\nLazy Evaluation\n&amp;#x2022;Match clause with ASCII-art\n&amp;#x2022;derive pattern description\n&amp;#x2022;bound Nodes and Relationships\n&amp;#x2022;finds patterns attached to bound entities\n&amp;#x2022;each found Pattern spawns Subgraph Result\n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. 5th minute\n
  60. \n
  61. \n
  62. \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. \n
  109. \n
  110. \n
  111. \n
  112. \n
  113. \n
  114. \n
  115. \n
  116. \n
  117. \n
  118. \n
  119. \n
  120. \n
  121. \n
  122. \n
  123. \n
  124. \n
  125. \n
  126. \n
  127. \n
  128. \n
  129. \n
  130. \n
  131. \n
  132. \n
  133. \n
  134. Mutation\n&amp;#x2022;need transactions\n&amp;#x2022;must not disturb reads / traversals\n&amp;#x2022;separation of read and write query parts\n&amp;#x2022;explicit context change and scope: WITH\n&amp;#x2022;implicit split for simple queries\n&amp;#x2022;granularity of mutation aligned with # of executions\n&amp;#x2022;work with parameters\n\nMutation-Impl\n&amp;#x2022;Query Builder create UpdateCommands\n&amp;#x2022;UpdatePipe ??\n&amp;#x2022;Transaction Scope for whole Query\n&amp;#x2022;collect statistics\n&amp;#x2022;create new entities\n&amp;#x2022;add identifiers to the ExecutionContext\n&amp;#x2022;need to iterate through to get all updates executed (no lazyness), special Pipe\n&amp;#x2022;have to track already deleted entities\n\n
  135. \n
  136. \n
  137. \n
  138. 5th minute\n
  139. \n
  140. \n
  141. \n
  142. DELETE\n&amp;#x2022;as expected\n&amp;#x2022;idempotent deletion\n&amp;#x2022;can only delete unconnected nodes\n&amp;#x2022;so delete relationships first\n&amp;#x2022;keeps track of deleted ndoes\n
  143. \n
  144. \n
  145. \n
  146. \n
  147. \n
  148. Self Documenting Tests\n&amp;#x2022;Provides\n&amp;#x2022;Title &amp; Description\n&amp;#x2022;Define Sample Graph\n&amp;#x2022;Declare &amp; Execute Query\n&amp;#x2022;Results\n\n&amp;#x2022;Asserts\n&amp;#x2022;No Syntax Errors\n&amp;#x2022;Multiple Cypher Versions\n&amp;#x2022;No Execution Errors\n&amp;#x2022;Results \n&amp;#x2022;Resulting graph\n\n&amp;#x2022;Generates\n&amp;#x2022;Graph Rendering Graph-Viz\n&amp;#x2022;Tabular Results\n&amp;#x2022;Ascii-doc for Documentation\n&amp;#x2022;Live-Console Integration\n
  149. \n
  150. \n
  151. \n
  152. 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
  153. \n
  154. \n
  155. \n