Presented at the First openCypher Implementers Meeting in Walldorf, Germany, February 2017 @ http://www.opencypher.org/blog/2017/03/31/first-ocim-blog/
1. Budapest University of Technology and Economics
Department of Measurement and Information Systems
Department of Telecommunications and Media Informatics
Budapest University of Technology and Economics
McGill University, Montréal
Incremental Graph Queries for Cypher
Gábor Szárnyas, József Marton
20. Trailing the switch
seg div
t
STRAIGHT
ON
MATCH (t:Train)-[:ON]->(seg:Segment)
<-[:STRAIGHT]-(sw:Switch)
WHERE sw.position = 'diverging'
RETURN t.number, sw
21. Trailing the switch
seg div
t
STRAIGHT
ON
MATCH (t:Train)-[:ON]->(seg:Segment)
<-[:STRAIGHT]-(sw:Switch)
WHERE sw.position = 'diverging'
RETURN t.number, sw
22. Trailing the switch
seg div
t
STRAIGHT
ON
MATCH (t:Train)-[:ON]->(seg:Segment)
<-[:STRAIGHT]-(sw:Switch)
WHERE sw.position = 'diverging'
RETURN t.number, sw
Evaluate
continuously
25. Incremental queries
Register a set of standing queries
Continuously evaluate queries on changes
The Rete algorithm (1974)
o Originally for rule-based expert systems
o Indexes the graph and caches interim query results
27. πt.number, sw
σsw.position = ′diverging′
⋈
STRAIGHTON
c d e
g
fdiv
2
NEXT NEXT
STRAIGHT TOP
a b
1
NEXT NEXT ON
ON
div
STRAIGHT
Trailing the switch
ON
28. πt.number, sw
σsw.position = ′diverging′
⋈
STRAIGHTON
c d e
g
fdiv
2
NEXT NEXT
STRAIGHT TOP
a b
1
NEXT NEXT ON
ON
div
STRAIGHT
Trailing the switch
ON
29. πt.number, sw
σsw.position = ′diverging′
⋈
STRAIGHTON
c d e
g
fdiv
2
NEXT NEXT
STRAIGHT TOP
a b
1
NEXT NEXT ON
ON
div
STRAIGHT
Trailing the switch
ON
a
1
ON
e
2
ON
30. πt.number, sw
σsw.position = ′diverging′
⋈
STRAIGHTON e2
ON
a1
ON
c d e
g
fdiv
2
NEXT NEXT
STRAIGHT TOP
a b
1
NEXT NEXT ON
ON
div
STRAIGHT
Trailing the switch
ON
a
1
ON
e
2
ON
31. πt.number, sw
σsw.position = ′diverging′
⋈
STRAIGHTON e2
ON
a1
ON
c d e
g
fdiv
2
NEXT NEXT
STRAIGHT TOP
a b
1
NEXT NEXT ON
ON
div
STRAIGHT
Trailing the switch
ON
32. πt.number, sw
σsw.position = ′diverging′
⋈
STRAIGHTON e2
ON
a1
ON
c d e
g
fdiv
2
NEXT NEXT
STRAIGHT TOP
a b
1
NEXT NEXT ON
ON
div
STRAIGHT
Trailing the switch
ON
e div
STRAIGHT
33. πt.number, sw
σsw.position = ′diverging′
⋈
STRAIGHTON e2
ON
a1
ON
c d e
g
fdiv
2
NEXT NEXT
STRAIGHT TOP
a b
1
NEXT NEXT ON
ON
div
STRAIGHT
Trailing the switch
ON
e div
STRAIGHT
e div
STRAIGHT
34. πt.number, sw
σsw.position = ′diverging′
⋈
STRAIGHTON e div
STRAIGHT
e2
ON
a1
ON
c d e
g
fdiv
2
NEXT NEXT
STRAIGHT TOP
a b
1
NEXT NEXT ON
ON
div
STRAIGHT
Trailing the switch
ON
35. πt.number, sw
σsw.position = ′diverging′
⋈
STRAIGHTON e div
STRAIGHT
e2
ON
a1
ON
c d e
g
fdiv
2
NEXT NEXT
STRAIGHT TOP
a b
1
NEXT NEXT ON
ON
div
STRAIGHT
Trailing the switch
ON
e div
STRAIGHT
e2
ON
36. πt.number, sw
σsw.position = ′diverging′
⋈
STRAIGHTON e div
STRAIGHT
e2
ON
a1
ON
c d e
g
fdiv
2
NEXT NEXT
STRAIGHT TOP
a b
1
NEXT NEXT ON
ON
div
STRAIGHT
Trailing the switch
ON
e div
STRAIGHT
e2
ON
e div
2
STRAIGHT
ON
37. πt.number, sw
σsw.position = ′diverging′
⋈
STRAIGHTON e div
STRAIGHT
e2
ON
a1
ON
e div
STRAIGHT
2
ON
c d e
g
fdiv
2
NEXT NEXT
STRAIGHT TOP
a b
1
NEXT NEXT ON
ON
div
STRAIGHT
Trailing the switch
ON
e div
STRAIGHT
e2
ON
e div
2
STRAIGHT
ON
38. πt.number, sw
σsw.position = ′diverging′
⋈
STRAIGHTON e div
STRAIGHT
e2
ON
a1
ON
div
STRAIGHTON
c d e
g
fdiv
2
NEXT NEXT
STRAIGHT TOP
a b
1
NEXT NEXT ON
ON
div
STRAIGHT
Trailing the switch
ON
e2 div
STRAIGHTON
e2
39. πt.number, sw
σsw.position = ′diverging′
⋈
STRAIGHTON e div
STRAIGHT
e2
ON
a1
ON
div
STRAIGHTON
e div
STRAIGHT
2
ON
c d e
g
fdiv
2
NEXT NEXT
STRAIGHT TOP
a b
1
NEXT NEXT ON
ON
div
STRAIGHT
Trailing the switch
ON
e2 div
STRAIGHTON
e2
40. πt.number, sw
σsw.position = ′diverging′
⋈
STRAIGHTON e div
STRAIGHT
e2
ON
a1
ON
e div
STRAIGHT
2
ON
e div
STRAIGHT
2
ON
c d e
g
fdiv
2
NEXT NEXT
STRAIGHT TOP
a b
1
NEXT NEXT ON
ON
div
STRAIGHT
Trailing the switch
ON
div
2
41. πt.number, sw
σsw.position = ′diverging′
⋈
STRAIGHTON e div
STRAIGHT
e2
ON
a1
ON
e div
STRAIGHT
2
ON
e div
STRAIGHT
2
ON
div2
c d e
g
fdiv
2
NEXT NEXT
STRAIGHT TOP
a b
1
NEXT NEXT ON
ON
div
STRAIGHT
Trailing the switch
ON
div
2
42. πt.number, sw
σsw.position = ′diverging′
⋈
STRAIGHTON e div
STRAIGHT
e2
ON
a1
ON
e div
STRAIGHT
2
ON
e div
STRAIGHT
2
ON
div2
c d e
g
fdiv
2
NEXT NEXT
STRAIGHT TOP
a b
1
NEXT NEXT ON
ON
div
STRAIGHT
Trailing the switch
ON
div
2
43. πt.number, sw
σsw.position = ′diverging′
⋈
STRAIGHTON e div
STRAIGHT
e2
ON
a1
ON
e div
STRAIGHT
2
ON
e div
STRAIGHT
2
ON
div2
c e
g
fdiv
NEXT NEXT
STRAIGHT TOP
a b
1
NEXT NEXT
ON
div
STRAIGHT
Trailing the switch
ON
div
ON
2
d
44. πt.number, sw
σsw.position = ′diverging′
⋈
STRAIGHTON e div
STRAIGHT
d2
ON
a1
ON
e div
STRAIGHT
2
ON
e div
STRAIGHT
2
ON
div2
c e
g
fdiv
NEXT NEXT
STRAIGHT TOP
a b
1
NEXT NEXT
ON
div
STRAIGHT
Trailing the switch
ON
div
ON
2
d
45. πt.number, sw
σsw.position = ′diverging′
⋈
STRAIGHTON e div
STRAIGHT
d2
ON
a1
ON
e div
STRAIGHT
2
ON
div2
c e
g
fdiv
NEXT NEXT
STRAIGHT TOP
a b
1
NEXT NEXT
ON
div
STRAIGHT
Trailing the switch
ON
div
ON
2
d
46. πt.number, sw
σsw.position = ′diverging′
⋈
STRAIGHTON e div
STRAIGHT
d2
ON
a1
ON
div2
c e
g
fdiv
NEXT NEXT
STRAIGHT TOP
a b
1
NEXT NEXT
ON
div
STRAIGHT
Trailing the switch
ON
div
ON
2
d
47. πt.number, sw
σsw.position = ′diverging′
⋈
STRAIGHTON e div
STRAIGHT
d2
ON
a1
ON
c e
g
fdiv
NEXT NEXT
STRAIGHT TOP
a b
1
NEXT NEXT
ON
div
STRAIGHT
Trailing the switch
ON
div
ON
2
d
48. Batch vs. incremental queries
Batch queries
(pull / request-driven):
1. Client selects a query
2. Results are calculated
Query results
obtained on demand
49. Batch vs. incremental queries
Batch queries
(pull / request-driven):
1. Client selects a query
2. Results are calculated
Query results
obtained on demand
Incremental queries
(push / event-driven):
1. Client registers queries
2. Graph is changed
3. Results are maintained
4. Goto 2
Query results are
always available
70. Relational algebra
Standard relational algebra
o 𝜋, 𝜎
o ∪,∩,∖
o ×, ⋈
Common extensions
o 𝛿 – duplicate elimination
o 𝛾 – grouping
o 𝜏 – sorting
71. Graph-specific operators
Jürgen Hölsch, Michael Grossniklaus:
An Algebra and Equivalences to Transform
Graph Patterns in Neo4j, GraphQ 2016, EDBT,
http://ceur-ws.org/Vol-1558/paper24.pdf
GetVertices: returns a graph relation containing all
vertices of the underlying graph G
Expand: return the neighbors of a given node
72. Additional extensions
GetEdges: returns a graph relation containing all
edges of the underlying graph G
Gábor Szárnyas, József Marton:
openCypher specification, Technical report
http://docs.inf.mit.bme.hu/ingraph/pub/
opencypher-report.pdf
73. While pattern matching, Neo4j makes
sure to not include matches where the
same graph relationship is found
multiple times in a single pattern.
Uniqueness of edges
All-different operator
83. openCypher constructs
Standard constructs
o pattern matching
o filtering
o lists, maps
o data manipulation
o variable length paths
84. openCypher constructs
Standard constructs
o pattern matching
o filtering
o lists, maps
o data manipulation
o variable length paths
Legacy constructs
o indexing, constraints
o regular expressions
o some list functions,
including reduce
o most predicate functions
o shortest path functions
o CASE expressions
o id()
85. openCypher constructs
Standard constructs
o pattern matching
o filtering
o lists, maps
o data manipulation
o variable length paths
Legacy constructs
o indexing, constraints
o regular expressions
o some list functions,
including reduce
o most predicate functions
o shortest path functions
o CASE expressions
o id()
Difficult to handle
incrementally
86. Challenges for incremental openCypher
Lists
o ['a', 1, 2, true]
o ['a', [1, [2]], true]
o UNWIND
Efficient aggregation
o min(), max()
o collect()
Bag semantics, ORDER BY, SKIP and LIMIT
o Idea: collect(x ORDER BY x.name)
87. Incremental queries – use cases
Standing queries on large & quickly changing graph
Runtime monitoring (train example)
Model validation: The Train Benchmark
Static analysis of JavaScript source code
Fraud detection
IT infrastructure monitoring
88. Future work
Path operator
Giacomo Bergami, Matteo Magnani, and Danilo Montesi,
A join operator for property graphs, GraphQ 2016, EDBT,
http://jackbergus.alwaysdata.net/paper_graph_graphq2
017.pdf
Unwind operator: 𝜔
Elena Botoeva et al.:
A Formal Presentation of MongoDB,
https://arxiv.org/abs/1603.09291
89. Open-Source Projects
Incremental Graph Engine:
https://github.com/ftsrg/ingraph
Train Benchmark:
https://github.com/ftsrg/trainbenchmark
BME-MODES3:
https://github.com/ftsrg/bme-modes3
Available under EPL v1.0.