Formal Specification of Cypher Nadime Francis University of - - PowerPoint PPT Presentation

formal specification of cypher
SMART_READER_LITE
LIVE PREVIEW

Formal Specification of Cypher Nadime Francis University of - - PowerPoint PPT Presentation

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases Formal Specification of Cypher Nadime Francis University of Edinburgh Wednesday, May, 10th 1 / 16 Semantics Overview Ambiguous and Edge Cases Incomplete and


slide-1
SLIDE 1

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Formal Specification of Cypher

Nadime Francis

University of Edinburgh

Wednesday, May, 10th

1 / 16

slide-2
SLIDE 2

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Property Graphs

Person, Postdoc name : ‘Nadime’ institute : ‘UoE’ Person, Professor name : ‘Leonid’ institute : ‘UoE’ knows since : 2010 colleague since : 2015

A property graph is a tuple G = (N, R, s, t, ι, λ, τ), where: N ⊆ N: finite set of nodes R ⊆ R: finite set of relationships s : R → N: maps each relationship to its source t : R → N: maps each relationship to its target ι : (N ∪ R) × K → V: maps each x and k to x.k. λ : N → 2L: associates a set of label to each node τ : R → T : associates a type to each relationship

2 / 16

slide-3
SLIDE 3

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Records and Tables

A record is a tuple with named fields : (a1 : v1, . . . , an : vn). A table is a bag of uniform records. Example: (a : 1, b : 3), (a : ‘oCIM 2’, b : ‘London’), (a : ‘oCIM’, b : ‘Walldorf’), (a : 1, b : 3)

  • a

b 1 3 ‘oCIM 2’ ‘London’ ‘oCIM’ ‘Walldorf’ 1 3 = a b ‘oCIM’ ‘Walldorf’ 1 3 ‘oCIM 2’ ‘London’ 1 3

3 / 16

slide-4
SLIDE 4

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Operations and Expressions

An Example

◮ MATCH (n : Person) − [: knows]−> (m : Person) WHERE n.institute = m.institute RETURN n.name, m.name, n.institute AS institute

4 / 16

slide-5
SLIDE 5

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Operations and Expressions

An Example

◮ MATCH (n : Person) − [: knows]−> (m : Person) WHERE n.institute = m.institute RETURN n.name, m.name, n.institute AS institute

  • 4 / 16
slide-6
SLIDE 6

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Operations and Expressions

An Example

◮ MATCH (n : Person) − [: knows]−> (m : Person) WHERE n.institute = m.institute RETURN n.name, m.name, n.institute AS institute

n m {name : ‘Nadime’, institute : ‘UoE’} {name : ‘Leonid’, institute : ‘UoE’} {name : ‘Paolo’, institute : ‘UoE’} {name : ‘Nadime’, institute : ‘UoE’} {name : ‘Nadime’, institute : ‘UoE’} {name : ‘Stefan’, institute : ‘Neo’} {name : ‘Alastair’, institute : ‘Neo’} {name : ‘Stefan’, institute : ‘Neo’}

4 / 16

slide-7
SLIDE 7

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Operations and Expressions

An Example

MATCH (n : Person) − [: knows]−> (m : Person) ◮ WHERE n.institute = m.institute RETURN n.name, m.name, n.institute AS institute

n m {name : ‘Nadime’, institute : ‘UoE’} {name : ‘Leonid’, institute : ‘UoE’} {name : ‘Paolo’, institute : ‘UoE’} {name : ‘Nadime’, institute : ‘UoE’} {name : ‘Alastair’, institute : ‘Neo’} {name : ‘Stefan’, institute : ‘Neo’}

4 / 16

slide-8
SLIDE 8

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Operations and Expressions

An Example

MATCH (n : Person) − [: knows]−> (m : Person) WHERE n.institute = m.institute ◮ RETURN n.name, m.name, n.institute AS institute

n.name m.name institute ‘Nadime’ ‘Leonid’ UoE ‘Paolo’ ‘Nadime’ UoE ‘Alastair’ ‘Stefan’ Neo

4 / 16

slide-9
SLIDE 9

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Operations and Expressions

Q = (α) MATCH (n : Person) − [: knows]−> (m : Person) (β) WHERE n.institute = m.institute (γ) RETURN n.name, m.name, n.institute AS institute

5 / 16

slide-10
SLIDE 10

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Operations and Expressions

Q = (α) MATCH (n : Person) − [: knows]−> (m : Person) (β) WHERE n.institute = m.institute (γ) RETURN n.name, m.name, n.institute AS institute Operations [ [op] ]G : Tables → Tables Semantics of a query by composition Ex: [ [Q] ]G = [ [α] ]G ◦ [ [β] ]G ◦ [ [γ] ]G Answers to Q on G: [ [Q] ]G({})

