Formal semantics of Cypher: towards a standard language for querying - - PowerPoint PPT Presentation

formal semantics of cypher
SMART_READER_LITE
LIVE PREVIEW

Formal semantics of Cypher: towards a standard language for querying - - PowerPoint PPT Presentation

Formal semantics of Cypher: towards a standard language for querying property graphs N. Francis 1 A. Green 2 M. Rydberg 2 P. Guagliardo 3 V. Marsault 1 T. Lindaaker 2 P. Selmer 2 L. Libkin 3 S. Plantikow 2 A. Taylor 2 M. Schuster 3 1. Univ.


slide-1
SLIDE 1

Formal semantics of Cypher:

towards a standard language for querying property graphs

  • N. Francis 1
  • V. Marsault 1
  • A. Green 2
  • T. Lindaaker 2
  • S. Plantikow 2
  • M. Rydberg 2
  • P. Selmer 2
  • A. Taylor 2
  • P. Guagliardo 3
  • L. Libkin 3
  • M. Schuster 3
  • 1. Univ. Paris-Est Marne-la-

Vall´ ee, ENPC, ESIEE, CNRS

  • 2. Neo Technology
  • 3. University of Edinburgh

GT Alga Inria Nord Europe, Lille 2018-10-15

slide-2
SLIDE 2

Outline

1

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

slide-3
SLIDE 3

Representing data as graphs

1

Most databases use the relational model Relational algebra in theory The language SQL in practice

slide-4
SLIDE 4

Representing data as graphs

1

Most databases use the relational model Relational algebra in theory The language SQL in practice Some data have intrinsically the structure of graphs: Semantic web Social Networks Bioinformatic networks Native representation of data as graphs allows: Efficient algorithms on graphs Pattern matching Optimisations

slide-5
SLIDE 5

More and more ways to manipulate data as graphs

2 Data model

Property graphs, RDF

Query languages

Cypher, Gremlin, PGQL, SPARQL, G-Core

Engines

JanusGraph, Jena, Neo4j, Virtuoso

Domain

Fraud detection, Investigative journalism

slide-6
SLIDE 6

More and more ways to manipulate data as graphs

2 Data model

Property graphs Property graphs, RDF

Query languages

Cypher Cypher, Gremlin, PGQL PGQL, SPARQL, G-Core G-Core

Engines

JanusGraph, Jena, Neo4j Neo4j, Virtuoso

Domain

Fraud detection, Investigative journalism

slide-7
SLIDE 7

Cypher

3

Language for querying and updating property graphs Invented by Neo Technology Originally, part of engine Neo4j → commercial success Now, in multiple datagraph engines (e.g., SAP HANA Graph, Redis Graph, Agens Graph)

slide-8
SLIDE 8

Cypher

3

Language for querying and updating property graphs Invented by Neo Technology Originally, part of engine Neo4j → commercial success Now, in multiple datagraph engines (e.g., SAP HANA Graph, Redis Graph, Agens Graph)

The openCypher project

Since 2015 Seeks to standardise Cypher (SQL for property graphs?) Community-led evolution Complete specification

slide-9
SLIDE 9

Short term goal

Full denotational semantics for the language Cypher. Industrial partnership Neo4j/University of Edinburgh Reverse engineering and formalisation from Neo4j Done semantics of the “core fragment’

[Francis et al’18]

Soon: semantics of the “update clauses

slide-10
SLIDE 10

Short term goal

Full denotational semantics for the language Cypher. Industrial partnership Neo4j/University of Edinburgh Reverse engineering and formalisation from Neo4j Done semantics of the “core fragment’

[Francis et al’18]

Soon: semantics of the “update clauses

Long term goal

Design a standard language for querying property graphs: GQL. Merging Cypher, PGQL, G-Core. Involvement of Neo Technology, Oracle and LDBC.

slide-11
SLIDE 11

Outline

5

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

slide-12
SLIDE 12

Property graph

5

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Nodes : N1, N2,· · · , N5

slide-13
SLIDE 13

Property graph

5

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Nodes : N1, N2,· · · , N5 Relationships : r1,r2,· · · ,r7

slide-14
SLIDE 14

Property graph

5

N1 User User name:"Alice" N2 User User name:"Bob" N3 User User , Admin Admin name:"Charlie" N4 Message Message id:22 text:"Hello" N5 Message Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Nodes : N1, N2,· · · , N5 Relationships : r1,r2,· · · ,r7 Labels Labels (de nœuds) : User Message

slide-15
SLIDE 15

Property graph

