SlideShare a Scribd company logo
opencypher.org | opencypher@googlegroups.comopencypher.org | opencypher@googlegroups.com
Path Query Patterns
CIP2017-02-06
a.k.a. (Conjunctive) Regular Path Queries
“Regular expressions over Graphs”
Tobias Lindaaker
tobias@neotechnology.com
opencypher.org | opencypher@googlegroups.com
Find complex connections
MATCH (a)-[~cousin]-(b)
MATCH (me)-[:ALLY | [:ENEMY :ENEMY]]-(friend)
MATCH (x)-[[:A :B]+ :C+ [:B :A]*]->(y)
MATCH p = (a)-[[:KNOWS | :LOVES]+]->()
opencypher.org | opencypher@googlegroups.com
● Reuse and extend existing syntax
● Direct notation for common simple patterns
● Allow for complex patterns
● Avoid repetition and ceremony
Syntax design philosophy
opencypher.org | opencypher@googlegroups.com
● Shorthand syntax for node labels!
● Shorthand syntax for matching any edge!
● Shorthand syntax for property predicates!
● Declared Path Patterns are scoped per query
And declared at the head of the query
● Non-repetitive syntax for Declared Path Patterns
Improved since last time
opencypher.org | opencypher@googlegroups.com
Regular Expressions over Paths
● Sequence / Concatenation:
()-[ ]-()
● Alternative / Disjunction:
()-[ | ]-()
● Transitive closure:
()-[ *]-() // zero or more times
()-[ +]-() // one or more times
()-[ *n..]-() // n or more times
()-[ *n..m]-() // at least n, at most m
● Overriding direction for sub-pattern:
()-[< ]-() ()-[ >]-() ()-[< >]-()
Composition of Patterns
opencypher.org | opencypher@googlegroups.com
● Edge Label
()-[:KNOWS]-()
● Node Label
()-[(:Person)]-()
● Edge Properties
()-[:ROAD{length:12}]-()
● Node Properties
()-[({year:2017})]-()
● Edges with any label, and matching empty path
()-[-]-() ()-[()]-()
● Grouping of expressions
()-[[:KNOWS :LOVES]+]-()
Predicates for Path Patterns
opencypher.org | opencypher@googlegroups.com
● Referenced using ~
MATCH (a)-[~my_pattern]-(b)
● Declaration:
PATH PATTERN my_pattern =
()-[:FOO :BAR* :BAZ]-()
● Makes the pattern language Context Free
Declared Path Patterns
opencypher.org | opencypher@googlegroups.com
● PATH PATTERN same_color_nodes = (a)-[-]-(b)
WHERE a.color = b.color
MATCH (x)-[~same_color_nodes+]-(y)
● PATH PATTERN older_friends = (a)-[:KNOWS]-(b)
WHERE b.birthday < a.birthday
Advanced property tests
opencypher.org | opencypher@googlegroups.com
● PATH PATTERN friends_in_same_city = (a)-[:KNOWS]-(b)
WHERE EXISTS {
(a)-[:LIVES_IN]->()<-[:LIVES_IN]-(b)
}
● One pattern must be designated the main pattern
● Other patterns are put in WHERE
● The main pattern is presented when binding a matched path:
MATCH friendships = (a)-[~friends_in_same_city+]-()
Conjunctive Path Queries
opencypher.org | opencypher@googlegroups.com
Classic Context Free use case
// treats siblings as “zeroth cousin”
PATH PATTERN cousin =
()-[:PARENT> [() | ~cousin] <:PARENT]-()
MATCH rel=(me)-[~cousin]-(cus)
WHERE length(rel) > 2 // filter away siblings
Balanced Path Matching
opencypher.org | opencypher@googlegroups.com
● Covers all of GXPath - except negation
● Weaker scoping reach than
Regular Expressions with Memory
○ Variables only reach within single
Declared Path Pattern
● Defines a Context Free Language over paths
rather than just a Regular Language
● More sophisticated data tests than GXPath
Expressive power
compared to academic languages
opencypher.org | opencypher@googlegroups.com
PATH PATTERN same_pet_name = (a)-[:KNOWS]-(b)
WHERE EXISTS {
MATCH (a)-[:OWNS]-(petA:Animal),
(b)-[:OWNS]-(petB:Animal)
WHERE petA.name = petB.name
}
MATCH peculiar_friends = (x)-[~same_pet_name*]-()
Sophisticated data test
opencypher.org | opencypher@googlegroups.com
● Differentiate between single edge and path
MATCH (a)-[single:EDGE]-(and_a)-/~path*/-()
● Single edge matching allows variable binding
● Binding a path results in a whole path value bound
Alternative syntax ideas
opencypher.org | opencypher@googlegroups.com
“Battle testing”
● Prototype implementation
● Try to express interesting queries
○ Needs to find / define interesting queries
● Measure up against “yardstick queries”
● Academic evaluation of
○ expressive power
○ computational complexity
Next steps
opencypher.org | opencypher@googlegroups.com
that I have not yet been able to express
● Paths where the property value differs in all
nodes
○ quite possibly not tractable
● Paths where the property value in all
subsequent nodes differs from the first node
Yardstick queries

