SlideShare a Scribd company logo
1 of 36
Download to read offline
FOSDEM 2012
                                                         Graph Processing Room
                                                         5 Feb 2012




         Cypher Query Language
                              Andrés Taylor and Alistair Jones




Wednesday, February 8, 2012
What is Cypher?


                    • Graph Query Language for Neo4j
                    • Aims to make querying simple

Wednesday, February 8, 2012
Motivation
       Something new?


                    • Existing Neo4j query mechanisms were not
                          simple enough

                         • Too verbose (Java API)
                         • Too prescriptive (Gremlin)

Wednesday, February 8, 2012
Motivation
       SQL?


                    • Unable to express paths
                      • these are crucial for graph-based
                              reasoning

                    • neo4j is schema/table free

Wednesday, February 8, 2012
Motivation
       SPARQL?


                    • SPARQL designed for a different data model
                      • namespaces
                      • properties as nodes


Wednesday, February 8, 2012
Design




Wednesday, February 8, 2012
Design Decisions
             Declarative
                        Imperative         Declarative
      follow relationship              specify starting point
  breadth-first vs depth-first         specify desired outcome

              explicit algorithm       algorithm adaptable
                                         based on query




Wednesday, February 8, 2012
Design Decisions
             Pattern matching




Wednesday, February 8, 2012
Design Decisions
             Pattern matching


                                  A


                              B       C


Wednesday, February 8, 2012
Design Decisions                    A
             Pattern matching
                                B       C




Wednesday, February 8, 2012
Design Decisions                    A
             Pattern matching
                                B       C




Wednesday, February 8, 2012
Design Decisions                    A
             Pattern matching
                                B       C




Wednesday, February 8, 2012
Design Decisions                    A
             Pattern matching
                                B       C




Wednesday, February 8, 2012
Design Decisions
             ASCII-art patterns




Wednesday, February 8, 2012
Design Decisions
             ASCII-art patterns




                              () --> ()

Wednesday, February 8, 2012
Design Decisions
             ASCII-art patterns


                              A   B




Wednesday, February 8, 2012
Design Decisions
             ASCII-art patterns


                               A      B

                              (A) --> (B)

Wednesday, February 8, 2012
Design Decisions
             ASCII-art patterns

                                  LOVES
                              A           B




Wednesday, February 8, 2012
Design Decisions
             ASCII-art patterns

                                   LOVES
                               A           B

                              A -[:LOVES]-> B



Wednesday, February 8, 2012
Design Decisions
             ASCII-art patterns


                    A         B   C




Wednesday, February 8, 2012
Design Decisions
             ASCII-art patterns


                    A         B   C

                   A --> B --> C

Wednesday, February 8, 2012
Design Decisions
             ASCII-art patterns

                                  A


                              B       C




Wednesday, February 8, 2012
Design Decisions
             ASCII-art patterns

                                  A


                              B       C

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

Wednesday, February 8, 2012
Design Decisions
             ASCII-art patterns

                                  A


                              B       C

                 A --> B --> C, A --> C
                  A --> B --> C <-- A
Wednesday, February 8, 2012
Design Decisions
             Variable length paths

                                      A         B

                                  A                 B

                              A                         B
                                          ...



Wednesday, February 8, 2012
Design Decisions
             Variable length paths

                                      A         B

                                  A                 B

                              A                         B
                                          ...

                              A -[*]-> B
Wednesday, February 8, 2012
Design Decisions
             Optional relationships


                              A       B




Wednesday, February 8, 2012
Design Decisions
             Optional relationships


                               A      B

                              A -[?]-> B

Wednesday, February 8, 2012
Design Decisions
             Closures

      start london = node(1), moscow = node(2)
      match path = london -[*]-> moscow
      where all(city in nodes(path) where city.capital = true)




Wednesday, February 8, 2012
Design Decisions
             Parsed, not an internal DSL



              Execution Semantics      Serialisation

                         Type System   Portability




Wednesday, February 8, 2012
Design Decisions
             Familiar for SQL users


                               select
                                          start
                                from
                                         match
                               where
                                         where
                              group by
                                         return
                              order by




Wednesday, February 8, 2012
Implementation




Wednesday, February 8, 2012
Implementation

             Execution Plan


  start n=node(0)
  return n

  Parameters()
  Nodes(n)
  Extract([n])
  ColumnFilter([n])




Wednesday, February 8, 2012
Implementation

             Execution Plan
  start n=node(0)
  match n-[*]-> b
  return n.name, n, count(*)
  order by n.age

  Parameters()
  Nodes(n)
  PatternMatch(n-[*]->b)
  Extract([n.name, n])
  EagerAggregation( keys: [n.name, n], aggregates: [count(*)])
  Extract([n.age])
  Sort(n.age ASC)
  ColumnFilter([n.name,n,count(*)])


