formal semantics of cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10....

111
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

Upload: others

Post on 17-Aug-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Formal semantics of Cypher:towards a standard language for querying property graphs

N. Francis 1

V. Marsault 1A. 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-Vallee, ENPC, ESIEE, CNRS

2. Neo Technology 3. University of Edinburgh

GT AlgaInria Nord Europe, Lille

2018-10-15

Page 2: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

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

Page 3: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Representing data as graphs 1

Most databases use the relational modelRelational algebra in theoryThe language SQL in practice

Some data have intrinsically the structure of graphs:Semantic webSocial NetworksBioinformatic networks

Native representation of data as graphs allows:Efficient algorithms on graphsPattern matchingOptimisations

Page 4: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Representing data as graphs 1

Most databases use the relational modelRelational algebra in theoryThe language SQL in practice

Some data have intrinsically the structure of graphs:Semantic webSocial NetworksBioinformatic networks

Native representation of data as graphs allows:Efficient algorithms on graphsPattern matchingOptimisations

Page 5: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

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

Page 6: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

More and more ways to manipulate data as graphs 2

Data model

Property graphsProperty graphs, RDF

Query languages

CypherCypher, Gremlin, PGQLPGQL, SPARQL, G-CoreG-Core

Engines

JanusGraph, Jena, Neo4jNeo4j, Virtuoso

Domain

Fraud detection, Investigative journalism

Page 7: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Cypher 3

Language for querying and updating property graphs

Invented by Neo TechnologyOriginally, part of engine Neo4j → commercial successNow, in multiple datagraph engines (e.g., SAP HANA Graph,Redis Graph, Agens Graph)

The openCypher project

Since 2015Seeks to standardise Cypher (SQL for property graphs?)

Community-led evolutionComplete specification

Page 8: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Cypher 3

Language for querying and updating property graphs

Invented by Neo TechnologyOriginally, part of engine Neo4j → commercial successNow, in multiple datagraph engines (e.g., SAP HANA Graph,Redis Graph, Agens Graph)

The openCypher project

Since 2015Seeks to standardise Cypher (SQL for property graphs?)

Community-led evolutionComplete specification

Page 9: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Short term goal

Full denotational semantics for the language Cypher.

Industrial partnership Neo4j/University of EdinburghReverse engineering and formalisation from Neo4jDone 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.

Page 10: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Short term goal

Full denotational semantics for the language Cypher.

Industrial partnership Neo4j/University of EdinburghReverse engineering and formalisation from Neo4jDone 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.

Page 11: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

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

Page 12: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Property graph 5

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Nodes : N1,N2, · · · ,N5

Relationships : r1,r2, · · · ,r7

Labels (de nœuds) :UserMessage

Types (of relationships) :followspostedanswers

Properties(i.e. Key/Value pairs) :

name:"Alice"id:22text:"Hello"

Page 13: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Property graph 5

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Nodes : N1,N2, · · · ,N5

Relationships : r1,r2, · · · ,r7

Labels (de nœuds) :UserMessage

Types (of relationships) :followspostedanswers

Properties(i.e. Key/Value pairs) :

name:"Alice"id:22text:"Hello"

Page 14: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Property graph 5

N1

UserUser

name:"Alice"

N2

UserUser

name:"Bob"

N3

UserUser , AdminAdmin

name:"Charlie"

N4

MessageMessage

id:22text:"Hello"

N5

MessageMessage

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Nodes : N1,N2, · · · ,N5

Relationships : r1,r2, · · · ,r7

LabelsLabels (de nœuds) :UserMessage

Types (of relationships) :followspostedanswers

Properties(i.e. Key/Value pairs) :

name:"Alice"id:22text:"Hello"

Page 15: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Property graph 5

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

followsfollows

r2

r3r4

r5postedposted

on:"05-14"r6

postedposted

on:"05-15"

r7

answersanswers

r8

follows

followsfollows

Nodes : N1,N2, · · · ,N5

Relationships : r1,r2, · · · ,r7