More Related Content

PDF
List comprehensions
PPTX
3 - Finding similar items
PDF
Future features for openCypher: Schema, Constraints, Subqueries, Configurable...
PDF
openCypher: Further Developments on Path Pattern Queries (Regular Path Queries)
PDF
openCypher: Technology Compatibility Kit (TCK) and Vendor Extensions
PDF
The 2nd graph database in sv meetup
PPTX
The openCypher Project - An Open Graph Query Language
PDF
Configurable Pattern Matching Semantics in openCypher: Defining Levels of Nod...
List comprehensions
3 - Finding similar items
Future features for openCypher: Schema, Constraints, Subqueries, Configurable...
openCypher: Further Developments on Path Pattern Queries (Regular Path Queries)
openCypher: Technology Compatibility Kit (TCK) and Vendor Extensions
The 2nd graph database in sv meetup
The openCypher Project - An Open Graph Query Language
Configurable Pattern Matching Semantics in openCypher: Defining Levels of Nod...

Similar to Path Pattern Queries: Introducing Regular Path Queries in openCypher (19)

PDF
How openCypher is implemented in Neo4j
PDF
openCypher: Syntax and Semantics for Multiple Graphs
PDF
Formal semantics for Cypher queries and updates
PDF
openCypher: Naming and Addressing Multiple Graphs
PDF
openCypher: Introducing subqueries
PDF
Flink Forward Berlin 2017: Max Kiessling, Martin Junghanns - Cypher-based Gra...
PDF
Cypher.PL: an executable specification of Cypher semantics
PDF
Writing a Cypher Engine in Clojure
PPTX
Mapping Graph Queries to PostgreSQL
PDF
Cypher.PL: Executable Specification of Cypher written in Prolog
PDF
Graph pattern matching semantics
PDF
openCypher Technology Compatibility Kit (TCK)
PDF
Lighthouse: Large-scale graph pattern matching on Giraph
PDF
Lighthouse: Large-scale graph pattern matching on Giraph
PDF
Intro to Cypher
PPT
X Path
PDF
Cypher for Apache Spark
PDF
Seventh openCypher Implementers Group Meeting: Status Update
How openCypher is implemented in Neo4j
openCypher: Syntax and Semantics for Multiple Graphs
Formal semantics for Cypher queries and updates
openCypher: Naming and Addressing Multiple Graphs
openCypher: Introducing subqueries
Flink Forward Berlin 2017: Max Kiessling, Martin Junghanns - Cypher-based Gra...
Cypher.PL: an executable specification of Cypher semantics
Writing a Cypher Engine in Clojure
Mapping Graph Queries to PostgreSQL
Cypher.PL: Executable Specification of Cypher written in Prolog
Graph pattern matching semantics
openCypher Technology Compatibility Kit (TCK)
Lighthouse: Large-scale graph pattern matching on Giraph
Lighthouse: Large-scale graph pattern matching on Giraph
Intro to Cypher
X Path
Cypher for Apache Spark
Seventh openCypher Implementers Group Meeting: Status Update
Ad

