●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
● →
●
○
■
■
● →
●
●
●
●
●
●
●
●
●
●
●
●
○ →
○ →
●
○ →
●
○
○ →
○ →
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
○
●
●
●
●
Name: DEXA 2017
Year: 2017
Place: Lyon, FR
Name: Harsh
Age: 27
From: Bonn, DE
Role: Speaker
Time: 20
Person Event
Name: Kemele
Age: 30
From: Bonn, DE
Name: DEXA
Year: 2017
Place: Lyon, FR
Name: Harsh
Age: 27
From: Bonn, DE
Role: speaker
Time: 20
1
Person
2
Event
Role:speaker
Time:20 Name: Kuldeep
Age: 28
From: Bonn
Role: speaker
Time: 20
V = {1,2,3,4}
E = {(1,5,2),(3,6,2),(4,7,2),(1,8,3),(4,9,3)}
Pv
= {Name,Age,From,Year,Place} ; Pe
= {Role,Time,Since}
Lv
= {Person,Event} ; Le
= {Speaks,Friend}
μ(V/E,Pv
,Pe
) = “value” ; λ(V/E) = Lv
/Le
;
μ(1,Name) = “Harsh” ; λ(1) = “Person”;
μ(2,Year) = “2017” ; λ(2) = “Event”;
μ(5,Time) = “20” ; λ(9) = “Friend”;
μ(7,Role) = “speaker” ; λ(5) = “Speaks”;
…… ; …...
3
Person
4
Person
5 7
6
Speaks
Friend
SpeaksSpeaks
Since: 2015
Since: 2015Friend
98
●
●
●
○
○
○
○
○ …
●
GPM using Gremlin*
1. g.V().match(
__.as(‘x’).out(‘Created’).as(‘y’)).se
lect(‘x’).dedup()
2. g.V(2).match(__.as(‘x’).out(‘Created’
).as(‘y’))
==>x:v[4]
==>x:v[2]
==>x:v[5]
Output
*In Gremlin GPM is executed by the match() step
==>x:v[3]
Output
GPM using Gremlin*
1. g.V().match(
__.as(‘x’).out(‘Created’).as(‘y’)).se
lect(‘x’).dedup()
2. g.V(2).match(__.as(‘x’).out(‘Created’
).as(‘y’))
==>x:v[4]
==>x:v[2]
==>x:v[5]
Output
*In Gremlin GPM is executed by the match() step
==>x:v[3]
Output
x
x
x
y
y
●
○
○
○
○
●
○ ∪ →
■
■
g.V().hasLabel("person").as("a").in("knows").as("b").out("created").as("c").select('c')
* a = {v[2],v[4],v[5],v[6]}, b = {v[2],v[2]}, c = {v[3],v[3]}
==>v[3]
==>v[3]
○ Ǝ filters/restricts the match of a graph pattern (P) against
G given a conditional expression (p)
■ e.g., inequalities and/or other traversal-specific predicates (where predicate
is a proposition formula).
■ .where(_p_) step is used in Gremlin
1. g.V().match(
__.as(‘x’).out(‘Created’).as(‘y’)).select(‘x’).where(.as(‘x’).in(‘knows’).
has(‘name’,’marko’)
2. g.V(1).as('a').out('created').in('created').where(neq('a'))
●
○ о ✕ →
■ α β о
α β ∈ α β ∈
○ ⊎ ✕ →
■ ⊎
○ ⨝ ✕ →
∈
■
●
○ †a
(p)
// g.V().group().by('name')
○ ℜ⇑a
,⇓b
(p)
// g.V().values('name').order().by(decr)
○
// g.V().in(“Created”).dedup()
●
○
■
■
// g.V().fold() = {[v[1],v[2],v[3],v[4],v[5],v[6]]}
○ ∪ ✕ → ∪
↑ ↓
// g.V().as(‘a’).out(‘created’).as(‘b’) ⇒ ↑b
a
[created]
●
○ σ ∪ ✕ →
// g.V().has(‘name’,’harsh’)
// g.V().has(‘age’,lt(30))
// g.V().values(‘name’)
A consolidated list of graph relational operators and their corresponding Gremlin implementation.
●
●
●
●
●
●
●
●
●
●
●
●
http://www.datastax.com/wp-content/uploads/2015/09/many-to-many-mapping.png
http://www.datastax.com/wp-content/uploads/2015/09/gtm-dataflow.png
Gremlin’s Multi-Graph Query Language (GQL) support
…
Multi-DMS & platform support
https://tinkerpop.apache.org/images/oltp-and-olap.png
1. g.V().out(“Created”).dedup()
2. g.V().match(
__.as(‘x’).out(‘Created’).as(‘y’))
.select(‘y’).dedup()
Output
==>y:v[1]
==>y:v[3]
Output
==>v[1]
==>v[3]
●
●
●
●
●
●
●
●
● *Match()
● ⟦ ⟧
● match()
○
○
○
○ The bind()
* http://tinkerpop.apache.org/docs/3.2.3/reference/#match-step
Input
Query
Extract
individual GPs
Graph algebra
builder
Formalised
Query
Parse Build
#Parse
#Build
g.V().match(__.as (’a’).out(’Created’).as(’b’),
__.as(’b’).has(’name’,’lop’),
__.as(’b’).in(’Created’).as(’c’),
__.as(’c’).has(’age’,30)).select(’a’,’c’).by(’name’)
Q1. "Who created a project named 'lop' that was also created by someone who is
30 years old? Return the two creators."
Input
Query
Input
Query
g.V().match(__.as (’a’).out(’Created’).as(’b’),
__.as(’b’).has(’name’,’lop’),
__.as(’b’).in(’Created’).as(’c’),
__.as(’c’).has(’age’,30)).select(’a’,’c’).by(’name’)
Q1. "Who created a project named 'lop' that was also created by someone who is
30 years old? Return the two creators."
Parse
Extract
individual GPs
f(i) = (outCreated
) (i)
g(i) = (hasname=lop
) (i)
h(i) = (inCreated
) (i)
i(i) = (ageage=30
) (i)
t
Input
Query
g.V().match(__.as (’a’).out(’Created’).as(’b’),
__.as(’b’).has(’name’,’lop’),
__.as(’b’).in(’Created’).as(’c’),
__.as(’c’).has(’age’,30)).select(’a’,’c’).by(’name’)
Input
Query
Parse
Extract
individual GPs
Graph algebra
builder
Build
Formalised
Query
f(i) = (outCreated
) (i)
g(i) = (hasname=lop
) (i)
h(i) = (inCreated
) (i)
i(i) = (ageage=30
) (i)
t
g.V().match(__.as (’a’).out(’Created’).as(’b’),
__.as(’b’).has(’name’,’lop’),
__.as(’b’).in(’Created’).as(’c’),
__.as(’c’).has(’age’,30)).select(’a’,’c’).by(’name’)
Q1. "Who created a project named 'lop' that was also created by someone who is
30 years old? Return the two creators."
Input
Query
Parse
Extract
individual GPs
Graph algebra
builder
Build
Formalised
Query
†a,c
a,c
c
age=30
↓c
b
[Created]
b
name=lop
↑b
a
[Created]
Vg
⟦ ⟧
g.V().match(__.as (’a’).out(’Created’).as(’b’),
__.as(’b’).has(’name’,’lop’),
__.as(’b’).in(’Created’).as(’c’),
__.as(’c’).has(’age’,30)).select(’a’,’c’).by(‘name’)
Q1. "Who created a project named 'lop' that was also created by someone who is
30 years old? Return the two creators."
⟦ ⟧
†a,c
a,c
c
age=30
↓c
b
[Created]
b
name=lop
↑b
a
[Created]
Vg
g.V().match(
__.as('a').hasLabel(‘person’).values(‘age’).as('b')).select(
'b').order().by(asc)
ℜ⇑b b
⟦ b
age
a
label=person
⟧
ℜ⇑b
b
c
age
b
label=person
Vg
⟦ ⟧
Q2. "List all the persons in the ascending order of the age"
g.V().union( __.match( __.as('a').out('created').as('c')),
__.match( __.as('b').out('created').as('c'))).select('a','c')
b,c
⟦ ⟧ ⊎ ⟦ ⟧
t1
⊎
⟦ ⟧
a,c
↑c
a
[created]
Vg
↑c
b
[created]
Vg
⊎
t1
t2
t
Q3. "List the people who have collaboratively created a software"
●
●
●
●
●
●
●
●
●
○
○
○
○
○
●
●
addProperty() aggregate
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
●
Prof. Dr.
Soeren Auer
TiB, Hannover
Prof. Dr. Jens
Lehmann
Uni. Bonn.
Prof. Dr.
Maria-Esther
Vidal
Fraunhofer, IAIS
H2020 WDAqua ITN (GA: 642795)
http://wdaqua.eu/
https://github.com/LITMUS-Benchmark-Suite/sparql-to-gremlin
https://github.com/LITMUS-Benchmark-Suite/
https://litmus-benchmark-suite.github.io
https://hub.docker.com/r/litmusbenchmarksuite/litmus/
LITMUS Benchmark Suite
Twitter: @harsh9t
LinkedIn: thakkarharsh
E-mail: harsh9t@gmail.com
Questions? Comments?
Insults? Injuries?

Formalising Graph Pattern Matching Gremlin traversals in Graph Alegra