variable length relationship pattern extensions
play

Variable Length Relationship Pattern Extensions Teon Banek March , - PowerPoint PPT Presentation

Variable Length Relationship Pattern Extensions Teon Banek March , cbnd About Me Teon Banek Graduated from University of Zagreb, Faculty of Electrical Engineering and Computing Lead query engine developer at Memgraph


  1. Variable Length Relationship Pattern Extensions Teon Banek March �, ���� cbnd

  2. About Me Teon Banek • Graduated from University of Zagreb, Faculty of Electrical Engineering and Computing • Lead query engine developer at Memgraph • Loves fencing, lasagne and black tea • teon.banek@memgraph.com Variable Length Relationship Pattern Extensions — About � of ��

  3. About Us Memgraph Ltd. • Startup, founded in ���6 • Building a graph database • In-memory • High-performance • Distributed • https://memgraph.com Variable Length Relationship Pattern Extensions — About � of ��

  4. Contents About � Filtering � Traversal Strategies � Conclusion � Variable Length Relationship Pattern Extensions — About � of ��

  5. Relationship Pattern Syntax • MATCH ()-[var? types? variableLength? properties?]-() • types = ':' name ( '|' types )? • variableLength = '*' min_bound? ( '..' max_bound )? • properties = '{' ( key_name ':' value )* '}' Variable Length Relationship Pattern Extensions — About � of ��

  6. MATCH ()-[rs:FriendOf *2..3 {years: 3}]->() Variable Length Relationship Pattern Extensions — About 6 of ��

  7. MATCH ()-[rs:FriendOf *2..3 {years: 3}]->() Variable Length Relationship Pattern Extensions — About 6 of ��

  8. What if want arbitrary expression predicate? We can traverse the obtained list. For example: ALL(r IN rs WHERE r.years > 2) What if we want to filter on traversed nodes? Still possible, we have access to whole path. But, the query can get complicated. Standard Filtering • We can filter on relationship type & property equality Variable Length Relationship Pattern Extensions — Filtering � of ��

  9. We can traverse the obtained list. For example: ALL(r IN rs WHERE r.years > 2) What if we want to filter on traversed nodes? Still possible, we have access to whole path. But, the query can get complicated. Standard Filtering • We can filter on relationship type & property equality • What if want arbitrary expression predicate? Variable Length Relationship Pattern Extensions — Filtering � of ��

  10. What if we want to filter on traversed nodes? Still possible, we have access to whole path. But, the query can get complicated. Standard Filtering • We can filter on relationship type & property equality • What if want arbitrary expression predicate? • We can traverse the obtained list. • For example: ALL(r IN rs WHERE r.years > 2) Variable Length Relationship Pattern Extensions — Filtering � of ��

  11. Standard Filtering • We can filter on relationship type & property equality • What if want arbitrary expression predicate? • We can traverse the obtained list. • For example: ALL(r IN rs WHERE r.years > 2) • What if we want to filter on traversed nodes? • Still possible, we have access to whole path. • But, the query can get complicated. Variable Length Relationship Pattern Extensions — Filtering � of ��

  12. Lambda syntax '(' rel_var ',' node_var '|' expr ')' rel_var — next relationship that we are about to traverse node_var — next node that we are about to reach expr — arbitrary expression which when evaluated produces true if we want to continue traversing MATCH ()-[rs * (next_r, next_n | next_r.years > 2)]-() MATCH ()-[rs *]-() WHERE ALL(next_r IN rs WHERE next_r.years > 2) Filter Lambda • For example • Essentially ALL embedded in pattern syntax Variable Length Relationship Pattern Extensions — Filtering 8 of ��

  13. MATCH ()-[rs * (next_r, next_n | next_r.years > 2)]-() MATCH ()-[rs *]-() WHERE ALL(next_r IN rs WHERE next_r.years > 2) Filter Lambda • For example • Essentially ALL embedded in pattern syntax • Lambda syntax '(' rel_var ',' node_var '|' expr ')' • rel_var — next relationship that we are about to traverse • node_var — next node that we are about to reach • expr — arbitrary expression which when evaluated produces true if we want to continue traversing Variable Length Relationship Pattern Extensions — Filtering 8 of ��

  14. MATCH (:Alice)-[rs:FriendOf * (r, n | r.years + n.age > 34)]->() Variable Length Relationship Pattern Extensions — Filtering � of ��

  15. MATCH (:Alice)-[rs:FriendOf * (r, n | r.years + n.age > 34)]->() Variable Length Relationship Pattern Extensions — Filtering � of ��

  16. MATCH (:Alice)-[rs:FriendOf * (r, n | r.years + n.age > 34)]->() Variable Length Relationship Pattern Extensions — Filtering � of ��

  17. Filter Lambda Conclusions • We can match using arbitrary expression on each upcoming node and relationship. • Covers the most common use case of regular expression like patterns. • There’s still the issue of filtering based on remote parts of the traversed paths. Variable Length Relationship Pattern Extensions — Filtering �� of ��

  18. Depth-First Search • Variable length expansion essentially performs a depth-first search. • Each result is a list of relationships forming the current step of the algorithm. Variable Length Relationship Pattern Extensions — Traversal Strategies �� of ��

  19. MATCH (:Alice)-[*]->(:Daniel) Variable Length Relationship Pattern Extensions — Traversal Strategies �� of ��

  20. MATCH (:Alice)-[*]->(:Daniel) Variable Length Relationship Pattern Extensions — Traversal Strategies �� of ��

  21. MATCH (:Alice)-[*]->(:Daniel) Variable Length Relationship Pattern Extensions — Traversal Strategies �� of ��

  22. MATCH (:Alice)-[*]->(:Daniel) Variable Length Relationship Pattern Extensions — Traversal Strategies �� of ��

  23. Breadth-First Search • One of the more common graph use cases is finding shortest paths. • Breadth-first search seems like a logical addition. • Syntax remains the same, but to enable the algorithm just append bfs to * . • MATCH ()-[var? types? '*bfs' properties? filterLambda?]-() Variable Length Relationship Pattern Extensions — Traversal Strategies �� of ��

  24. MATCH (:Alice)-[*bfs]->(:Daniel) Variable Length Relationship Pattern Extensions — Traversal Strategies �� of ��

  25. MATCH (:Alice)-[*bfs]->(:Daniel) Variable Length Relationship Pattern Extensions — Traversal Strategies �� of ��

  26. BFS Conclusion • BFS is nice and simple. • What about path cost determined by something other than a relationship traversal? Variable Length Relationship Pattern Extensions — Traversal Strategies �� of ��

  27. weightLambda — just like filterLambda but needs to produce a positive number as the current weight. weightVar — stores the final weight of the path. MATCH ()-[var? types? '*wShortest' properties? weightLambda weightVar filterLambda?]-() Weighted Shortest Path Search • Natural extension is assigning weights to relationships. • Algorithm is enabled by appending wShortest to * . • We also need syntax for tracking the weight. Variable Length Relationship Pattern Extensions — Traversal Strategies �6 of ��

  28. weightLambda weightVar filterLambda?]-() Weighted Shortest Path Search • Natural extension is assigning weights to relationships. • Algorithm is enabled by appending wShortest to * . • We also need syntax for tracking the weight. • MATCH ()-[var? types? '*wShortest' properties? • weightLambda — just like filterLambda but needs to produce a positive number as the current weight. • weightVar — stores the final weight of the path. Variable Length Relationship Pattern Extensions — Traversal Strategies �6 of ��

  29. MATCH (:Alice)-[*wShortest (r, n | r.years) total_weight]-(:Daniel) Variable Length Relationship Pattern Extensions — Traversal Strategies �� of ��

  30. MATCH (:Alice)-[*wShortest (r, n | r.years) total_weight]-(:Daniel) Variable Length Relationship Pattern Extensions — Traversal Strategies �� of ��

  31. Implementation maps naturally to how we do pattern matching. Conclusion • Syntactic additions are tied with pattern matching. • No special functions doing pattern matching outside of patterns. • This avoids surprising users. Variable Length Relationship Pattern Extensions — Conclusion �8 of ��

  32. Conclusion • Syntactic additions are tied with pattern matching. • No special functions doing pattern matching outside of patterns. • This avoids surprising users. • Implementation maps naturally to how we do pattern matching. Variable Length Relationship Pattern Extensions — Conclusion �8 of ��

  33. Thank You • Thank you for you attention! • Any questions? Variable Length Relationship Pattern Extensions — Conclusion �� of ��

Recommend


More recommend