More from openCypher (20)

PDF
Learning Timed Automata with Cypher
PDF
Incremental View Maintenance for openCypher Queries
PDF
Multiple Graphs: Updatable Views
PDF
Micro-Servicing Linked Data
PDF
Graph abstraction
PDF
From Cypher 9 to GQL: Conceptual overview of multiple named graphs and compos...
PDF
Cypher for Gremlin
PDF
Comparing PGQL, G-Core and Cypher
PDF
Multiple graphs in openCypher
PDF
Eighth openCypher Implementers Group Meeting: Status Update
PDF
Cypher for Gremlin
PDF
Supporting dates and times in Cypher
PDF
Academic research on graph processing: connecting recent findings to industri...
PDF
Property Graphs with Time
PDF
Use case: processing multiple graphs
PDF
Cypher Editor in the Web
PDF
The inGraph project and incremental evaluation of Cypher queries
PDF
Formal Specification of Cypher
PDF
Formal Semantics of SQL and Cypher
PDF
Virtual Graphs & Graph Views in Cypher
Learning Timed Automata with Cypher
Incremental View Maintenance for openCypher Queries
Multiple Graphs: Updatable Views
Micro-Servicing Linked Data
Graph abstraction
From Cypher 9 to GQL: Conceptual overview of multiple named graphs and compos...
Cypher for Gremlin
Comparing PGQL, G-Core and Cypher
Multiple graphs in openCypher
Eighth openCypher Implementers Group Meeting: Status Update
Cypher for Gremlin
Supporting dates and times in Cypher
Academic research on graph processing: connecting recent findings to industri...
Property Graphs with Time
Use case: processing multiple graphs
Cypher Editor in the Web
The inGraph project and incremental evaluation of Cypher queries
Formal Specification of Cypher
Formal Semantics of SQL and Cypher
Virtual Graphs & Graph Views in Cypher
Ad

Recently uploaded (20)

PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Spectroscopy.pptx food analysis technology
PPTX
MYSQL Presentation for SQL database connectivity
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
KodekX | Application Modernization Development
PDF
Approach and Philosophy of On baking technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Chapter 3 Spatial Domain Image Processing.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Reach Out and Touch Someone: Haptics and Empathic Computing
Spectroscopy.pptx food analysis technology
MYSQL Presentation for SQL database connectivity
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Understanding_Digital_Forensics_Presentation.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Mobile App Security Testing_ A Comprehensive Guide.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Big Data Technologies - Introduction.pptx
KodekX | Application Modernization Development
Approach and Philosophy of On baking technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Chapter 3 Spatial Domain Image Processing.pdf