5 / 16

slide-11
SLIDE 11

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Operations and Expressions

Q = (α) MATCH (n : Person) − [: knows]−> (m : Person) (β) WHERE n.institute = m.institute (γ) RETURN n.name, m.name, n.institute AS institute Operations [ [op] ]G : Tables → Tables Semantics of a query by composition Ex: [ [Q] ]G = [ [α] ]G ◦ [ [β] ]G ◦ [ [γ] ]G Answers to Q on G: [ [Q] ]G({}) Expressions [ [exp] ]G,u ∈ V where u is a record, giving binding to variables Ex: [ [β] ]G(T) =

  • u ∈ T | [

[n.institute = m.institute] ]G,u = true

  • 5 / 16
slide-12
SLIDE 12

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Pattern Matching

Rigid pattern satisfaction Rigid path pattern: no variable length edge patterns. Ex: (n : Person) − [: knows ∗ 2]−> () − [: likes]−> (m : Movie) Unique way for a path p to satisfy a rigid pattern π wrt G, u. Notation: (p, G, u) | = π

6 / 16

slide-13
SLIDE 13

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Pattern Matching

Rigid pattern satisfaction Rigid path pattern: no variable length edge patterns. Ex: (n : Person) − [: knows ∗ 2]−> () − [: likes]−> (m : Movie) Unique way for a path p to satisfy a rigid pattern π wrt G, u. Notation: (p, G, u) | = π Variable-length paths and free variables rigid(π) = {π′ | π′ is rigid and π ⊐ π′} Ex: () − [∗2]−> () − [∗4]−> () ⊏ () − [∗1..3]−> () − [∗]−> () free(π, u): all names that occur in π and not in u

6 / 16

slide-14
SLIDE 14

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Pattern Matching

Rigid pattern satisfaction Rigid path pattern: no variable length edge patterns. Ex: (n : Person) − [: knows ∗ 2]−> () − [: likes]−> (m : Movie) Unique way for a path p to satisfy a rigid pattern π wrt G, u. Notation: (p, G, u) | = π Variable-length paths and free variables rigid(π) = {π′ | π′ is rigid and π ⊐ π′} Ex: () − [∗2]−> () − [∗4]−> () ⊏ () − [∗1..3]−> () − [∗]−> () free(π, u): all names that occur in π and not in u [ [MATCH π] ]G(T) =

  • π′∈rigid(π)

u∈T, p∈paths

  • (u, u′)
  • u′ is uniform with free(π′, u)

and (p, G, (u, u′)) | = π′

  • 6 / 16
slide-15
SLIDE 15

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Ambiguous and Edge Cases

7 / 16

slide-16
SLIDE 16

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Nulls in Patterns

MATCH (n : Person {name : null}) RETURN (n)

8 / 16

slide-17
SLIDE 17

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Nulls in Patterns

MATCH (n : Person {name : null}) RETURN (n)

1 Every node n with a name property? 2 Every node n such that n.name IS NULL = true? 3 Nothing? 8 / 16

slide-18
SLIDE 18

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Nulls in Patterns

MATCH (n : Person {name : null}) RETURN (n)

1 Every node n with a name property? 2 Every node n such that n.name IS NULL = true? 3 Nothing!

Because Q is actually equivalent to: MATCH (n : Person) WHERE n.name = null RETURN (n)

8 / 16

slide-19
SLIDE 19

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Map Comparisons

When does {k1 : v1, . . . , kn : vn} = {ℓ1 : w1, . . . , ℓm : wm} return true, false or null? {name : null} = {} {name : null} = {name : null} {a : 1, b : 2} = {b : 2, a : 1} {a : 1, a : 2} = {a : 2}

9 / 16

slide-20
SLIDE 20

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Map Comparisons

When does {k1 : v1, . . . , kn : vn} = {ℓ1 : w1, . . . , ℓm : wm} return true, false or null? false {name : null} = {} true {name : null} = {name : null} true {a : 1, b : 2} = {b : 2, a : 1} true {a : 1, a : 2} = {a : 2} Neither purely syntactic, nor ∀k, m1.k = m2.k.

9 / 16

slide-21
SLIDE 21

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Setting Properties using a Map

WITH {name : null} AS map CREATE (n) SET n = map RETURN (n)

10 / 16

slide-22
SLIDE 22

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Setting Properties using a Map

WITH {name : null} AS map CREATE (n) SET n = map RETURN (n) Returns n as {}. The property map of n is not equal to the map it was set to. In particular, n {.∗} = map returns false.

10 / 16

slide-23
SLIDE 23

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

MATCH with no Free Variables