Labels (de nœuds) :UserMessage

TypesTypes (of relationships) :followspostedanswers

Properties(i.e. Key/Value pairs) :

name:"Alice"id:22text:"Hello"

Page 16: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

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:22id:22text:"Hello"text:"Hello"

N5

Message

id:25id:25text:"World"text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"on:"05-14"r6

posted

on:"05-15"on:"05-15"

r7

answers

r8

follows

follows

Nodes : N1,N2, · · · ,N5

Relationships : r1,r2, · · · ,r7

Labels (de nœuds) :UserMessage

Types (of relationships) :followspostedanswers

PropertiesProperties(i.e. Key/Value pairs) :

name:"Alice"id:22text:"Hello"

Page 17: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

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

Page 18: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Data model for theoretical query languages 6

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Graph database

Relation bear typesNode do not bear types

(could be simulated)Neither bears property

Finite number of relation types(and node types)

→ “Dataless graph”

Page 19: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Data model for theoretical query languages 6

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Graph database

Relation bear typesNode do not bear types

(could be simulated)Neither bears property

Finite number of relation types(and node types)

→ “Dataless graph”

Page 20: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Data model for theoretical query languages 6

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Graph database

Relation bear typesNode do not bear types

(could be simulated)Neither bears property

Finite number of relation types(and node types)

→ “Dataless graph”

Page 21: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

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 Ax, 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)

Page 22: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Regular Path Query (RPQ) – Example 1 8

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

x yPOSTED.(ANSWERS)∗

Answers:

F1 : x 7→ N1 y 7→ N4

F2 : x 7→ N2 y 7→ N5

F3 : x 7→ N2 y 7→ N4

Page 23: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Regular Path Query (RPQ) – Example 1 8

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

x yPOSTED.(ANSWERS)∗

Answers:

F1 : x 7→ N1 y 7→ N4

F2 : x 7→ N2 y 7→ N5

F3 : x 7→ N2 y 7→ N4

Page 24: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Regular Path Query (RPQ) – Example 1 8

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

postedposted

on:"05-15"

r7

answers

r8

follows

follows

Query:

x yPOSTED.(ANSWERS)∗

Answers:

F1 : x 7→ N1 y 7→ N4

F2 : x 7→ N2 y 7→ N5

F3 : x 7→ N2 y 7→ N4

Page 25: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Regular Path Query (RPQ) – Example 1 8

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

postedposted

on:"05-15"

r7

answersanswers

r8

follows

follows

Query:

x yPOSTED.(ANSWERS)∗

Answers:

F1 : x 7→ N1 y 7→ N4

F2 : x 7→ N2 y 7→ N5

F3 : x 7→ N2 y 7→ N4

Page 26: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Regular Path Query (RPQ) – Example 1 8

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

x yPOSTED.(ANSWERS)∗

Answers:

F1 : x 7→ N1 y 7→ N4

F2 : x 7→ N2 y 7→ N5

F3 : x 7→ N2 y 7→ N4

Page 27: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Regular Path Query (RPQ) – Example 2 9

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

x y(FOLLOWS)∗

Answers:

F1 : x 7→ N1 y 7→ N1

F2 : x 7→ N1 y 7→ N2

F3 : x 7→ N1 y 7→ N3...

......

F9 : x 7→ N3 y 7→ N3

→ ∞-many path realise F1

→ RPQ follows set-semantics

Page 28: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Regular Path Query (RPQ) – Example 2 9

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

followsfollows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

followsfollows

Query:

x y(FOLLOWS)∗

Answers:

F1 : x 7→ N1 y 7→ N1

F2 : x 7→ N1 y 7→ N2

F3 : x 7→ N1 y 7→ N3...

......

F9 : x 7→ N3 y 7→ N3

→ ∞-many path realise F1

→ RPQ follows set-semantics

Page 29: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Regular Path Query (RPQ) – Example 2 9

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

x y(FOLLOWS)∗

Answers:

F1 : x 7→ N1 y 7→ N1