5

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows follows r2 r3 r4 r5 posted posted

  • n:"05-14"

r6 posted posted

  • n:"05-15"

r7 answers answers r8 follows follows follows

Nodes : N1, N2,· · · , N5 Relationships : r1,r2,· · · ,r7 Labels (de nœuds) : User Message Types Types (of relationships) : follows posted answers

slide-16
SLIDE 16

Property graph

5

N1 User name:"Alice" name:"Alice" N2 User name:"Bob" name:"Bob" N3 User , Admin name:"Charlie" name:"Charlie" N4 Message id:22 id:22 text:"Hello" text:"Hello" N5 Message id:25 id:25 text:"World" text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"
  • n:"05-14"

r6 posted

  • n:"05-15"
  • n:"05-15"

r7 answers r8 follows follows

Nodes : N1, N2,· · · , N5 Relationships : r1,r2,· · · ,r7 Labels (de nœuds) : User Message Types (of relationships) : follows posted answers Properties Properties (i.e. Key/Value pairs) : name:"Alice" id:22 text:"Hello"

slide-17
SLIDE 17

Outline

6

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

slide-18
SLIDE 18

Data model for theoretical query languages

6

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Graph database

Relation bear types Node do not bear types (could be simulated) Neither bears property

slide-19
SLIDE 19

Data model for theoretical query languages

6

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Graph database

Relation bear types Node do not bear types (could be simulated) Neither bears property

slide-20
SLIDE 20

Data model for theoretical query languages

6

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Graph database

Relation bear types Node do not bear types (could be simulated) Neither bears property Finite number of relation types (and node types) → “Dataless graph”

slide-21
SLIDE 21

Regular Path Query (RPQ) – Definition

7

A: finite alphabet (of relation types) N: nodes in the graph Definition (RPQ R): R = (x, E, y) E : regular expr. over A x, y : two variables Example: x y (a + b)∗ Definition (Answer to R): Set of the functions F : {x, y} → N , ∃u ∈ E, F(x)

u

− − → F(y)

slide-22
SLIDE 22

Regular Path Query (RPQ) – Example 1

8

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

x y

POSTED.(ANSWERS)∗

Answers: F1 : x → N1 y → N4 F2 : x → N2 y → N5 F3 : x → N2 y → N4

slide-23
SLIDE 23

Regular Path Query (RPQ) – Example 1

8

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

x y

POSTED.(ANSWERS)∗

Answers: F1 : x → N1 y → N4 F2 : x → N2 y → N5 F3 : x → N2 y → N4

slide-24
SLIDE 24

Regular Path Query (RPQ) – Example 1

8

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

x y

POSTED.(ANSWERS)∗

Answers: F1 : x → N1 y → N4 F2 : x → N2 y → N5 F3 : x → N2 y → N4

slide-25
SLIDE 25

Regular Path Query (RPQ) – Example 1

8

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted posted

  • n:"05-15"

r7 answers answers r8 follows follows

Query:

x y

POSTED.(ANSWERS)∗

Answers: F1 : x → N1 y → N4 F2 : x → N2 y → N5 F3 : x → N2 y → N4

slide-26
SLIDE 26

Regular Path Query (RPQ) – Example 1

8

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

x y

POSTED.(ANSWERS)∗

Answers: F1 : x → N1 y → N4 F2 : x → N2 y → N5 F3 : x → N2 y → N4

slide-27
SLIDE 27

Regular Path Query (RPQ) – Example 2

9

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

x y

(FOLLOWS)∗

slide-28
SLIDE 28

Regular Path Query (RPQ) – Example 2

9

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows follows

Query:

x y

(FOLLOWS)∗

slide-29
SLIDE 29

Regular Path Query (RPQ) – Example 2

9

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

x y

(FOLLOWS)∗

Answers: F1 : x → N1 y → N1 F2 : x → N1 y → N2 F3 : x → N1 y → N3 . . . . . . . . . F9 : x → N3 y → N3

slide-30
SLIDE 30

Regular Path Query (RPQ) – Example 2

9

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

x y

(FOLLOWS)∗

Answers: F1 : x → N1 y → N1 F2 : x → N1 y → N2 F3 : x → N1 y → N3 . . . . . . . . . F9 : x → N3 y → N3

slide-31
SLIDE 31

Regular Path Query (RPQ) – Example 2

9

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows follows

Query:

x y

(FOLLOWS)∗

Answers: F1 : x → N1 y → N1 F2 : x → N1 y → N2 F3 : x → N1 y → N3 . . . . . . . . . F9 : x → N3 y → N3

slide-32
SLIDE 32