Path Pattern Queries: Introducing Regular Path Queries in openCypher

  • 1. opencypher.org | opencypher@googlegroups.comopencypher.org | opencypher@googlegroups.com Path Query Patterns CIP2017-02-06 a.k.a. (Conjunctive) Regular Path Queries “Regular expressions over Graphs” Tobias Lindaaker tobias@neotechnology.com
  • 2. opencypher.org | opencypher@googlegroups.com Find complex connections MATCH (a)-[~cousin]-(b) MATCH (me)-[:ALLY | [:ENEMY :ENEMY]]-(friend) MATCH (x)-[[:A :B]+ :C+ [:B :A]*]->(y) MATCH p = (a)-[[:KNOWS | :LOVES]+]->()
  • 3. opencypher.org | opencypher@googlegroups.com ● Reuse and extend existing syntax ● Direct notation for common simple patterns ● Allow for complex patterns ● Avoid repetition and ceremony Syntax design philosophy
  • 4. opencypher.org | opencypher@googlegroups.com ● Shorthand syntax for node labels! ● Shorthand syntax for matching any edge! ● Shorthand syntax for property predicates! ● Declared Path Patterns are scoped per query And declared at the head of the query ● Non-repetitive syntax for Declared Path Patterns Improved since last time
  • 5. opencypher.org | opencypher@googlegroups.com Regular Expressions over Paths ● Sequence / Concatenation: ()-[ ]-() ● Alternative / Disjunction: ()-[ | ]-() ● Transitive closure: ()-[ *]-() // zero or more times ()-[ +]-() // one or more times ()-[ *n..]-() // n or more times ()-[ *n..m]-() // at least n, at most m ● Overriding direction for sub-pattern: ()-[< ]-() ()-[ >]-() ()-[< >]-() Composition of Patterns
  • 6. opencypher.org | opencypher@googlegroups.com ● Edge Label ()-[:KNOWS]-() ● Node Label ()-[(:Person)]-() ● Edge Properties ()-[:ROAD{length:12}]-() ● Node Properties ()-[({year:2017})]-() ● Edges with any label, and matching empty path ()-[-]-() ()-[()]-() ● Grouping of expressions ()-[[:KNOWS :LOVES]+]-() Predicates for Path Patterns
  • 7. opencypher.org | opencypher@googlegroups.com ● Referenced using ~ MATCH (a)-[~my_pattern]-(b) ● Declaration: PATH PATTERN my_pattern = ()-[:FOO :BAR* :BAZ]-() ● Makes the pattern language Context Free Declared Path Patterns
  • 8. opencypher.org | opencypher@googlegroups.com ● PATH PATTERN same_color_nodes = (a)-[-]-(b) WHERE a.color = b.color MATCH (x)-[~same_color_nodes+]-(y) ● PATH PATTERN older_friends = (a)-[:KNOWS]-(b) WHERE b.birthday < a.birthday Advanced property tests
  • 9. opencypher.org | opencypher@googlegroups.com ● PATH PATTERN friends_in_same_city = (a)-[:KNOWS]-(b) WHERE EXISTS { (a)-[:LIVES_IN]->()<-[:LIVES_IN]-(b) } ● One pattern must be designated the main pattern ● Other patterns are put in WHERE ● The main pattern is presented when binding a matched path: MATCH friendships = (a)-[~friends_in_same_city+]-() Conjunctive Path Queries
  • 10. opencypher.org | opencypher@googlegroups.com Classic Context Free use case // treats siblings as “zeroth cousin” PATH PATTERN cousin = ()-[:PARENT> [() | ~cousin] <:PARENT]-() MATCH rel=(me)-[~cousin]-(cus) WHERE length(rel) > 2 // filter away siblings Balanced Path Matching
  • 11. opencypher.org | opencypher@googlegroups.com ● Covers all of GXPath - except negation ● Weaker scoping reach than Regular Expressions with Memory ○ Variables only reach within single Declared Path Pattern ● Defines a Context Free Language over paths rather than just a Regular Language ● More sophisticated data tests than GXPath Expressive power compared to academic languages
  • 12. opencypher.org | opencypher@googlegroups.com PATH PATTERN same_pet_name = (a)-[:KNOWS]-(b) WHERE EXISTS { MATCH (a)-[:OWNS]-(petA:Animal), (b)-[:OWNS]-(petB:Animal) WHERE petA.name = petB.name } MATCH peculiar_friends = (x)-[~same_pet_name*]-() Sophisticated data test
  • 13. opencypher.org | opencypher@googlegroups.com ● Differentiate between single edge and path MATCH (a)-[single:EDGE]-(and_a)-/~path*/-() ● Single edge matching allows variable binding ● Binding a path results in a whole path value bound Alternative syntax ideas
  • 14. opencypher.org | opencypher@googlegroups.com “Battle testing” ● Prototype implementation ● Try to express interesting queries ○ Needs to find / define interesting queries ● Measure up against “yardstick queries” ● Academic evaluation of ○ expressive power ○ computational complexity Next steps
  • 15. opencypher.org | opencypher@googlegroups.com that I have not yet been able to express ● Paths where the property value differs in all nodes ○ quite possibly not tractable ● Paths where the property value in all subsequent nodes differs from the first node Yardstick queries