Wednesday, February 8, 2012
Implementation

             Execution Plan
  start n=node(0)
  match n-[*]-> b
  return n.name, n, count(*)
  order by n.name

  Parameters()
  Nodes(n)
  PatternMatch(n-[*]->b)
  Extract([n.name, n])
  Sort(n.name ASC,n ASC)
  EagerAggregation( keys: [n.name, n], aggregates: [count(*)])
  ColumnFilter([n.name,n,count(*)])


Wednesday, February 8, 2012
Thanks for Listening!
                                Questions?
   Andrés Taylor andres.taylor@neotechnology.com @andres_taylor
       Alistair Jones alistair.jones@neotechnology.com @apcj




Wednesday, February 8, 2012

More Related Content

What's hot

Pig Tutorial | Apache Pig Tutorial | What Is Pig In Hadoop? | Apache Pig Arch...
Pig Tutorial | Apache Pig Tutorial | What Is Pig In Hadoop? | Apache Pig Arch...Pig Tutorial | Apache Pig Tutorial | What Is Pig In Hadoop? | Apache Pig Arch...
Pig Tutorial | Apache Pig Tutorial | What Is Pig In Hadoop? | Apache Pig Arch...
Simplilearn
 
Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...
Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...
Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...
Databricks
 
Database Programming with Perl and DBIx::Class
Database Programming with Perl and DBIx::ClassDatabase Programming with Perl and DBIx::Class
Database Programming with Perl and DBIx::Class
Dave Cross
 
HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...
HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...
HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...
Simplilearn
 

What's hot (20)

Introduction to Graph Databases
Introduction to Graph DatabasesIntroduction to Graph Databases
Introduction to Graph Databases
 
Introduction: Relational to Graphs
Introduction: Relational to GraphsIntroduction: Relational to Graphs
Introduction: Relational to Graphs
 
Pig Tutorial | Apache Pig Tutorial | What Is Pig In Hadoop? | Apache Pig Arch...
Pig Tutorial | Apache Pig Tutorial | What Is Pig In Hadoop? | Apache Pig Arch...Pig Tutorial | Apache Pig Tutorial | What Is Pig In Hadoop? | Apache Pig Arch...
Pig Tutorial | Apache Pig Tutorial | What Is Pig In Hadoop? | Apache Pig Arch...
 
Introdução à Neo4j
Introdução à Neo4j Introdução à Neo4j
Introdução à Neo4j
 
Graph databases
Graph databasesGraph databases
Graph databases
 
Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...
Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...
Redis + Structured Streaming—A Perfect Combination to Scale-Out Your Continuo...
 
Neo4j GraphDay Seattle- Sept19- neo4j basic training
Neo4j GraphDay Seattle- Sept19- neo4j basic trainingNeo4j GraphDay Seattle- Sept19- neo4j basic training
Neo4j GraphDay Seattle- Sept19- neo4j basic training
 
Relational databases vs Non-relational databases
Relational databases vs Non-relational databasesRelational databases vs Non-relational databases
Relational databases vs Non-relational databases
 
Intro to Cypher
Intro to CypherIntro to Cypher
Intro to Cypher
 
Spark Summit East 2015 Advanced Devops Student Slides
Spark Summit East 2015 Advanced Devops Student SlidesSpark Summit East 2015 Advanced Devops Student Slides
Spark Summit East 2015 Advanced Devops Student Slides
 
NoSQL databases
NoSQL databasesNoSQL databases
NoSQL databases
 
Database Programming with Perl and DBIx::Class
Database Programming with Perl and DBIx::ClassDatabase Programming with Perl and DBIx::Class
Database Programming with Perl and DBIx::Class
 
Authentication & Authorization in GraphQL with AWS AppSync (MOB402) - AWS re:...
Authentication & Authorization in GraphQL with AWS AppSync (MOB402) - AWS re:...Authentication & Authorization in GraphQL with AWS AppSync (MOB402) - AWS re:...
Authentication & Authorization in GraphQL with AWS AppSync (MOB402) - AWS re:...
 
HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...
HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...
HBase Tutorial For Beginners | HBase Architecture | HBase Tutorial | Hadoop T...
 
Neo4J : Introduction to Graph Database
Neo4J : Introduction to Graph DatabaseNeo4J : Introduction to Graph Database
Neo4J : Introduction to Graph Database
 
Hive(ppt)
Hive(ppt)Hive(ppt)
Hive(ppt)
 