Regular Path Query (RPQ) – Example 2

9

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows follows

Query:

x y

(FOLLOWS)∗

Answers: F1 : x → N1 y → N1 F2 : x → N1 y → N2 F3 : x → N1 y → N3 . . . . . . . . . F9 : x → N3 y → N3

slide-33
SLIDE 33

Regular Path Query (RPQ) – Example 2

9

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

x y

(FOLLOWS)∗

Answers: F1 : x → N1 y → N1 F2 : x → N1 y → N2 F3 : x → N1 y → N3 . . . . . . . . . F9 : x → N3 y → N3 → ∞-many path realise F1 → RPQ follows set-semantics

slide-34
SLIDE 34

Conjunction of RPQs (CRPQ) – Definition

10

A: alphabet (of relation types) N: nodes in the graph Definition (a CRPQ C): C = (R1 ∧ R2 ∧ · · · ∧ Rn) where R1,, . . ., Rn are RPQs Example:

x y z (a + b)∗ (ab)∗ c

Answer to C: Set of the functions F : var(C) → N such that ∀i, F|var(Ri) is an answer to Ri

slide-35
SLIDE 35

Conjunction of RPQs (CRPQ) – Example

11

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query: x y z

POSTED (ANSWERS)∗

Answers: x y z → → → F1 : N1 N4 N4 F2 : N2 N5 N4 F3 : N2 N5 N5

slide-36
SLIDE 36

Union of CRPQs (UCRPQ) – Defintion

12

A: alphabet (of relation types) N: nodes in the graph Definition (UCRPQ Q) Q = (C1 ∪ C2 ∪ · · · ∪ Cn) where C1, C2, . . ., Cn are CRPQs Answer to Q: Set of partial functions: var(C1) ∪ · · · ∪ var(Cn) → N

n

  • i=1

Fi , where,∀i, Fi is the answer to Ci.

slide-37
SLIDE 37

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

slide-38
SLIDE 38

Evaluating a Cypher query

13

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Example of Cypher query:

MATCH ✭u1✮✲❬p1✿POSTED❪✲❃✭m1✮ WITH u1, p1, m1✳text AS t1 WHERE t1 ❂ "Hello"

A Cypher statement

is a sequence of clauses

slide-39
SLIDE 39

Evaluating a Cypher query

13

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Example of Cypher query:

MATCH ✭u1✮✲❬p1✿POSTED❪✲❃✭m1✮ WITH u1, p1, m1✳text AS t1 WHERE t1 ❂ "Hello"

A Cypher statement

is a sequence of clauses queries a graph returns a table

slide-40
SLIDE 40

Matching nodes (1)

14

N1 User User name:"Alice" N2 User User name:"Bob" N3 User User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1✿User✮

slide-41
SLIDE 41

Matching nodes (1)

14

N1 User User name:"Alice" N2 User User name:"Bob" N3 User User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1✿User✮

Result: u1 N1 N2 N3

slide-42
SLIDE 42

Matching nodes (2)

15

N1 User name:"Alice" N2 User name:"Bob" N3 User User , Admin Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1✿User✿Admin✮

Result: u1 N3

slide-43
SLIDE 43

Matching nodes (3)

16

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1{id✿22}✮

Result: u1 N4

slide-44
SLIDE 44

Matching relations (1)

17

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭✮✲❬p1❪✲❃✭✮

Result: p1 r1 r2 r3 r4 r5 r6 r7

slide-45
SLIDE 45

Matching relation (2)

18

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted posted

  • n:"05-14"

r6 posted posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1✮✲❬p1✿POSTED❪✲❃✭m1✮

Result: u1 p1 m1 N1 r5 N4 N2 r6 N5

slide-46
SLIDE 46

Matching relationships (3)

19

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows follows

Query:

MATCH ✭u1✮✲❬✿FOLLOWS❪✲❃✭✮

Result: u1 N1 N2 N2 N3 Cypher has bag semantics: N2 has two outgoing follows relations ⇒ two lines N2

slide-47
SLIDE 47

Matching paths (1)

20

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows follows

Query:

MATCH ✭u1✿Admin✮ ✲❬l1✿FOLLOWS*❪✲❃✭m1✮

Result: u1 l1 m1 N3 [r4] N1 N3 [r4,r1] N2 N3 [r4,r1,r2] N1 N3 [r4,r1,r3] N3

slide-48
SLIDE 48

Matching paths (1)

20

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows follows

Query:

MATCH ✭u1✿Admin✮ ✲❬l1✿FOLLOWS*❪✲❃✭m1✮