F2 : x 7→ N1 y 7→ N2

F3 : x 7→ N1 y 7→ N3...

......

F9 : x 7→ N3 y 7→ N3

→ ∞-many path realise F1

→ RPQ follows set-semantics

Page 30: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Regular Path Query (RPQ) – Example 2 9

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

x y(FOLLOWS)∗

Answers:

F1 : x 7→ N1 y 7→ N1

F2 : x 7→ N1 y 7→ N2

F3 : x 7→ N1 y 7→ N3...

......

F9 : x 7→ N3 y 7→ N3

→ ∞-many path realise F1

→ RPQ follows set-semantics

Page 31: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Regular Path Query (RPQ) – Example 2 9

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

followsfollows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

followsfollows

Query:

x y(FOLLOWS)∗

Answers:

F1 : x 7→ N1 y 7→ N1

F2 : x 7→ N1 y 7→ N2

F3 : x 7→ N1 y 7→ N3...

......

F9 : x 7→ N3 y 7→ N3

→ ∞-many path realise F1

→ RPQ follows set-semantics

Page 32: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Regular Path Query (RPQ) – Example 2 9

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

followsfollows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

followsfollows

Query:

x y(FOLLOWS)∗

Answers:

F1 : x 7→ N1 y 7→ N1

F2 : x 7→ N1 y 7→ N2

F3 : x 7→ N1 y 7→ N3...

......

F9 : x 7→ N3 y 7→ N3

→ ∞-many path realise F1

→ RPQ follows set-semantics

Page 33: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Regular Path Query (RPQ) – Example 2 9

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

x y(FOLLOWS)∗

Answers:

F1 : x 7→ N1 y 7→ N1

F2 : x 7→ N1 y 7→ N2

F3 : x 7→ N1 y 7→ N3...

......

F9 : x 7→ N3 y 7→ N3

→ ∞-many path realise F1

→ RPQ follows set-semantics

Page 34: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

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

Page 35: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Conjunction of RPQs (CRPQ) – Example 11

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

x y z

POSTED

(ANSWERS)∗

Answers:

x y z

7→ 7→ 7→

F1 : N1 N4 N4

F2 : N2 N5 N4

F3 : N2 N5 N5

Page 36: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

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.

Page 37: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

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

Page 38: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Evaluating a Cypher query 13

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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 statementis a sequence of clauses

queries a graphreturns a table

Page 39: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Evaluating a Cypher query 13

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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 statementis a sequence of clausesqueries a graphreturns a table

Page 40: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Matching nodes (1) 14

N1

UserUser

name:"Alice"

N2

UserUser

name:"Bob"

N3

UserUser , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

MATCH (u1:User)

Result:

u1

N1

N2

N3

Page 41: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Matching nodes (1) 14

N1

UserUser

name:"Alice"

N2

UserUser

name:"Bob"

N3

UserUser , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

MATCH (u1:User)

Result:

u1

N1

N2

N3

Page 42: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Matching nodes (2) 15

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

UserUser , AdminAdmin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

MATCH (u1:User:Admin)

Result:

u1

N3

Page 43: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Matching nodes (3) 16

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

MATCH (u1{id:22})

Result:

u1

N4

Page 44: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Matching relations (1) 17

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

MATCH ()-[p1]->()

Result:

p1

r1r2r3r4r5r6r7

Page 45: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Matching relation (2) 18

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5postedposted

on:"05-14"r6

postedposted

on:"05-15"

r7

answers

r8

follows

follows

Query:

MATCH (u1)-[p1:POSTED]->(m1)

Result:

u1 p1 m1

N1 r5 N4

N2 r6 N5

Page 46: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Matching relationships (3) 19

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

followsfollows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

followsfollows

Query:

MATCH (u1)-[:FOLLOWS]->()

Result:

u1

N1

N2

N2

N3

Cypher has bag semantics:N2 has two outgoing followsrelations ⇒ two lines N2

Page 47: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Matching paths (1) 20

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , AdminAdmin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