Presto: Optimizing Performance of SQL-on-Anything Engine
Presto: Optimizing Performance of SQL-on-Anything EnginePresto: Optimizing Performance of SQL-on-Anything Engine
Presto: Optimizing Performance of SQL-on-Anything Engine
 
OSA Con 2022 - Arrow in Flight_ New Developments in Data Connectivity - David...
OSA Con 2022 - Arrow in Flight_ New Developments in Data Connectivity - David...OSA Con 2022 - Arrow in Flight_ New Developments in Data Connectivity - David...
OSA Con 2022 - Arrow in Flight_ New Developments in Data Connectivity - David...
 
Neo4j Training Introduction
Neo4j Training IntroductionNeo4j Training Introduction
Neo4j Training Introduction
 
Graph based data models
Graph based data modelsGraph based data models
Graph based data models
 

Similar to Cypher Query Language

Redis on Rails (RedDotRubyConf 2012)
Redis on Rails (RedDotRubyConf 2012)Redis on Rails (RedDotRubyConf 2012)
Redis on Rails (RedDotRubyConf 2012)
Obie Fernandez
 

Similar to Cypher Query Language (9)

Como escalar aplicações PHP
Como escalar aplicações PHPComo escalar aplicações PHP
Como escalar aplicações PHP
 
Games for the Masses (QCon London 2012)
Games for the Masses (QCon London 2012)Games for the Masses (QCon London 2012)
Games for the Masses (QCon London 2012)
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Continous Delivery in Action
Continous Delivery in ActionContinous Delivery in Action
Continous Delivery in Action
 