Result: u1 l1 m1 N3 [r4] N1 N3 [r4,r1] N2 N3 [r4,r1,r2] N1 N3 [r4,r1,r3] N3

slide-49
SLIDE 49

Matching paths (1)

20

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows follows

Query:

MATCH ✭u1✿Admin✮ ✲❬l1✿FOLLOWS*❪✲❃✭m1✮

Result: u1 l1 m1 N3 [r4] N1 N3 [r4,r1] N2 N3 [r4,r1,r2] N1 N3 [r4,r1,r3] N3

slide-50
SLIDE 50

Matching paths (1)

20

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows follows

Query:

MATCH ✭u1✿Admin✮ ✲❬l1✿FOLLOWS*❪✲❃✭m1✮

Result: u1 l1 m1 N3 [r4] N1 N3 [r4,r1] N2 N3 [r4,r1,r2] N1 N3 [r4,r1,r3] N3

slide-51
SLIDE 51

Matching paths (1)

20

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows follows

Query:

MATCH ✭u1✿Admin✮ ✲❬l1✿FOLLOWS*❪✲❃✭m1✮

Result: u1 l1 m1 N3 [r4] N1 N3 [r4,r1] N2 N3 [r4,r1,r2] N1 N3 [r4,r1,r3] N3

slide-52
SLIDE 52

Matching paths (1)

20

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1✿Admin✮ ✲❬l1✿FOLLOWS*❪✲❃✭m1✮

Result: u1 l1 m1 N3 [r4] N1 N3 [r4,r1] N2 N3 [r4,r1,r2] N1 N3 [r4,r1,r3] N3 Cypher-Morphism Each rel. matched ≤ 1 time ⇒ Finitely many results

slide-53
SLIDE 53

Matching paths (2)

21

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1✮✲❬✿FOLLOWS❪✲❃✭✮ ✲❬✿POSTED❪✲❃✭m1✮

Result: u1 m1 N1 N5 N2 N4 N3 N5

slide-54
SLIDE 54

Matching paths (2)

21

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1✮✲❬✿FOLLOWS❪✲❃✭✮ ✲❬✿POSTED❪✲❃✭m1✮

Result: u1 m1 N1 N5 N2 N4 N3 N5

slide-55
SLIDE 55

Chaining clauses

22

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1✮✲❬✿POSTED❪✲❃✭m1✮ MATCH ✭u2✮❁✲❬✿FOLLOWS❪✲✭u1✮ ✲❬✿FOLLOWS❪✲❃✭u3✮

slide-56
SLIDE 56

Chaining clauses

22

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1✮✲❬✿POSTED❪✲❃✭m1✮ MATCH ✭u2✮❁✲❬✿FOLLOWS❪✲✭u1✮ ✲❬✿FOLLOWS❪✲❃✭u3✮

Table after first MATCH:

u1 m1 N1 N4 N2 N5

slide-57
SLIDE 57

Chaining clauses

22

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1 u1✮✲❬✿POSTED❪✲❃✭m1✮ MATCH ✭u2✮❁✲❬✿FOLLOWS❪✲✭u1 u1✮ ✲❬✿FOLLOWS❪✲❃✭u3✮

Table after first MATCH:

u1 m1 N1 N4 N2 N5

Table after second MATCH:

u1 u1 m1 u2 u3 N1 N4 · · N2 N5 · ·

slide-58
SLIDE 58

Chaining clauses

22

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1 u1✮✲❬✿POSTED❪✲❃✭m1✮ MATCH ✭u2✮❁✲❬✿FOLLOWS❪✲✭u1 u1✮ ✲❬✿FOLLOWS❪✲❃✭u3✮

Table after first MATCH:

u1 m1 N1 N4 N2 N5

Table after second MATCH:

u1 u1 m1 u2 u3 N1 N4 · · N2 N5 · ·

slide-59
SLIDE 59

Chaining clauses

22

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1 u1✮✲❬✿POSTED❪✲❃✭m1✮ MATCH ✭u2✮❁✲❬✿FOLLOWS❪✲✭u1 u1✮ ✲❬✿FOLLOWS❪✲❃✭u3✮

Table after first MATCH:

u1 m1 N1 N4 N2 N5

Table after second MATCH:

u1 u1 m1 u2 u3 N1 N4 · · N2 N5 · ·

slide-60
SLIDE 60

Chaining clauses

22

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows follows

Query:

MATCH ✭u1 u1✮✲❬✿POSTED❪✲❃✭m1✮ MATCH ✭u2✮❁✲❬✿FOLLOWS❪✲✭u1 u1✮ ✲❬✿FOLLOWS❪✲❃✭u3✮