followsfollows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

followsfollows

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-MorphismEach rel. matched ≤ 1 time⇒ Finitely many results

Page 48: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Matching paths (1) 20

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , AdminAdmin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

followsfollows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

followsfollows

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-MorphismEach rel. matched ≤ 1 time⇒ Finitely many results

Page 49: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Matching paths (1) 20

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , AdminAdmin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

followsfollows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

followsfollows

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-MorphismEach rel. matched ≤ 1 time⇒ Finitely many results

Page 50: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Matching paths (1) 20

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , AdminAdmin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

followsfollows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

followsfollows

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-MorphismEach rel. matched ≤ 1 time⇒ Finitely many results

Page 51: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Matching paths (1) 20

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , AdminAdmin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

followsfollows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

followsfollows

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-MorphismEach rel. matched ≤ 1 time⇒ Finitely many results

Page 52: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Matching paths (1) 20

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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-MorphismEach rel. matched ≤ 1 time⇒ Finitely many results

Page 53: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Matching paths (2) 21

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

MATCH (u1)-[:FOLLOWS]->()

-[:POSTED]->(m1)

Result:

u1 m1

N1 N5

N2 N4

N3 N5

Page 54: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Matching paths (2) 21

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

followsfollows

r2

r3r4

r5posted

on:"05-14"r6

postedposted

on:"05-15"

r7

answers

r8

follows

follows

Query:

MATCH (u1)-[:FOLLOWS]->()

-[:POSTED]->(m1)

Result:

u1 m1

N1 N5

N2 N4

N3 N5

Page 55: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Chaining clauses 22

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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

Table after second MATCH:

u1 m1 u2 u3

N2 N5 N1 N3

N2 N5 N3 N1

Page 56: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Chaining clauses 22

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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

Table after second MATCH:

u1 m1 u2 u3

N2 N5 N1 N3

N2 N5 N3 N1

Page 57: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Chaining clauses 22

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

MATCH (u1u1)-[:POSTED]->(m1)

MATCH (u2)<-[:FOLLOWS]-(u1u1)

-[:FOLLOWS]->(u3)

Table after first MATCH:

u1 m1

N1 N4

N2 N5

Table after second MATCH:

u1u1 m1 u2 u3

N1 N4 · ·

N2 N5 · ·

Page 58: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Chaining clauses 22

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

followsfollows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

MATCH (u1u1)-[:POSTED]->(m1)

MATCH (u2)<-[:FOLLOWS]-(u1u1)

-[:FOLLOWS]->(u3)

Table after first MATCH:

u1 m1

N1 N4

N2 N5

Table after second MATCH:

u1u1 m1 u2 u3

N1 N4 · ·

N2 N5 · ·

Page 59: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Chaining clauses 22

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

followsfollows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

MATCH (u1u1)-[:POSTED]->(m1)

MATCH (u2)<-[:FOLLOWS]-(u1u1)

-[:FOLLOWS]->(u3)

Table after first MATCH:

u1 m1

N1 N4

N2 N5

Table after second MATCH:

u1u1 m1 u2 u3

N1 N4 · ·

N2 N5 · ·

Page 60: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Chaining clauses 22

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

followsfollows

Query:

MATCH (u1u1)-[:POSTED]->(m1)

MATCH (u2)<-[:FOLLOWS]-(u1u1)

-[:FOLLOWS]->(u3)

Table after first MATCH:

u1 m1

N1 N4

N2 N5

Table after second MATCH:

u1u1 m1 u2 u3

N1 N4 · ·

N2 N5 · ·

Page 61: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Chaining clauses 22

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

followsfollows

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

Page 62: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Column manipulation (WITH clause) 23

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5postedposted

on:"05-14"r6

postedposted

on:"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

Execution of the WITH clause

u1 p1 t1

N1 r5N2 r6

Page 63: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Column manipulation (WITH clause) 23

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

MATCH (u1)-[p1:POSTED]->(m1)

WITH u1u1, p1p1, m1.text AS t1t1