Games for the Masses - Wie DevOps die Entwicklung von Architektur verändert (...
Games for the Masses - Wie DevOps die Entwicklung von Architektur verändert (...Games for the Masses - Wie DevOps die Entwicklung von Architektur verändert (...
Games for the Masses - Wie DevOps die Entwicklung von Architektur verändert (...
 
How design is transforming modern intranets
How design is transforming modern intranetsHow design is transforming modern intranets
How design is transforming modern intranets
 
An Analytics Toolkit Tour
An Analytics Toolkit TourAn Analytics Toolkit Tour
An Analytics Toolkit Tour
 
Redis on Rails (RedDotRubyConf 2012)
Redis on Rails (RedDotRubyConf 2012)Redis on Rails (RedDotRubyConf 2012)
Redis on Rails (RedDotRubyConf 2012)
 
RoRoRoomba - Ruby on Rails on Roomba Railsconf 2012
RoRoRoomba - Ruby on Rails on Roomba Railsconf 2012RoRoRoomba - Ruby on Rails on Roomba Railsconf 2012
RoRoRoomba - Ruby on Rails on Roomba Railsconf 2012
 

More from graphdevroom

Challenges in the Design of a Graph Database Benchmark
Challenges in the Design of a Graph Database Benchmark Challenges in the Design of a Graph Database Benchmark
Challenges in the Design of a Graph Database Benchmark
graphdevroom
 
Using Cascalog and Hadoop for rapid graph processing and exploration
Using Cascalog and Hadoop for rapid graph processing and exploration Using Cascalog and Hadoop for rapid graph processing and exploration
Using Cascalog and Hadoop for rapid graph processing and exploration
graphdevroom
 

More from graphdevroom (6)

An example graph visualization with Processing.js
An example graph visualization with Processing.js An example graph visualization with Processing.js
An example graph visualization with Processing.js
 
Bio4j: A pioneer graph based database for the integration of biological Big D...
Bio4j: A pioneer graph based database for the integration of biological Big D...Bio4j: A pioneer graph based database for the integration of biological Big D...
Bio4j: A pioneer graph based database for the integration of biological Big D...
 
Challenges in the Design of a Graph Database Benchmark
Challenges in the Design of a Graph Database Benchmark Challenges in the Design of a Graph Database Benchmark
Challenges in the Design of a Graph Database Benchmark
 
Ontological Conjunctive Query Answering over large, semi-structured knowledge...
Ontological Conjunctive Query Answering over large, semi-structured knowledge...Ontological Conjunctive Query Answering over large, semi-structured knowledge...
Ontological Conjunctive Query Answering over large, semi-structured knowledge...
 
Works with persistent graphs using OrientDB
Works with persistent graphs using OrientDB Works with persistent graphs using OrientDB
Works with persistent graphs using OrientDB
 
Using Cascalog and Hadoop for rapid graph processing and exploration
Using Cascalog and Hadoop for rapid graph processing and exploration Using Cascalog and Hadoop for rapid graph processing and exploration
Using Cascalog and Hadoop for rapid graph processing and exploration
 

Cypher Query Language

  • 1. FOSDEM 2012 Graph Processing Room 5 Feb 2012 Cypher Query Language Andrés Taylor and Alistair Jones Wednesday, February 8, 2012
  • 2. What is Cypher? • Graph Query Language for Neo4j • Aims to make querying simple Wednesday, February 8, 2012
  • 3. Motivation Something new? • Existing Neo4j query mechanisms were not simple enough • Too verbose (Java API) • Too prescriptive (Gremlin) Wednesday, February 8, 2012
  • 4. Motivation SQL? • Unable to express paths • these are crucial for graph-based reasoning • neo4j is schema/table free Wednesday, February 8, 2012
  • 5. Motivation SPARQL? • SPARQL designed for a different data model • namespaces • properties as nodes Wednesday, February 8, 2012
  • 7. Design Decisions Declarative Imperative Declarative follow relationship specify starting point breadth-first vs depth-first specify desired outcome explicit algorithm algorithm adaptable based on query Wednesday, February 8, 2012
  • 8. Design Decisions Pattern matching Wednesday, February 8, 2012
  • 9. Design Decisions Pattern matching A B C Wednesday, February 8, 2012
  • 10. Design Decisions A Pattern matching B C Wednesday, February 8, 2012
  • 11. Design Decisions A Pattern matching B C Wednesday, February 8, 2012
  • 12. Design Decisions A Pattern matching B C Wednesday, February 8, 2012
  • 13. Design Decisions A Pattern matching B C Wednesday, February 8, 2012
  • 14. Design Decisions ASCII-art patterns Wednesday, February 8, 2012
  • 15. Design Decisions ASCII-art patterns () --> () Wednesday, February 8, 2012
  • 16. Design Decisions ASCII-art patterns A B Wednesday, February 8, 2012
  • 17. Design Decisions ASCII-art patterns A B (A) --> (B) Wednesday, February 8, 2012
  • 18. Design Decisions ASCII-art patterns LOVES A B Wednesday, February 8, 2012
  • 19. Design Decisions ASCII-art patterns LOVES A B A -[:LOVES]-> B Wednesday, February 8, 2012
  • 20. Design Decisions ASCII-art patterns A B C Wednesday, February 8, 2012
  • 21. Design Decisions ASCII-art patterns A B C A --> B --> C Wednesday, February 8, 2012
  • 22. Design Decisions ASCII-art patterns A B C Wednesday, February 8, 2012
  • 23. Design Decisions ASCII-art patterns A B C A --> B --> C, A --> C Wednesday, February 8, 2012
  • 24. Design Decisions ASCII-art patterns A B C A --> B --> C, A --> C A --> B --> C <-- A Wednesday, February 8, 2012
  • 25. Design Decisions Variable length paths A B A B A B ... Wednesday, February 8, 2012
  • 26. Design Decisions Variable length paths A B A B A B ... A -[*]-> B Wednesday, February 8, 2012
  • 27. Design Decisions Optional relationships A B Wednesday, February 8, 2012
  • 28. Design Decisions Optional relationships A B A -[?]-> B Wednesday, February 8, 2012
  • 29. Design Decisions Closures start london = node(1), moscow = node(2) match path = london -[*]-> moscow where all(city in nodes(path) where city.capital = true) Wednesday, February 8, 2012
  • 30. Design Decisions Parsed, not an internal DSL Execution Semantics Serialisation Type System Portability Wednesday, February 8, 2012
  • 31. Design Decisions Familiar for SQL users select start from match where where group by return order by Wednesday, February 8, 2012
  • 33. Implementation Execution Plan start n=node(0) return n Parameters() Nodes(n) Extract([n]) ColumnFilter([n]) Wednesday, February 8, 2012
  • 34. Implementation Execution Plan start n=node(0) match n-[*]-> b return n.name, n, count(*) order by n.age Parameters() Nodes(n) PatternMatch(n-[*]->b) Extract([n.name, n]) EagerAggregation( keys: [n.name, n], aggregates: [count(*)]) Extract([n.age]) Sort(n.age ASC) ColumnFilter([n.name,n,count(*)]) Wednesday, February 8, 2012
  • 35. Implementation Execution Plan start n=node(0) match n-[*]-> b return n.name, n, count(*) order by n.name Parameters() Nodes(n) PatternMatch(n-[*]->b) Extract([n.name, n]) Sort(n.name ASC,n ASC) EagerAggregation( keys: [n.name, n], aggregates: [count(*)]) ColumnFilter([n.name,n,count(*)]) Wednesday, February 8, 2012
  • 36. Thanks for Listening! Questions? Andrés Taylor andres.taylor@neotechnology.com @andres_taylor Alistair Jones alistair.jones@neotechnology.com @apcj Wednesday, February 8, 2012