Table after first MATCH:

u1 m1 N1 N4 N2 N5

Table after second MATCH:

u1 u1 m1 u2 u3 N1 N4 · · N2 N5 · ·

slide-61
SLIDE 61

Chaining clauses

22

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows follows

Query:

MATCH ✭u1✮✲❬✿POSTED❪✲❃✭m1✮ MATCH ✭u2✮❁✲❬✿FOLLOWS❪✲✭u1✮ ✲❬✿FOLLOWS❪✲❃✭u3✮

Table after first MATCH:

u1 m1 N1 N4 N2 N5

Table after second MATCH:

u1 m1 u2 u3 N2 N5 N1 N3 N2 N5 N3 N1

slide-62
SLIDE 62

Column manipulation (WITH clause)

23

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted posted

  • n:"05-14"

r6 posted posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1✮✲❬p1✿POSTED❪✲❃✭m1✮ WITH u1, p1, m1.text AS t1

After the MATCH clause u1 p1 m1 N1 r5 N4 N2 r6 N5

slide-63
SLIDE 63

Column manipulation (WITH clause)

23

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1✮✲❬p1✿POSTED❪✲❃✭m1✮ WITH u1 u1, p1 p1, m1.text AS t1 t1

After the MATCH clause u1 u1 p1 p1 m1 N1 r5 N4 N2 r6 N5 Execution of the WITH clause u1 u1 p1 p1 t1 t1 N1 r5 N2 r6

slide-64
SLIDE 64

Column manipulation (WITH clause)

23

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1✮✲❬p1✿POSTED❪✲❃✭m1✮ WITH u1, p1, m1.text m1.text AS t1

After the MATCH clause u1 p1 m1 N1 r5 N4 N2 r6 N5 Execution of the WITH clause u1 p1 t1 N1 r5 N2 r6

slide-65
SLIDE 65

Column manipulation (WITH clause)

23

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1✮✲❬p1✿POSTED❪✲❃✭m1✮ WITH u1, p1, m1.text m1.text AS t1

After the MATCH clause u1 p1 m1 N1 r5 N4 N4 N2 r6 N5 Execution of the WITH clause u1 p1 t1 N1 r5 "Hello" "Hello" N2 r6

slide-66
SLIDE 66

Column manipulation (WITH clause)

23

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1✮✲❬p1✿POSTED❪✲❃✭m1✮ WITH u1, p1, m1.text AS t1

After the MATCH clause u1 p1 m1 N1 r5 N4 N2 r6 N5 N5 Execution of the WITH clause u1 p1 t1 N1 r5 "Hello" N2 r6 "World" "World"

slide-67
SLIDE 67

Column manipulation (WITH clause)

23

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1✮✲❬p1✿POSTED❪✲❃✭m1✮ WITH u1, p1, m1.text AS t1

After the MATCH clause u1 p1 m1 N1 r5 N4 N2 r6 N5 Final result u1 p1 t1 N1 r5 "Hello" N2 r6 "World"

slide-68
SLIDE 68

Line filtering (WHERE clause)

24

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1✮✲❬p1✿POSTED❪✲❃✭m1✮ WITH u1, p1, m1✳text AS t1 WHERE t1 ❂ "Hello"

After the WITH clause u1 p1 t1 N1 r5 "Hello" N2 r6 "World"

slide-69
SLIDE 69

Line filtering (WHERE clause)

24

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1✮✲❬p1✿POSTED❪✲❃✭m1✮ WITH u1, p1, m1✳text AS t1 WHERE t1 ❂ "Hello"

After the WITH clause u1 p1 t1 N1 r5 "Hello" N2 r6 "World" Execution of the WHERE clause u1 p1 t1 N1 r5 "Hello" N2 r6 "World"

slide-70
SLIDE 70

Line filtering (WHERE clause)

24

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭u1✮✲❬p1✿POSTED❪✲❃✭m1✮ WITH u1, p1, m1✳text AS t1 WHERE t1 ❂ "Hello"

After the WITH clause u1 p1 t1 N1 r5 "Hello" N2 r6 "World" Final result u1 p1 t1 N1 r5 "Hello"

slide-71
SLIDE 71

A last read-only example

25

N1 User name:"Alice" N2 User name:"Bob" name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭a{name✿"Bob"}✮ ✲❬*❪✲❃✭b{id✿22}✮ ❁✲❬*❪✲✭a✮

Question What does this computes ?

slide-72
SLIDE 72