After the MATCH clause

u1u1 p1p1 m1

N1 r5 N4

N2 r6 N5

Execution of the WITH clause

u1u1 p1p1 t1t1

N1 r5N2 r6

Page 64: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Column manipulation (WITH clause) 23

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

MATCH (u1)-[p1:POSTED]->(m1)

WITH u1, p1, m1.textm1.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 r5N2 r6

Page 65: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Column manipulation (WITH clause) 23

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

MATCH (u1)-[p1:POSTED]->(m1)

WITH u1, p1, m1.textm1.text AS t1

After the MATCH clause

u1 p1 m1

N1 r5 N4N4

N2 r6 N5

Execution of the WITH clause

u1 p1 t1

N1 r5 "Hello""Hello"

N2 r6

Page 66: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Column manipulation (WITH clause) 23

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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 N5N5

Execution of the WITH clause

u1 p1 t1

N1 r5 "Hello"

N2 r6 "World""World"

Page 67: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Column manipulation (WITH clause) 23

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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"

Page 68: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Line filtering (WHERE clause) 24

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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"

Page 69: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Line filtering (WHERE clause) 24

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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"

Page 70: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Line filtering (WHERE clause) 24

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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"

Page 71: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

A last read-only example 25

N1

User

name:"Alice"

N2

User

name:"Bob"name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

MATCH (a{name:"Bob"})

-[*]->(b{id:22})

<-[*]-(a)

QuestionWhat does this computes ?

AnswerThe # of pairs of disjoint pathsfrom N2 to N4.

⇒ Evaluation of one constantMATCH is NP-HARD

Page 72: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

A last read-only example 25

N1

User

name:"Alice"

N2

User

name:"Bob"name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

MATCH (a{name:"Bob"})

-[*]->(b{id:22})

<-[*]-(a)

QuestionWhat does this computes ?

AnswerThe # of pairs of disjoint pathsfrom N2 to N4.

⇒ Evaluation of one constantMATCH is NP-HARD

Page 73: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

A last read-only example 25

N1

User

name:"Alice"

N2

User

name:"Bob"name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

follows

Query:

MATCH (a{name:"Bob"})

-[*]->(b{id:22})

<-[*]-(a)

QuestionWhat does this computes ?

AnswerThe # of pairs of disjoint pathsfrom N2 to N4.

⇒ Evaluation of one constantMATCH is NP-HARD

Page 74: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Node and relation creation (CREATE) 26

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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

Page 75: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Node and relation creation (CREATE) 26

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

UserUser

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

followsfollows

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

Page 76: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Node and relation creation (CREATE) 26

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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

Page 77: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

The example graph stored as CREATE clauses 27

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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),

Page 78: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Node/Relation modification (SET clause) 28

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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

Page 79: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Node/Relation modification (SET clause) 28

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User , AdminAdmin

name:"Eve"name:"Eve"

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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

Page 80: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

The MERGE clause : MATCH else CREATE 29

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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

Page 81: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

The MERGE clause : MATCH else CREATE 29

N1

UserUser

name:"Alice"name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

follows

followsfollows

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

Page 82: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

The MERGE clause : MATCH else CREATE 29

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

UserUser

name:"Eve"name:"Eve"

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answers

r8

followsfollows

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

Page 83: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

The MERGE clause : MATCH else CREATE 29

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

name:"Eve"

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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

Page 84: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

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

Page 85: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

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

Page 86: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Modelling Tables 31

Record (table row)

A record is a partial function from variables to values.

