Regular Path Query (RPQ) – Example 1 8 User , Admin Query: User name :"Charlie" POSTED . ( ANSWERS ) ∗ r 8 y x N 6 N 3 follows Answers: r 4 r 3 User User follows F 1 : x �→ N 1 y �→ N 4 name :"Alice" name :"Bob" r 2 x �→ N 2 y �→ N 5 F 2 : N 1 N 2 F 3 : x �→ N 2 y �→ N 4 r 1 posted posted posted r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 N 5 answers answers Message Message id :22 id :25 text :"Hello" text :"World"
Regular Path Query (RPQ) – Example 1 8 User , Admin Query: User name :"Charlie" POSTED . ( ANSWERS ) ∗ r 8 y x N 6 N 3 follows Answers: r 4 r 3 User User follows F 1 : x �→ N 1 y �→ N 4 name :"Alice" name :"Bob" r 2 x �→ N 2 y �→ N 5 F 2 : N 1 N 2 F 3 : x �→ N 2 y �→ N 4 r 1 posted posted r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Regular Path Query (RPQ) – Example 2 9 User , Admin Query: User name :"Charlie" ( FOLLOWS ) ∗ r 8 y x N 6 N 3 follows r 4 r 3 User User follows name :"Alice" name :"Bob" r 2 N 1 N 2 r 1 posted posted r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Regular Path Query (RPQ) – Example 2 9 User , Admin Query: User name :"Charlie" ( FOLLOWS ) ∗ r 8 y x N 6 N 3 follows r 4 r 3 User User follows follows name :"Alice" name :"Bob" r 2 N 1 N 2 r 1 posted posted r 5 follows follows r 6 on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Regular Path Query (RPQ) – Example 2 9 User , Admin Query: User name :"Charlie" ( FOLLOWS ) ∗ r 8 y x N 6 N 3 follows Answers: r 4 r 3 User User follows F 1 : x �→ N 1 y �→ N 1 name :"Alice" name :"Bob" r 2 x �→ N 1 y �→ N 2 F 2 : N 1 N 2 F 3 : x �→ N 1 y �→ N 3 r 1 . . . . . . posted . . . posted r 5 follows r 6 x �→ N 3 y �→ N 3 F 9 : on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Regular Path Query (RPQ) – Example 2 9 User , Admin Query: User name :"Charlie" ( FOLLOWS ) ∗ r 8 y x N 6 N 3 follows Answers: r 4 r 3 User User follows F 1 : x �→ N 1 y �→ N 1 name :"Alice" name :"Bob" r 2 x �→ N 1 y �→ N 2 F 2 : N 1 N 2 F 3 : x �→ N 1 y �→ N 3 r 1 . . . . . . posted . . . posted r 5 follows r 6 x �→ N 3 y �→ N 3 F 9 : on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Regular Path Query (RPQ) – Example 2 9 User , Admin Query: User name :"Charlie" ( FOLLOWS ) ∗ r 8 y x N 6 N 3 follows Answers: r 4 r 3 User User follows follows F 1 : x �→ N 1 y �→ N 1 name :"Alice" name :"Bob" r 2 x �→ N 1 y �→ N 2 F 2 : N 1 N 2 F 3 : x �→ N 1 y �→ N 3 r 1 . . . . . . posted . . . posted r 5 follows follows r 6 x �→ N 3 y �→ N 3 F 9 : on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Regular Path Query (RPQ) – Example 2 9 User , Admin Query: User name :"Charlie" ( FOLLOWS ) ∗ r 8 y x N 6 N 3 follows Answers: r 4 r 3 User User follows follows F 1 : x �→ N 1 y �→ N 1 name :"Alice" name :"Bob" r 2 x �→ N 1 y �→ N 2 F 2 : N 1 N 2 F 3 : x �→ N 1 y �→ N 3 r 1 . . . . . . posted . . . posted r 5 follows follows r 6 x �→ N 3 y �→ N 3 F 9 : on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Regular Path Query (RPQ) – Example 2 9 User , Admin Query: User name :"Charlie" ( FOLLOWS ) ∗ r 8 y x N 6 N 3 follows Answers: r 4 r 3 User User follows F 1 : x �→ N 1 y �→ N 1 name :"Alice" name :"Bob" r 2 x �→ N 1 y �→ N 2 F 2 : N 1 N 2 F 3 : x �→ N 1 y �→ N 3 r 1 . . . . . . posted . . . posted r 5 follows r 6 x �→ N 3 y �→ N 3 F 9 : on :"05-14" on :"05-15" → ∞ -many path realise F 1 N 4 r 7 N 5 → RPQ follows set-semantics answers Message Message id :22 id :25 text :"Hello" text :"World"
Conjunction of RPQs (CRPQ) – Definition 10 A : alphabet (of relation types) N : nodes in the graph Example: Definition (a CRPQ C): y C = ( R 1 ∧ R 2 ∧ · · · ∧ R n ) ( a + b ) ∗ ( ab ) ∗ where R 1 ,, . . ., R n are RPQs x z c Answer to C: Set of the functions F : var ( C ) → N such that ∀ i , F | var ( R i ) is an answer to R i
Conjunction of RPQs (CRPQ) – Example 11 User , Admin Query: User name :"Charlie" r 8 POSTED N 6 N 3 y x z follows ( ANSWERS ) ∗ r 4 r 3 User User follows name :"Alice" name :"Bob" r 2 Answers: N 1 N 2 r 1 x z y posted posted �→ �→ �→ r 5 follows r 6 on :"05-14" on :"05-15" F 1 : N 1 N 4 N 4 F 2 : N 2 N 5 N 4 N 4 r 7 N 5 F 3 : N 2 N 5 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Union of CRPQs (UCRPQ) – Defintion 12 A : alphabet (of relation types) N : nodes in the graph Definition (UCRPQ Q) Q = ( C 1 ∪ C 2 ∪ · · · ∪ C n ) where C 1 , C 2 , . . ., C n are CRPQs Answer to Q: Set of partial functions: � var ( C 1 ) ∪ · · · ∪ var ( C n ) � → N � n F i , i = 1 where, ∀ i , F i is the answer to C i .
Outline 13 1 Introduction 2 Property graphs 3 Regular Path Queries 4 Cypher by example 5 Principles of the semantics 6 Towards a standard language for querying property graphs
Evaluating a Cypher query 13 User , Admin Example of Cypher query: User name :"Charlie" MATCH ✭ u1 ✮✲❬ p1 ✿ POSTED ❪✲❃✭ m1 ✮ r 8 WITH u1, p1, m1 ✳ text AS t1 N 6 N 3 follows WHERE t1 ❂ "Hello" r 4 r 3 User User follows A Cypher statement name :"Alice" name :"Bob" r 2 is a sequence of clauses N 1 N 2 r 1 posted posted r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Evaluating a Cypher query 13 User , Admin Example of Cypher query: User name :"Charlie" MATCH ✭ u1 ✮✲❬ p1 ✿ POSTED ❪✲❃✭ m1 ✮ r 8 WITH u1, p1, m1 ✳ text AS t1 N 6 N 3 follows WHERE t1 ❂ "Hello" r 4 r 3 User User follows A Cypher statement name :"Alice" name :"Bob" r 2 is a sequence of clauses N 1 N 2 queries a graph r 1 returns a table posted posted r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Matching nodes (1) 14 User User , Admin Query: User name :"Charlie" MATCH ✭ u1 ✿ User ✮ r 8 N 6 N 3 follows r 4 r 3 User User User User follows name :"Alice" name :"Bob" r 2 N 1 N 2 r 1 posted posted r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Matching nodes (1) 14 User User , Admin Query: User name :"Charlie" MATCH ✭ u1 ✿ User ✮ r 8 N 6 N 3 follows Result: r 4 r 3 User User User User follows u1 name :"Alice" name :"Bob" r 2 N 1 N 1 N 2 N 2 r 1 N 3 posted posted r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Matching nodes (2) 15 User User , Admin Admin Query: User name :"Charlie" MATCH ✭ u1 ✿ User ✿ Admin ✮ r 8 N 6 N 3 follows Result: r 4 r 3 User User follows u1 name :"Alice" name :"Bob" r 2 N 3 N 1 N 2 r 1 posted posted r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Matching nodes (3) 16 User , Admin Query: User name :"Charlie" MATCH ✭ u1{id ✿ 22} ✮ r 8 N 6 N 3 follows Result: r 4 r 3 User User follows u1 name :"Alice" name :"Bob" r 2 N 4 N 1 N 2 r 1 posted posted r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :22 id :25 text :"Hello" text :"World"
Matching relations (1) 17 User , Admin Query: User name :"Charlie" MATCH ✭✮✲❬ p1 ❪✲❃✭✮ r 8 N 6 N 3 follows Result: r 4 r 3 User User follows p1 name :"Alice" name :"Bob" r 2 r 1 N 1 N 2 r 2 r 1 r 3 posted posted r 5 follows r 6 r 4 on :"05-14" on :"05-15" r 5 r 6 N 4 r 7 N 5 r 7 answers Message Message id :22 id :25 text :"Hello" text :"World"
Matching relation (2) 18 User , Admin Query: User name :"Charlie" MATCH ✭ u1 ✮✲❬ p1 ✿ POSTED ❪✲❃✭ m1 ✮ r 8 N 6 N 3 follows Result: r 4 r 3 User User follows u1 p1 m1 name :"Alice" name :"Bob" r 2 N 1 r 5 N 4 N 1 N 2 N 2 r 6 N 5 r 1 posted posted posted posted r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Matching relationships (3) 19 User , Admin Query: User name :"Charlie" MATCH ✭ u1 ✮✲❬✿ FOLLOWS ❪✲❃✭✮ r 8 N 6 N 3 follows Result: r 4 r 3 User User follows follows u1 name :"Alice" name :"Bob" r 2 N 1 N 1 N 2 N 2 r 1 N 2 posted posted r 5 follows follows r 6 N 3 on :"05-14" on :"05-15" N 4 r 7 N 5 Cypher has bag semantics: N 2 has two outgoing follows answers Message Message relations ⇒ two lines N 2 id :22 id :25 text :"Hello" text :"World"
Matching paths (1) 20 User , Admin Admin Query: User name :"Charlie" MATCH ✭ u1 ✿ Admin ✮ r 8 ✲❬ l1 ✿ FOLLOWS* ❪✲❃✭ m1 ✮ N 6 N 3 follows r 4 r 3 User User Result: follows follows name :"Alice" name :"Bob" r 2 u1 l1 m1 N 1 N 2 N 3 [ r 4 ] N 1 r 1 N 3 [ r 4 , r 1 ] N 2 posted posted r 5 follows follows r 6 N 3 [ r 4 , r 1 , r 2 ] N 1 on :"05-14" on :"05-15" [ r 4 , r 1 , r 3 ] N 3 N 3 N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Matching paths (1) 20 User , Admin Admin Query: User name :"Charlie" MATCH ✭ u1 ✿ Admin ✮ r 8 ✲❬ l1 ✿ FOLLOWS* ❪✲❃✭ m1 ✮ N 6 N 3 follows r 4 r 3 User User Result: follows follows name :"Alice" name :"Bob" r 2 u1 l1 m1 N 1 N 2 N 3 [ r 4 ] N 1 r 1 N 3 [ r 4 , r 1 ] N 2 posted posted r 5 follows follows r 6 N 3 [ r 4 , r 1 , r 2 ] N 1 on :"05-14" on :"05-15" [ r 4 , r 1 , r 3 ] N 3 N 3 N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Matching paths (1) 20 User , Admin Admin Query: User name :"Charlie" MATCH ✭ u1 ✿ Admin ✮ r 8 ✲❬ l1 ✿ FOLLOWS* ❪✲❃✭ m1 ✮ N 6 N 3 follows r 4 r 3 User User Result: follows follows name :"Alice" name :"Bob" r 2 u1 l1 m1 N 1 N 2 N 3 [ r 4 ] N 1 r 1 N 3 [ r 4 , r 1 ] N 2 posted posted r 5 follows follows r 6 N 3 [ r 4 , r 1 , r 2 ] N 1 on :"05-14" on :"05-15" [ r 4 , r 1 , r 3 ] N 3 N 3 N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Matching paths (1) 20 User , Admin Admin Query: User name :"Charlie" MATCH ✭ u1 ✿ Admin ✮ r 8 ✲❬ l1 ✿ FOLLOWS* ❪✲❃✭ m1 ✮ N 6 N 3 follows r 4 r 3 User User Result: follows follows name :"Alice" name :"Bob" r 2 u1 l1 m1 N 1 N 2 N 3 [ r 4 ] N 1 r 1 N 3 [ r 4 , r 1 ] N 2 posted posted r 5 follows follows r 6 N 3 [ r 4 , r 1 , r 2 ] N 1 on :"05-14" on :"05-15" [ r 4 , r 1 , r 3 ] N 3 N 3 N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Matching paths (1) 20 User , Admin Admin Query: User name :"Charlie" MATCH ✭ u1 ✿ Admin ✮ r 8 ✲❬ l1 ✿ FOLLOWS* ❪✲❃✭ m1 ✮ N 6 N 3 follows r 4 r 3 User User Result: follows follows name :"Alice" name :"Bob" r 2 u1 l1 m1 N 1 N 2 N 3 [ r 4 ] N 1 r 1 N 3 [ r 4 , r 1 ] N 2 posted posted r 5 follows follows r 6 N 3 [ r 4 , r 1 , r 2 ] N 1 on :"05-14" on :"05-15" [ r 4 , r 1 , r 3 ] N 3 N 3 N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Matching paths (1) 20 User , Admin Query: User name :"Charlie" MATCH ✭ u1 ✿ Admin ✮ r 8 ✲❬ l1 ✿ FOLLOWS* ❪✲❃✭ m1 ✮ N 6 N 3 follows r 4 r 3 User User Result: follows name :"Alice" name :"Bob" r 2 u1 l1 m1 N 1 N 2 N 3 [ r 4 ] N 1 r 1 N 3 [ r 4 , r 1 ] N 2 posted posted r 5 follows r 6 N 3 [ r 4 , r 1 , r 2 ] N 1 on :"05-14" on :"05-15" [ r 4 , r 1 , r 3 ] N 3 N 3 N 4 r 7 N 5 Cypher-Morphism answers Message Message Each rel. matched ≤ 1 time id :22 id :25 ⇒ Finitely many results text :"Hello" text :"World"
Matching paths (2) 21 User , Admin Query: User name :"Charlie" MATCH ✭ u1 ✮✲❬✿ FOLLOWS ❪✲❃✭✮ r 8 ✲❬✿ POSTED ❪✲❃✭ m1 ✮ N 6 N 3 follows r 4 r 3 User User Result: follows name :"Alice" name :"Bob" r 2 u1 m1 N 1 N 2 N 1 N 5 r 1 N 2 N 4 posted posted r 5 follows r 6 N 3 N 5 on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Matching paths (2) 21 User , Admin Query: User name :"Charlie" MATCH ✭ u1 ✮✲❬✿ FOLLOWS ❪✲❃✭✮ r 8 ✲❬✿ POSTED ❪✲❃✭ m1 ✮ N 6 N 3 follows r 4 r 3 User User Result: follows name :"Alice" name :"Bob" r 2 u1 m1 N 1 N 2 N 1 N 5 r 1 N 2 N 4 posted posted posted r 5 follows follows r 6 N 3 N 5 on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Chaining clauses 22 User , Admin Query: User name :"Charlie" MATCH ✭ u1 ✮✲❬✿ POSTED ❪✲❃✭ m1 ✮ r 8 MATCH ✭ u2 ✮❁✲❬✿ FOLLOWS ❪✲✭ u1 ✮ N 6 N 3 follows ✲❬✿ FOLLOWS ❪✲❃✭ u3 ✮ r 4 r 3 User User follows name :"Alice" name :"Bob" r 2 N 1 N 2 r 1 posted posted r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Chaining clauses 22 User , Admin Query: User name :"Charlie" MATCH ✭ u1 ✮✲❬✿ POSTED ❪✲❃✭ m1 ✮ r 8 MATCH ✭ u2 ✮❁✲❬✿ FOLLOWS ❪✲✭ u1 ✮ N 6 N 3 follows ✲❬✿ FOLLOWS ❪✲❃✭ u3 ✮ r 4 r 3 User User follows Table after first MATCH : name :"Alice" name :"Bob" r 2 u1 m1 N 1 N 2 r 1 N 1 N 4 N 2 N 5 posted posted r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Chaining clauses 22 User , Admin Query: User name :"Charlie" MATCH ✭ u1 u1 ✮✲❬✿ POSTED ❪✲❃✭ m1 ✮ r 8 MATCH ✭ u2 ✮❁✲❬✿ FOLLOWS ❪✲✭ u1 u1 ✮ N 6 N 3 follows ✲❬✿ FOLLOWS ❪✲❃✭ u3 ✮ r 4 r 3 User User follows Table after first MATCH : name :"Alice" name :"Bob" r 2 u1 m1 N 1 N 2 r 1 N 1 N 4 N 2 N 5 posted posted r 5 follows r 6 on :"05-14" on :"05-15" Table after second MATCH : N 4 r 7 N 5 u1 u1 m1 u2 u3 answers Message N 1 N 4 · · Message N 2 N 5 · · id :22 id :25 text :"Hello" text :"World"
Chaining clauses 22 User , Admin Query: User name :"Charlie" MATCH ✭ u1 u1 ✮✲❬✿ POSTED ❪✲❃✭ m1 ✮ r 8 MATCH ✭ u2 ✮❁✲❬✿ FOLLOWS ❪✲✭ u1 u1 ✮ N 6 N 3 follows ✲❬✿ FOLLOWS ❪✲❃✭ u3 ✮ r 4 r 3 User User follows Table after first MATCH : name :"Alice" name :"Bob" r 2 u1 m1 N 1 N 2 r 1 N 1 N 4 N 2 N 5 posted posted r 5 follows follows r 6 on :"05-14" on :"05-15" Table after second MATCH : N 4 r 7 N 5 u1 u1 m1 u2 u3 answers Message N 1 N 4 · · Message N 2 N 5 · · id :22 id :25 text :"Hello" text :"World"
Chaining clauses 22 User , Admin Query: User name :"Charlie" MATCH ✭ u1 u1 ✮✲❬✿ POSTED ❪✲❃✭ m1 ✮ r 8 MATCH ✭ u2 ✮❁✲❬✿ FOLLOWS ❪✲✭ u1 u1 ✮ N 6 N 3 follows ✲❬✿ FOLLOWS ❪✲❃✭ u3 ✮ r 4 r 3 User User follows Table after first MATCH : name :"Alice" name :"Bob" r 2 u1 m1 N 1 N 2 r 1 N 1 N 4 N 2 N 5 posted posted r 5 follows follows r 6 on :"05-14" on :"05-15" Table after second MATCH : N 4 r 7 N 5 u1 u1 m1 u2 u3 answers Message N 1 N 4 · · Message N 2 N 5 · · id :22 id :25 text :"Hello" text :"World"
Chaining clauses 22 User , Admin Query: User name :"Charlie" MATCH ✭ u1 u1 ✮✲❬✿ POSTED ❪✲❃✭ m1 ✮ r 8 MATCH ✭ u2 ✮❁✲❬✿ FOLLOWS ❪✲✭ u1 u1 ✮ N 6 N 3 follows ✲❬✿ FOLLOWS ❪✲❃✭ u3 ✮ r 4 r 3 User User follows follows Table after first MATCH : name :"Alice" name :"Bob" r 2 u1 m1 N 1 N 2 r 1 N 1 N 4 N 2 N 5 posted posted r 5 follows r 6 on :"05-14" on :"05-15" Table after second MATCH : N 4 r 7 N 5 u1 u1 m1 u2 u3 answers Message N 1 N 4 · · Message N 2 N 5 · · id :22 id :25 text :"Hello" text :"World"
Chaining clauses 22 User , Admin Query: User name :"Charlie" MATCH ✭ u1 ✮✲❬✿ POSTED ❪✲❃✭ m1 ✮ r 8 MATCH ✭ u2 ✮❁✲❬✿ FOLLOWS ❪✲✭ u1 ✮ N 6 N 3 follows ✲❬✿ FOLLOWS ❪✲❃✭ u3 ✮ r 4 r 3 User User follows follows Table after first MATCH : name :"Alice" name :"Bob" r 2 u1 m1 N 1 N 2 r 1 N 1 N 4 N 2 N 5 posted posted r 5 follows r 6 on :"05-14" on :"05-15" Table after second MATCH : N 4 r 7 N 5 u1 m1 u2 u3 answers Message N 2 N 5 N 1 N 3 Message N 2 N 5 N 3 N 1 id :22 id :25 text :"Hello" text :"World"
Column manipulation ( WITH clause) 23 User , Admin Query: User name :"Charlie" MATCH ✭ u1 ✮✲❬ p1 ✿ POSTED ❪✲❃✭ m1 ✮ r 8 WITH u1, p1, m1.text AS t1 N 6 N 3 follows r 4 r 3 User User After the MATCH clause follows name :"Alice" name :"Bob" r 2 u1 p1 m1 N 1 N 2 N 1 r 5 N 4 r 1 N 2 r 6 N 5 posted posted posted posted r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Column manipulation ( WITH clause) 23 User , Admin Query: User name :"Charlie" MATCH ✭ u1 ✮✲❬ p1 ✿ POSTED ❪✲❃✭ m1 ✮ r 8 WITH u1 u1, p1 p1, m1.text AS t1 t1 N 6 N 3 follows r 4 r 3 User User After the MATCH clause follows name :"Alice" name :"Bob" r 2 u1 u1 p1 p1 m1 N 1 N 2 N 1 r 5 N 4 r 1 N 2 r 6 N 5 posted posted r 5 follows r 6 on :"05-14" on :"05-15" Execution of the WITH clause N 4 r 7 N 5 u1 u1 p1 p1 t1 t1 answers Message Message N 1 r 5 id :22 id :25 N 2 r 6 text :"Hello" text :"World"
Column manipulation ( WITH clause) 23 User , Admin Query: User name :"Charlie" MATCH ✭ u1 ✮✲❬ p1 ✿ POSTED ❪✲❃✭ m1 ✮ r 8 WITH u1, p1, m1.text m1.text AS t1 N 6 N 3 follows r 4 r 3 User User After the MATCH clause follows name :"Alice" name :"Bob" r 2 u1 p1 m1 N 1 N 2 N 1 r 5 N 4 r 1 N 2 r 6 N 5 posted posted r 5 follows r 6 on :"05-14" on :"05-15" Execution of the WITH clause N 4 r 7 N 5 u1 p1 t1 answers Message Message N 1 r 5 id :22 id :25 N 2 r 6 text :"Hello" text :"World"
Column manipulation ( WITH clause) 23 User , Admin Query: User name :"Charlie" MATCH ✭ u1 ✮✲❬ p1 ✿ POSTED ❪✲❃✭ m1 ✮ r 8 WITH u1, p1, m1.text m1.text AS t1 N 6 N 3 follows r 4 r 3 User User After the MATCH clause follows name :"Alice" name :"Bob" r 2 u1 p1 m1 N 1 N 2 N 1 r 5 N 4 N 4 r 1 N 2 r 6 N 5 posted posted r 5 follows r 6 on :"05-14" on :"05-15" Execution of the WITH clause N 4 r 7 N 5 u1 p1 t1 answers Message Message N 1 r 5 "Hello" "Hello" id :22 id :25 N 2 r 6 text :"Hello" text :"Hello" text :"World"
Column manipulation ( WITH clause) 23 User , Admin Query: User name :"Charlie" MATCH ✭ u1 ✮✲❬ p1 ✿ POSTED ❪✲❃✭ m1 ✮ r 8 WITH u1, p1, m1.text AS t1 N 6 N 3 follows r 4 r 3 User User After the MATCH clause follows name :"Alice" name :"Bob" r 2 u1 p1 m1 N 1 N 2 N 1 r 5 N 4 r 1 N 2 r 6 N 5 N 5 posted posted r 5 follows r 6 on :"05-14" on :"05-15" Execution of the WITH clause N 4 r 7 N 5 u1 p1 t1 answers Message Message N 1 r 5 "Hello" id :22 id :25 N 2 r 6 "World" "World" text :"Hello" text :"World" text :"World"
Column manipulation ( WITH clause) 23 User , Admin Query: User name :"Charlie" MATCH ✭ u1 ✮✲❬ p1 ✿ POSTED ❪✲❃✭ m1 ✮ r 8 WITH u1, p1, m1.text AS t1 N 6 N 3 follows r 4 r 3 User User After the MATCH clause follows name :"Alice" name :"Bob" r 2 u1 p1 m1 N 1 N 2 N 1 r 5 N 4 r 1 N 2 r 6 N 5 posted posted r 5 follows r 6 on :"05-14" on :"05-15" Final result N 4 r 7 N 5 u1 p1 t1 answers Message Message N 1 r 5 "Hello" id :22 id :25 N 2 r 6 "World" text :"Hello" text :"World"
Line filtering ( WHERE clause) 24 User , Admin Query: User name :"Charlie" MATCH ✭ u1 ✮✲❬ p1 ✿ POSTED ❪✲❃✭ m1 ✮ r 8 WITH u1, p1, m1 ✳ text AS t1 N 6 N 3 follows WHERE t1 ❂ "Hello" r 4 r 3 User User follows After the WITH clause name :"Alice" name :"Bob" r 2 u1 p1 t1 N 1 N 2 r 1 N 1 r 5 "Hello" posted posted N 2 r 6 "World" r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Line filtering ( WHERE clause) 24 User , Admin Query: User name :"Charlie" MATCH ✭ u1 ✮✲❬ p1 ✿ POSTED ❪✲❃✭ m1 ✮ r 8 WITH u1, p1, m1 ✳ text AS t1 N 6 N 3 follows WHERE t1 ❂ "Hello" r 4 r 3 User User follows After the WITH clause name :"Alice" name :"Bob" r 2 u1 p1 t1 N 1 N 2 r 1 N 1 r 5 "Hello" posted posted N 2 r 6 "World" r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 Execution of the WHERE clause N 5 u1 p1 t1 answers Message Message id :22 id :25 N 1 r 5 "Hello" text :"Hello" text :"World" N 2 r 6 "World"
Line filtering ( WHERE clause) 24 User , Admin Query: User name :"Charlie" MATCH ✭ u1 ✮✲❬ p1 ✿ POSTED ❪✲❃✭ m1 ✮ r 8 WITH u1, p1, m1 ✳ text AS t1 N 6 N 3 follows WHERE t1 ❂ "Hello" r 4 r 3 User User follows After the WITH clause name :"Alice" name :"Bob" r 2 u1 p1 t1 N 1 N 2 r 1 N 1 r 5 "Hello" posted posted N 2 r 6 "World" r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 Final result N 5 u1 p1 t1 answers Message Message id :22 id :25 N 1 r 5 "Hello" text :"Hello" text :"World"
A last read-only example 25 User , Admin Query: User name :"Charlie" MATCH ✭ a{name ✿ "Bob"} ✮ r 8 ✲❬ * ❪✲❃✭ b{id ✿ 22} ✮ N 6 N 3 follows ❁✲❬ * ❪✲✭ a ✮ r 4 r 3 User User follows Question name :"Alice" name :"Bob" name :"Bob" r 2 What does this computes ? N 1 N 2 r 1 posted posted r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :22 id :25 text :"Hello" text :"World"
A last read-only example 25 User , Admin Query: User name :"Charlie" MATCH ✭ a{name ✿ "Bob"} ✮ r 8 ✲❬ * ❪✲❃✭ b{id ✿ 22} ✮ N 6 N 3 follows ❁✲❬ * ❪✲✭ a ✮ r 4 r 3 User User follows Question name :"Alice" name :"Bob" name :"Bob" r 2 What does this computes ? N 1 N 2 r 1 Answer posted posted r 5 follows r 6 The # of pairs of disjoint paths on :"05-14" on :"05-15" from N 2 to N 4 . N 4 r 7 N 5 answers Message Message id :22 id :22 id :25 text :"Hello" text :"World"
A last read-only example 25 User , Admin Query: User name :"Charlie" MATCH ✭ a{name ✿ "Bob"} ✮ r 8 ✲❬ * ❪✲❃✭ b{id ✿ 22} ✮ N 6 N 3 follows ❁✲❬ * ❪✲✭ a ✮ r 4 r 3 User User follows Question name :"Alice" name :"Bob" name :"Bob" r 2 What does this computes ? N 1 N 2 r 1 Answer posted posted r 5 follows r 6 The # of pairs of disjoint paths on :"05-14" on :"05-15" from N 2 to N 4 . N 4 r 7 N 5 ⇒ Evaluation of one constant answers Message Message MATCH is NP-HARD id :22 id :22 id :25 text :"Hello" text :"World"
Node and relation creation ( CREATE ) 26 User , Admin Query: User name :"Charlie" name :"Charlie" MATCH ✭ a{name ✿ "Charlie"} ✮ r 8 CREATE ✭ a ✮✲❬✿ FOLLOWS ❪✲❃ N 6 N 3 follows ✭ b ✿ User ✮ r 4 r 3 User User follows Table after MATCH clause: name :"Alice" name :"Bob" r 2 a N 1 N 2 r 1 N 3 posted posted r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Node and relation creation ( CREATE ) 26 User , Admin Query: User User name :"Charlie" name :"Charlie" MATCH ✭ a{name ✿ "Charlie"} ✮ r 8 CREATE ✭ a ✮✲❬✿ FOLLOWS ❪✲❃ N 6 N 3 follows follows ✭ b ✿ User ✮ r 4 r 3 User User follows Table after MATCH clause: name :"Alice" name :"Bob" r 2 a N 1 N 2 r 1 N 3 posted posted r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Node and relation creation ( CREATE ) 26 User , Admin Query: User name :"Charlie" MATCH ✭ a{name ✿ "Charlie"} ✮ r 8 CREATE ✭ a ✮✲❬✿ FOLLOWS ❪✲❃ N 6 N 3 follows ✭ b ✿ User ✮ r 4 r 3 User User follows Table after MATCH clause: name :"Alice" name :"Bob" r 2 a N 1 N 2 r 1 N 3 posted posted r 5 follows r 6 on :"05-14" on :"05-15" Table after CREATE clause: a b N 4 r 7 N 5 N 3 N 6 answers Message Message id :22 id :25 text :"Hello" text :"World"
The example graph stored as CREATE clauses 27 User , Admin Query: User name :"Charlie" CREATE r 8 ✭ n1 ✿ User{name ✿ "Alice"} ✮ , N 6 N 3 follows ✭ n2 ✿ User{name ✿ "Bob"} ✮ , ✭ n3 ✿ User ✿ Admin r 4 r 3 User User follows {name ✿ "Charlie"} ✮ , name :"Alice" name :"Bob" ✭ n4 ✿ Message {id ✿ 22, r 2 text ✿ "Hello"} ✮ , N 1 N 2 ✭ n5 ✿ Message {id ✿ 25, r 1 text ✿ "World"} ✮ CREATE posted posted r 5 follows r 6 ✭ n1 ✮✲❬✿ FOLLOWS ❪✲❃✭ n2 ✮ , on :"05-14" on :"05-15" ✭ n1 ✮✲❬✿ POSTED {on ✿ "05-04"} ❪✲❃✭ n4 ✮ , N 4 r 7 ✭ n2 ✮✲❬✿ FOLLOWS ❪✲❃✭ n1 ✮ , N 5 ✭ n2 ✮✲❬✿ FOLLOWS ❪✲❃✭ n3 ✮ , ✭ n2 ✮✲❬✿ POSTED answers Message Message {on ✿ "05-04"} ❪✲❃✭ n5 ✮ , id :22 id :25 ✭ n3 ✮✲❬✿ FOLLOWS ❪✲❃✭ n1 ✮ , text :"Hello" text :"World" ✭ n5 ✮✲❬✿ ANSWERS ❪✲❃✭ n4 ✮ ,
Node/Relation modification ( SET clause) 28 User , Admin Query: User name :"Charlie" MATCH ✭ a{name ✿ "Charlie"} ✮ r 8 CREATE ✭ a ✮✲❬✿ FOLLOWS ❪✲❃ N 6 N 3 follows ✭ b ✿ User ✮ SET b ✿ Admin, b ✳ name ❂ "Eve" r 4 r 3 User User follows name :"Alice" name :"Bob" Table after CREATE clause: r 2 N 1 N 2 a b r 1 N 3 N 6 posted posted r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
Node/Relation modification ( SET clause) 28 User , Admin Admin User , Admin Query: name :"Eve" name :"Eve" name :"Charlie" MATCH ✭ a{name ✿ "Charlie"} ✮ r 8 CREATE ✭ a ✮✲❬✿ FOLLOWS ❪✲❃ N 6 N 3 follows ✭ b ✿ User ✮ SET b ✿ Admin, b ✳ name ❂ "Eve" r 4 r 3 User User follows name :"Alice" name :"Bob" Table after CREATE clause: r 2 N 1 N 2 a b r 1 N 3 N 6 posted posted r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 N 5 answers Message Message id :22 id :25 text :"Hello" text :"World"
The MERGE clause : MATCH else CREATE 29 User , Admin Input table: User name :"Charlie" r 8 a n N 6 N 3 follows N 3 "Alice" N 3 "Eve" r 4 r 3 User User follows name :"Alice" name :"Bob" r 2 Query: N 1 N 2 r 1 MERGE ✭ a ✮✲❬✿ FOLLOWS ❪✲❃ ✭ b ✿ User {name ✿ n} ✮ posted posted r 5 follows r 6 on :"05-14" on :"05-15" Output table: a n c N 4 r 7 N 5 N 3 "Alice" answers Message Message N 3 "Eve" id :22 id :25 text :"Hello" text :"World"
The MERGE clause : MATCH else CREATE 29 User , Admin Input table: User name :"Charlie" r 8 a n N 6 N 3 follows N 3 "Alice" N 3 "Eve" r 4 r 3 User User User follows follows name :"Alice" name :"Alice" name :"Bob" r 2 Query: N 1 N 2 r 1 MERGE ✭ a ✮✲❬✿ FOLLOWS ❪✲❃ ✭ b ✿ User {name ✿ n} ✮ posted posted r 5 follows r 6 on :"05-14" on :"05-15" Output table: a n c N 4 r 7 N 5 N 3 "Alice" N 1 answers Message Message N 3 "Eve" id :22 id :25 text :"Hello" text :"World"
The MERGE clause : MATCH else CREATE 29 User User User , Admin Input table: name :"Eve" name :"Eve" name :"Charlie" r 8 a n N 6 N 3 follows follows N 3 "Alice" N 3 "Eve" r 4 r 3 User User follows name :"Alice" name :"Bob" r 2 Query: N 1 N 2 r 1 MERGE ✭ a ✮✲❬✿ FOLLOWS ❪✲❃ ✭ b ✿ User {name ✿ n} ✮ posted posted r 5 follows r 6 on :"05-14" on :"05-15" Output table: a n c N 4 r 7 N 5 N 3 "Alice" N 1 answers Message Message N 3 "Eve" N 6 id :22 id :25 text :"Hello" text :"World"
The MERGE clause : MATCH else CREATE 29 User User , Admin Input table: name :"Eve" name :"Charlie" r 8 a n N 6 N 3 follows N 3 "Alice" N 3 "Eve" r 4 r 3 User User follows name :"Alice" name :"Bob" r 2 Query: N 1 N 2 r 1 MERGE ✭ a ✮✲❬✿ FOLLOWS ❪✲❃ ✭ b ✿ User {name ✿ n} ✮ posted posted r 5 follows r 6 on :"05-14" on :"05-15" Output table: a n c N 4 r 7 N 5 N 3 "Alice" N 1 answers Message Message N 3 "Eve" N 6 id :22 id :25 text :"Hello" text :"World"
Other constructs 30 DELETE deletes node and relations. Ex: MATCH ✭ a{name ✿ "Eve"} ✮ DELETE a REMOVE removes labels or properties. Ex: MATCH ✭ a{name ✿ "Charlie"} ✮ REMOVE a ✿ Admin,a ✳ name WITH allows to perform aggregations. Ex: MATCH ✭ a ✮✲❬✿ FOLLOWS ❪✲❃✭ b ✮ WITH a, count ✭ b ✮ as c ORDER BY limits size of table. Ex: MATCH ✭ a ✿ User ✮ ORDER BY a ✳ name LIMIT 1
Outline 31 1 Introduction 2 Property graphs 3 Regular Path Queries 4 Cypher by example 5 Principles of the semantics 6 Towards a standard language for querying property graphs
Modelling Tables 31 Record (table row) A record is a partial function from variables to values. Example: ( x �→ "Bob" ; y �→ 1 )
Modelling Tables 31 Record (table row) A record is a partial function from variables to values. Example: ( x �→ "Bob" ; y �→ 1 ) Table A table is a multi-set (or bag) of records with the same domain. Example: x y "Bob" 1 999 "Alice" 1 "Bob"
Modelling Tables 31 Record (table row) A record is a partial function from variables to values. Example: ( x �→ "Bob" ; y �→ 1 ) Table A table is a multi-set (or bag) of records with the same domain. Example: x x y y "Bob" 1 999 "Alice" = 999 1 "Alice" "Bob" 1 1 "Bob" "Bob"
Semantics brackets – Read-Only 32 G : a graph Semantics of expressions � � � � · u , G : expression �−→ value (where u is a record) Semantics of clauses � � � � · G : clause �−→ (function: Tables → Tables) Semantics of queries � � � � · G : query �−→ (function: Tables → Tables) output : (Graphs × Queries) �−→ Tables
Principle of Read-Only Semantics 33 G : a graph Q : a query To compute the output of Q Q is a sequence of clauses Q = C 1 C 2 · · · C n
Principle of Read-Only Semantics 33 G : a graph Q : a query To compute the output of Q Q is a sequence of clauses Q = C 1 C 2 · · · C n � � � � � � � � � � � � Compute C 1 C 2 C n G , G , . . . , G
Principle of Read-Only Semantics 33 G : a graph Q : a query To compute the output of Q Q is a sequence of clauses Q = C 1 C 2 · · · C n � � � � � � � � � � � � Compute C 1 C 2 C n G , G , . . . , G � � � � � � � � � � � � � � � � Let Q C n G ◦ · · · ◦ C 2 G ◦ C 1 G = G
Principle of Read-Only Semantics 33 G : a graph Q : a query To compute the output of Q Q is a sequence of clauses Q = C 1 C 2 · · · C n � � � � � � � � � � � � Compute C 1 C 2 C n G , G , . . . , G � � � � � � � � � � � � � � � � Let Q C n G ◦ · · · ◦ C 2 G ◦ C 1 G = G � � � � � � output ( G , Q ) = Q T unit G where T unit is the 1-line 0-column table.
Excerpt of Read-Only semantics (2) 34 � � � � � � � � � � � � � WHERE e G ( T ) = u ∈ T e G , u = true � � � � � � { u · u ′ | u ′ ∈ match ( ¯ MATCH ¯ G ( T ) = π, G , u )} π u ∈ T � � � � � � � � �� � � � � G ( T ) = G ( T ) MATCH ¯ π WHERE e WHERE e MATCH ¯ π � � � � OPTIONAL MATCH ¯ π WHERE e G ( T ) � � � � � � � � � � G ({ u }) if G ({ u }) � ∅ MATCH ¯ π WHERE e MATCH ¯ π WHERE e = ( u , ( free ( u , ¯ π ) : null )) otherwise u ∈ T � � � � � � � � OPTIONAL MATCH ¯ G ( T ) = OPTIONAL MATCH ¯ π WHERE true G ( T ) π
Excerpt of Read-Only semantics (2) 35 � � � � G ( T ) = T if T has at least one column WITH ∗ � � � � WITH ∗ , e 1 [ AS a 1 ] ,. . ., e m [ AS a m ] G ( T ) = � � � � WITH b 1 AS b 1 ,. . ., b q AS b q , e 1 [ AS a 1 ] ,. . ., e m [ AS a m ] G ( T ) � � � � WITH e 1 [ AS a 1 ] ,. . ., e m [ AS a m ] G ( T ) = � � � � � � � � � � � ( a ′ G , u ,. . ., a ′ G , u ) e 1 e m 1 : m : u ∈ T � � � � � � UNWIND e AS a G ( T ) = {( u , a : v )} , u ∈ T v ∈ E u � � � � � 0 ≤ i < m { v i } if G , u = list ( v 0 ,. . ., v m − 1 ) e � � � � {} if e G , u = list () with E u = �� � � � � otherwise e G , u
Semantics brackets – Read-Write 36 Semantics of expressions: (Nothing changes) � � � � · u , G : expression �−→ value (where u is a record) Semantics of clauses: � � � � · : clause �−→ (function: (Graphs × Tables) → (Graphs × Tables)) Semantics of queries: � � � � · : query �−→ (function: (Graphs × Tables) → (Graphs × Tables)) output : (Graphs × Queries) �−→ (Graphs × Tables) (Computed just like RO → composition of clause semantics)
Desirable properties of the semantics at Clause-level 37 Atomicity: Each clause is executed as a single unit Consistency: Each clause should on valid Graph/Table pair General scheme of the semantics if a clause is: 1 Ensure that the input Graph/Table is valid w.r.t. clause 2 Compute output Table and all changes to graph 3 Apply all changes to Graph 4 Ensure validity of output Graph/Table If any fails, semantics is undefined.
Desirable properties of the semantics at Clause-level 37 Atomicity: Each clause is executed as a single unit Consistency: Each clause should on valid Graph/Table pair General scheme of the semantics if a clause is: 1 Ensure that the input Graph/Table is valid w.r.t. clause 2 Compute output Table and all changes to graph 3 Apply all changes to Graph 4 Ensure validity of output Graph/Table If any fails, semantics is undefined. In Neo4j, Atomicity and Consistency are verified at query level only.
In Neo4j, SET violate Atomicity 38 User , Admin Query: User name :"Charlie" MATCH ✭ m1 ✮✲❬✿ ANSWERS ❪✲❃✭ m2 ✮ r 8 SET m1 ✳ id ❂ m2 ✳ id, N 6 N 3 follows m2 ✳ id ❂ m1 ✳ id r 4 r 3 User User follows Table before SET clause: name :"Alice" name :"Bob" r 2 m1 m2 N 1 N 2 r 1 N 5 N 4 posted posted r 5 follows r 6 on :"05-14" on :"05-15" N 4 r 7 N 5 answers answers Message Message id :22 id :22 id :25 id :25 text :"Hello" text :"World"
In Neo4j, SET violate Atomicity 38 User , Admin Query: User name :"Charlie" MATCH ✭ m1 ✮✲❬✿ ANSWERS ❪✲❃✭ m2 ✮ r 8 SET m1 ✳ id ❂ m2 ✳ id, N 6 N 3 follows m2 ✳ id ❂ m1 ✳ id r 4 r 3 User User follows Table before SET clause: name :"Alice" name :"Bob" r 2 m1 m2 N 1 N 2 r 1 N 5 N 4 posted posted r 5 follows r 6 on :"05-14" on :"05-15" Neo4j sets both id to 25. N 4 r 7 N 5 Semantics exchange id values answers answers Message Message id :22 id :22 id :25 id :25 text :"Hello" text :"World"
Recommend
More recommend