A last read-only example

25

N1 User name:"Alice" N2 User name:"Bob" name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭a{name✿"Bob"}✮ ✲❬*❪✲❃✭b{id✿22}✮ ❁✲❬*❪✲✭a✮

Question What does this computes ? Answer The # of pairs of disjoint paths from N2 to N4.

slide-73
SLIDE 73

A last read-only example

25

N1 User name:"Alice" N2 User name:"Bob" name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭a{name✿"Bob"}✮ ✲❬*❪✲❃✭b{id✿22}✮ ❁✲❬*❪✲✭a✮

Question What does this computes ? Answer The # of pairs of disjoint paths from N2 to N4. ⇒ Evaluation of one constant MATCH is NP-HARD

slide-74
SLIDE 74

Node and relation creation (CREATE)

26

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭a{name✿"Charlie"}✮ CREATE ✭a✮✲❬✿FOLLOWS❪✲❃ ✭b✿User✮

Table after MATCH clause: a N3

slide-75
SLIDE 75

Node and relation creation (CREATE)

26

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows follows

Query:

MATCH ✭a{name✿"Charlie"}✮ CREATE ✭a✮✲❬✿FOLLOWS❪✲❃ ✭b✿User✮

Table after MATCH clause: a N3

slide-76
SLIDE 76

Node and relation creation (CREATE)

26

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭a{name✿"Charlie"}✮ CREATE ✭a✮✲❬✿FOLLOWS❪✲❃ ✭b✿User✮

Table after MATCH clause: a N3 Table after CREATE clause: a b N3 N6

slide-77
SLIDE 77

The example graph stored as CREATE clauses

27

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

CREATE ✭n1✿User{name✿"Alice"}✮, ✭n2✿User{name✿"Bob"}✮, ✭n3✿User✿Admin {name✿"Charlie"}✮, ✭n4✿Message {id✿22, text✿"Hello"}✮, ✭n5✿Message {id✿25, text✿"World"}✮ CREATE ✭n1✮✲❬✿FOLLOWS❪✲❃✭n2✮, ✭n1✮✲❬✿POSTED {on✿"05-04"}❪✲❃✭n4✮, ✭n2✮✲❬✿FOLLOWS❪✲❃✭n1✮, ✭n2✮✲❬✿FOLLOWS❪✲❃✭n3✮, ✭n2✮✲❬✿POSTED {on✿"05-04"}❪✲❃✭n5✮, ✭n3✮✲❬✿FOLLOWS❪✲❃✭n1✮, ✭n5✮✲❬✿ANSWERS❪✲❃✭n4✮,

slide-78
SLIDE 78

Node/Relation modification (SET clause)

28

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭a{name✿"Charlie"}✮ CREATE ✭a✮✲❬✿FOLLOWS❪✲❃ ✭b✿User✮ SET b✿Admin, b✳name❂"Eve"

Table after CREATE clause: a b N3 N6

slide-79
SLIDE 79

Node/Relation modification (SET clause)

28

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User , Admin Admin name:"Eve" name:"Eve" r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭a{name✿"Charlie"}✮ CREATE ✭a✮✲❬✿FOLLOWS❪✲❃ ✭b✿User✮ SET b✿Admin, b✳name❂"Eve"

Table after CREATE clause: a b N3 N6

slide-80
SLIDE 80

The MERGE clause : MATCH else CREATE

29

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Input table: a n N3 "Alice" N3 "Eve"

Query:

MERGE ✭a✮✲❬✿FOLLOWS❪✲❃ ✭b✿User {name✿n}✮

Output table: a n c N3 "Alice" N3 "Eve"

slide-81
SLIDE 81

The MERGE clause : MATCH else CREATE

29

N1 User User name:"Alice" name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows follows

Input table: a n N3 "Alice" N3 "Eve"

Query:

MERGE ✭a✮✲❬✿FOLLOWS❪✲❃ ✭b✿User {name✿n}✮

Output table: a n c N3 "Alice" N1 N3 "Eve"

slide-82
SLIDE 82

The MERGE clause : MATCH else CREATE

29

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User User name:"Eve" name:"Eve" r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows follows

Input table: a n N3 "Alice" N3 "Eve"

Query:

MERGE ✭a✮✲❬✿FOLLOWS❪✲❃ ✭b✿User {name✿n}✮

Output table: a n c N3 "Alice" N1 N3 "Eve" N6

slide-83
SLIDE 83

The MERGE clause : MATCH else CREATE

29

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User name:"Eve" r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Input table: a n N3 "Alice" N3 "Eve"