Example: (x 7→"Bob" ; y 7→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"

Page 87: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Modelling Tables 31

Record (table row)

A record is a partial function from variables to values.

Example: (x 7→"Bob" ; y 7→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"

Page 88: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Modelling Tables 31

Record (table row)

A record is a partial function from variables to values.

Example: (x 7→"Bob" ; y 7→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"

Page 89: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Semantics brackets – Read-Only 32

G: a graph

Semantics of expressions[[·

]]u,G

: expression 7−→ value (where u is a record)

Semantics of clauses[[·

]]G: clause 7−→ (function: Tables → Tables)

Semantics of queries[[·

]]G: query 7−→ (function: Tables → Tables)

output : (Graphs × Queries) 7−→ Tables

Page 90: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Principle of Read-Only Semantics 33

G: a graphQ: 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

output(G,Q) =[[Q

]]G

(Tunit

)where Tunit is the 1-line 0-column table.

Page 91: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Principle of Read-Only Semantics 33

G: a graphQ: 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

output(G,Q) =[[Q

]]G

(Tunit

)where Tunit is the 1-line 0-column table.

Page 92: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Principle of Read-Only Semantics 33

G: a graphQ: 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

output(G,Q) =[[Q

]]G

(Tunit

)where Tunit is the 1-line 0-column table.

Page 93: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Principle of Read-Only Semantics 33

G: a graphQ: 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

output(G,Q) =[[Q

]]G

(Tunit

)where Tunit is the 1-line 0-column table.

Page 94: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

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)) otherwise[[OPTIONAL MATCH π

]]G(T) =

[[OPTIONAL MATCH π WHERE true

]]G(T)

Page 95: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

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

}otherwise

Page 96: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

Semantics brackets – Read-Write 36

Semantics of expressions: (Nothing changes)[[·

]]u,G

: expression 7−→ value (where u is a record)

Semantics of clauses:[[·

]]: clause 7−→ (function: (Graphs×Tables)→ (Graphs×Tables))

Semantics of queries:[[·

]]: query 7−→ (function: (Graphs×Tables)→ (Graphs×Tables))

output : (Graphs×Queries) 7−→ (Graphs×Tables)

(Computed just like RO → composition of clause semantics)

Page 97: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

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. clause2 Compute output Table and all changes to graph3 Apply all changes to Graph4 Ensure validity of output Graph/Table

If any fails, semantics is undefined.

In Neo4j, Atomicity and Consistency are verified at query level only.

Page 98: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

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. clause2 Compute output Table and all changes to graph3 Apply all changes to Graph4 Ensure validity of output Graph/Table

If any fails, semantics is undefined.

In Neo4j, Atomicity and Consistency are verified at query level only.

Page 99: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

In Neo4j, SET violate Atomicity 38

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22id:22text:"Hello"

N5

Message

id:25id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answersanswers

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

Page 100: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

In Neo4j, SET violate Atomicity 38

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22id:22text:"Hello"

N5

Message

id:25id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"05-15"

r7

answersanswers

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

Page 101: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

In Neo4j, MERGE is highly non-deterministic 39

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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.

Page 102: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

In Neo4j, MERGE is highly non-deterministic 39

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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.

Page 103: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

In Neo4j, MERGE is highly non-deterministic 39

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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.

Page 104: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

In Neo4j, DELETE violates clause-level consistency 40

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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 codeon invalid graphAccess to deleted-entity

Semanticsis undefined if it should pro-duce invalid graphsreplaces deleted entities bynull in the table

Page 105: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

In Neo4j, DELETE violates clause-level consistency 40

N1

User

name:"Alice"

N2

User

name:"Bob"

N3

User , Admin

name:"Charlie"

N4

Message

id:22text:"Hello"

N5

Message

id:25text:"World"

N6

User

r1

follows

r2

r3r4

r5posted

on:"05-14"r6

posted

on:"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 codeon invalid graphAccess to deleted-entity

Semanticsis undefined if it should pro-duce invalid graphsreplaces deleted entities bynull in the table

Page 106: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

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

Page 107: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

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

Page 108: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

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. */

)

Page 109: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

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

Page 110: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

cf. GQL manifesto:http://gql.today

To be continued...

Page 111: Formal semantics of Cypherresearchers.lille.inria.fr/~fcapelli/gt-alga/slides/mar... · 2018. 10. 22. · Formal semantics of Cypher: towards a standard language for querying property

cf. GQL manifesto:http://gql.today

To be continued...