Cypher Query Language

4,841 views

Published on

Cypher is a declarative query language recently added to the Neo4j graph database. In this talk we explain the motivations for creating this language, describe its current features and design, and dive a little into its implementation. Finally, we discuss the future direction of how we expect the language to evolve.

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,841
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
77
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Cypher Query Language

  1. 1. FOSDEM 2012 Graph Processing Room 5 Feb 2012 Cypher Query Language Andrés Taylor and Alistair JonesWednesday, February 8, 2012
  2. 2. What is Cypher? • Graph Query Language for Neo4j • Aims to make querying simpleWednesday, February 8, 2012
  3. 3. Motivation Something new? • Existing Neo4j query mechanisms were not simple enough • Too verbose (Java API) • Too prescriptive (Gremlin)Wednesday, February 8, 2012
  4. 4. Motivation SQL? • Unable to express paths • these are crucial for graph-based reasoning • neo4j is schema/table freeWednesday, February 8, 2012
  5. 5. Motivation SPARQL? • SPARQL designed for a different data model • namespaces • properties as nodesWednesday, February 8, 2012
  6. 6. DesignWednesday, February 8, 2012
  7. 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 queryWednesday, February 8, 2012
  8. 8. Design Decisions Pattern matchingWednesday, February 8, 2012
  9. 9. Design Decisions Pattern matching A B CWednesday, February 8, 2012
  10. 10. Design Decisions A Pattern matching B CWednesday, February 8, 2012
  11. 11. Design Decisions A Pattern matching B CWednesday, February 8, 2012
  12. 12. Design Decisions A Pattern matching B CWednesday, February 8, 2012
  13. 13. Design Decisions A Pattern matching B CWednesday, February 8, 2012
  14. 14. Design Decisions ASCII-art patternsWednesday, February 8, 2012
  15. 15. Design Decisions ASCII-art patterns () --> ()Wednesday, February 8, 2012
  16. 16. Design Decisions ASCII-art patterns A BWednesday, February 8, 2012
  17. 17. Design Decisions ASCII-art patterns A B (A) --> (B)Wednesday, February 8, 2012
  18. 18. Design Decisions ASCII-art patterns LOVES A BWednesday, February 8, 2012
  19. 19. Design Decisions ASCII-art patterns LOVES A B A -[:LOVES]-> BWednesday, February 8, 2012
  20. 20. Design Decisions ASCII-art patterns A B CWednesday, February 8, 2012
  21. 21. Design Decisions ASCII-art patterns A B C A --> B --> CWednesday, February 8, 2012
  22. 22. Design Decisions ASCII-art patterns A B CWednesday, February 8, 2012
  23. 23. Design Decisions ASCII-art patterns A B C A --> B --> C, A --> CWednesday, February 8, 2012
  24. 24. Design Decisions ASCII-art patterns A B C A --> B --> C, A --> C A --> B --> C <-- AWednesday, February 8, 2012
  25. 25. Design Decisions Variable length paths A B A B A B ...Wednesday, February 8, 2012
  26. 26. Design Decisions Variable length paths A B A B A B ... A -[*]-> BWednesday, February 8, 2012
  27. 27. Design Decisions Optional relationships A BWednesday, February 8, 2012
  28. 28. Design Decisions Optional relationships A B A -[?]-> BWednesday, February 8, 2012
  29. 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. 30. Design Decisions Parsed, not an internal DSL Execution Semantics Serialisation Type System PortabilityWednesday, February 8, 2012
  31. 31. Design Decisions Familiar for SQL users select start from match where where group by return order byWednesday, February 8, 2012
  32. 32. ImplementationWednesday, February 8, 2012
  33. 33. Implementation Execution Plan start n=node(0) return n Parameters() Nodes(n) Extract([n]) ColumnFilter([n])Wednesday, February 8, 2012
  34. 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. 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. 36. Thanks for Listening! Questions? Andrés Taylor andres.taylor@neotechnology.com @andres_taylor Alistair Jones alistair.jones@neotechnology.com @apcjWednesday, February 8, 2012

×