Query:

MERGE ✭a✮✲❬✿FOLLOWS❪✲❃ ✭b✿User {name✿n}✮

Output table: a n c N3 "Alice" N1 N3 "Eve" N6

slide-84
SLIDE 84

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

slide-85
SLIDE 85

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

slide-86
SLIDE 86

Modelling Tables

31 Record (table row)

A record is a partial function from variables to values. Example: (x →"Bob" ; y →1)

slide-87
SLIDE 87

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 "Alice" 999 "Bob" 1

slide-88
SLIDE 88

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 "Alice" 999 "Bob" 1 = y x 999 "Alice" 1 "Bob" 1 "Bob"

slide-89
SLIDE 89

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)
  • utput : (Graphs × Queries) −→ Tables
slide-90
SLIDE 90

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 = C1 C2 · · · Cn

slide-91
SLIDE 91

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 = C1 C2 · · · Cn Compute

  • C1
  • G ,
  • C2
  • G ,

. . . ,

  • Cn
  • G
slide-92
SLIDE 92

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 = C1 C2 · · · Cn Compute

  • C1
  • G ,
  • C2
  • G ,

. . . ,

  • Cn
  • G

Let

  • Q
  • G =
  • Cn
  • G ◦ · · · ◦
  • C2
  • G ◦
  • C1
  • G
slide-93
SLIDE 93

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 = C1 C2 · · · Cn Compute

  • C1
  • G ,
  • C2
  • G ,

. . . ,

  • Cn
  • G

Let

  • Q
  • G =
  • Cn
  • G ◦ · · · ◦
  • C2
  • G ◦
  • C1
  • G
  • utput(G,Q) =
  • Q
  • G
  • Tunit
  • where Tunit is the 1-line 0-column table.
slide-94
SLIDE 94

Excerpt of Read-Only semantics (2)

34

  • WHERE e
  • G(T) =
  • u ∈ T
  • e
  • G,u = true
  • MATCH ¯

π

  • G(T) =
  • u∈T

{u · u′ | u′ ∈ match(¯ π,G,u)}

  • MATCH ¯

π WHERE e

  • G(T) =
  • WHERE e
  • MATCH ¯

π

  • G(T)
  • OPTIONAL MATCH ¯

π WHERE e

  • G(T)

=

  • u∈T
  • MATCH ¯

π WHERE e

  • G({u})

if

  • MATCH ¯

π WHERE e

  • G({u}) ∅

(u,(free(u, ¯ π) : null))

  • therwise
  • OPTIONAL MATCH ¯

π

  • G(T) =
  • OPTIONAL MATCH ¯

π WHERE true

  • G(T)
slide-95
SLIDE 95

Excerpt of Read-Only semantics (2)

35

  • WITH ∗
  • G(T) = T if T has at least one column
  • WITH ∗,e1 [AS a1],. . .,em [AS am]
  • G(T) =
  • WITH b1 AS b1,. . ., bq AS bq,e1 [AS a1],. . .,em [AS am]
  • G(T)
  • WITH e1 [AS a1],. . .,em [AS am]
  • G(T) =
  • u∈T
  • (a′

1 :

  • e1
  • G,u,. . .,a′

m :

  • em
  • G,u)
  • UNWIND e AS a
  • G(T) =
  • u∈T
  • v∈Eu

{(u,a : v)} , with Eu =               

  • 0≤i<m {vi}

if

  • e
  • G,u = list(v0,. . .,vm−1)

{} if

  • e
  • G,u = list()
  • e
  • G,u
  • therwise
slide-96
SLIDE 96

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))
  • utput : (Graphs × Queries) −→ (Graphs × Tables)

(Computed just like RO → composition of clause semantics)

slide-97
SLIDE 97

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.

slide-98
SLIDE 98

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.

slide-99
SLIDE 99

In Neo4j, SET violate Atomicity

38

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 id:22 text:"Hello" N5 Message id:25 id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers answers r8 follows follows

Query:

MATCH ✭m1✮✲❬✿ANSWERS❪✲❃✭m2✮ SET m1✳id ❂ m2✳id, m2✳id ❂ m1✳id

Table before SET clause: m1 m2 N5 N4

slide-100
SLIDE 100

In Neo4j, SET violate Atomicity

38

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 id:22 text:"Hello" N5 Message id:25 id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers answers r8 follows follows

Query:

MATCH ✭m1✮✲❬✿ANSWERS❪✲❃✭m2✮ SET m1✳id ❂ m2✳id, m2✳id ❂ m1✳id