MATCH () RETURN ∗ MATCH () RETURN 1

11 / 16

slide-24
SLIDE 24

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

MATCH with no Free Variables

Fail MATCH () RETURN ∗ RETURN ∗ is not allowed with no variable in scope. Pass MATCH () RETURN 1 Returns as many copies of 1 as nodes in the database. After MATCH (), the active table is a bag containing multiple copies

  • f the empty record.

11 / 16

slide-25
SLIDE 25

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Incomplete and Inconsistent Cases

12 / 16

slide-26
SLIDE 26

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Repeating UNWINDs

UNWIND [1, 2, 3] AS r UNWIND r AS s RETURN s UNWIND [[1, 2], 3] AS r UNWIND r AS s RETURN s

13 / 16

slide-27
SLIDE 27

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Repeating UNWINDs

Fail UNWIND [1, 2, 3] AS r UNWIND r AS s RETURN s Type mismatch, expected List but was Integer. Pass UNWIND [[1, 2], 3] AS r UNWIND r AS s RETURN s Returns a column with 1, 2 and 3 as rows.

13 / 16

slide-28
SLIDE 28

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Repeating UNWINDs

Fail UNWIND [1, 2, 3] AS r UNWIND r AS s RETURN s Type mismatch, expected List but was Integer. Pass UNWIND [[1, 2], 3] AS r UNWIND r AS s RETURN s Returns a column with 1, 2 and 3 as rows. UNWIND [[1, 2], 3] AS r UNWIND r AS s UNWIND s AS t UNWIND t AS u RETURN u Actually works, and returns a column with 1, 2 and 3 as rows.

13 / 16

slide-29
SLIDE 29

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Violating Cyphermorphism

Q0 = MATCH (x) − [r] − (y) − [r] − (z) RETURN x, y, z

14 / 16

slide-30
SLIDE 30

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Violating Cyphermorphism

Q0 = MATCH (x) − [r] − (y) − [r] − (z) RETURN x, y, z Error: cannot use the same relationship variable ‘r’ for multiple patterns.

14 / 16

slide-31
SLIDE 31

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Violating Cyphermorphism

Q0 = MATCH (x) − [r] − (y) − [r] − (z) RETURN x, y, z Error: cannot use the same relationship variable ‘r’ for multiple patterns. Q1 = MATCH (x) − [r∗] − (y) − [r∗] − (z) RETURN x, y, z

14 / 16

slide-32
SLIDE 32

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Violating Cyphermorphism

Q0 = MATCH (x) − [r] − (y) − [r] − (z) RETURN x, y, z Error: cannot use the same relationship variable ‘r’ for multiple patterns. Q1 = MATCH (x) − [r∗] − (y) − [r∗] − (z) RETURN x, y, z Works and enforces the paths from x to y and from y to z to use the same sequence of relationships, violating Cyphermorphism.

14 / 16

slide-33
SLIDE 33

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Violating Cyphermorphism

Q0 = MATCH (x) − [r] − (y) − [r] − (z) RETURN x, y, z Error: cannot use the same relationship variable ‘r’ for multiple patterns. Q1 = MATCH (x) − [r∗] − (y) − [r∗] − (z) RETURN x, y, z Works and enforces the paths from x to y and from y to z to use the same sequence of relationships, violating Cyphermorphism. It is not included in the query Q2 below: Q1 = MATCH (x) − [r∗] − (y) − [s∗] − (z) RETURN x, y, z

14 / 16

slide-34
SLIDE 34

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Two Small Issues: Nulls as Indices and Keys, and Naming

RETURN 1 AS ‘0‘, 0

15 / 16

slide-35
SLIDE 35

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Two Small Issues: Nulls as Indices and Keys, and Naming

Fail RETURN 1 AS ‘0‘, 0 Multiple result columns with the same name are not supported. Need to specify how expression naming is handled.

15 / 16

slide-36
SLIDE 36

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Two Small Issues: Nulls as Indices and Keys, and Naming

Fail RETURN 1 AS ‘0‘, 0 Multiple result columns with the same name are not supported. Need to specify how expression naming is handled. [1, 2, 3][null] [1, 2, 3][null..4] {name : ‘Nadime’} [null]

15 / 16

slide-37
SLIDE 37

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Two Small Issues: Nulls as Indices and Keys, and Naming

Fail RETURN 1 AS ‘0‘, 0 Multiple result columns with the same name are not supported. Need to specify how expression naming is handled. Fail [1, 2, 3][null] [1, 2, 3][null..4] {name : ‘Nadime’} [null] No error, never terminates.

15 / 16

slide-38
SLIDE 38

Semantics Overview Ambiguous and Edge Cases Incomplete and Inconsistent Cases

Thank you!

16 / 16