Table before SET clause: m1 m2 N5 N4 Neo4j sets both id to 25. Semantics exchange id values

slide-101
SLIDE 101

In Neo4j, MERGE is highly non-deterministic

39

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Input Table: a b c N1 N2 N3 N2 N3 N1 N3 N1 N2

Query:

MERGE ✭a✮✲❬✿FOLLOWS❪✲❃✭b✮ ✲❬✿FOLLOWS❪✲❃✭c✮

slide-102
SLIDE 102

In Neo4j, MERGE is highly non-deterministic

39

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Input Table: a b c N1 N2 N3 N2 N3 N1 N3 N1 N2

Query:

MERGE ✭a✮✲❬✿FOLLOWS❪✲❃✭b✮ ✲❬✿FOLLOWS❪✲❃✭c✮

Neo4j creates 4 edges

slide-103
SLIDE 103

In Neo4j, MERGE is highly non-deterministic

39

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Input Table: a b c N1 N2 N3 N2 N3 N1 N3 N1 N2

Query:

MERGE ✭a✮✲❬✿FOLLOWS❪✲❃✭b✮ ✲❬✿FOLLOWS❪✲❃✭c✮

Neo4j creates 4 edges Semantics propose different se- mantics creating either 3 or 6.

slide-104
SLIDE 104

In Neo4j, DELETE violates clause-level consistency

40

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭a {name✿"Alice"}✮ MATCH ✭a✮✲❬r❪✲✭✮ DELETE a ❬✳✳✳❪ // Arbitrary clauses DELETE r RETURN a✳name AS n

Execution of arbitrary code

  • n invalid graph

Access to deleted-entity

slide-105
SLIDE 105

In Neo4j, DELETE violates clause-level consistency

40

N1 User name:"Alice" N2 User name:"Bob" N3 User , Admin name:"Charlie" N4 Message id:22 text:"Hello" N5 Message id:25 text:"World" N6 User r1 follows r2 r3 r4 r5 posted

  • n:"05-14"

r6 posted

  • n:"05-15"

r7 answers r8 follows follows

Query:

MATCH ✭a {name✿"Alice"}✮ MATCH ✭a✮✲❬r❪✲✭✮ DELETE a ❬✳✳✳❪ // Arbitrary clauses DELETE r RETURN a✳name AS n

Execution of arbitrary code

  • n invalid graph

Access to deleted-entity Semantics is undefined if it should pro- duce invalid graphs replaces deleted entities by null in the table

slide-106
SLIDE 106

Outline

41

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

slide-107
SLIDE 107

Cypher vs RPQ

41 Cypher queries vs UCRPQs

Cypher has bag + cypher-morphism semantics (Set+ standard morphism semantics may be emulated...) Cypher has relationship/path variables (Data model is different)

RPQs not expressible in Cypher

(ab)∗ : no concatenation under star in Cypher (a∗)∗: no nested stars in Cypher (a + b−1)∗: some unions are not allowed under star in Cypher (ab + cd)3: nested alternations of concatenations and unions re- quire multi-exponential blow-up of the query → (ab)3 + (ab)2cd + ab(cd)2 + (cd)3

slide-108
SLIDE 108

PGQL (Property Graph Query Language)

42

Designed by Oracle Inc. Support full UCRPQ ASCII-art representation of patterns (similar to Cypher) Syntax close to SQL Example: (from http://pgql-lang.org/)

SELECT p1✳name FROM facebook_graph /* In the Facebook graph,.. */ MATCH ✭p1✿Person✮ /* ..find persons such that.. */ WHERE NOT EXISTS ✭ /* ..there does not exist.. */ SELECT p2 FROM twitter_graph /* ..in the Twitter graph.. */ MATCH ✭p2✿Person✮ /* ..a person.. */ WHERE p1✳name ❂ p2✳name /* ..with the same name. */ ✮

slide-109
SLIDE 109

G-Core

43

Designed by LDBC Experimental Support full UCRPQ ASCII-art representation of patterns (similar to Cypher) Support Multiple graphs, graph views, and paths cost Multiple semantics Example:

CONSTRUCT ✭n✮✲❬✿To{distance✿❂c}❪✲❃✭m✮ MATCH ✭n✮ ✲/SHORTEST p❁✿KNOWS*❃ COST c/✲❃✭m✮ ON facebook_graph MATCH ✭n✮,✭m✮ ON upem_graph

slide-110
SLIDE 110
  • cf. GQL manifesto:

http://gql.today

slide-111
SLIDE 111
  • cf. GQL manifesto:

http://gql.today To be continued...