Budapest University of Technology and Economics Department of Measurement and Information Systems Department of Telecommunications and Media Informatics
Incremental Graph Queries for Cypher Gbor Szrnyas, Jzsef Marton - - PowerPoint PPT Presentation
Incremental Graph Queries for Cypher Gbor Szrnyas, Jzsef Marton - - PowerPoint PPT Presentation
Incremental Graph Queries for Cypher Gbor Szrnyas, Jzsef Marton Budapest University of Technology and Economics McGill University, Montral Budapest University of Technology and Economics Department of Measurement and Information Systems
Live railway model
Live railway model
Live railway model
Live railway model
Live railway model
Proximity detection
Live railway model
Proximity detection
Live railway model
Proximity detection
Live railway model
Trailing the switch Proximity detection
Live railway model
Live railway model
Live railway model
c d e g f div 2 a b 1
Live railway model
c d e g f div 2
NEXT NEXT STRAIGHT TOP ON
a b 1
NEXT ON NEXT
Proximity detection
Proximity detection
≤ 𝟑 segments
Proximity detection
seg1
NEXT: 1..2
t1
ON
Proximity detection
seg2
t2
ON
≤ 𝟑 segments
Proximity detection
seg1
NEXT: 1..2
t1
ON
MATCH (t1:Train)-[:ON]->(seg1:Segment)
- [:NEXT*1..2]->(seg2:Segment)
<-[:ON]-(t2:Train) RETURN t1, t2, seg1, seg2
Proximity detection
seg2
t2
ON
≤ 𝟑 segments
Proximity detection
seg1
NEXT: 1..2
t1
ON
MATCH (t1:Train)-[:ON]->(seg1:Segment)
- [:NEXT*1..2]->(seg2:Segment)
<-[:ON]-(t2:Train) RETURN t1, t2, seg1, seg2
Proximity detection
seg2
t2
ON
≤ 𝟑 segments
Trailing the switch
Trailing the switch
seg div t
STRAIGHT ON
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
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
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
Incremental queries
Incremental queries
- Register a set of standing queries
- Continuously evaluate queries on changes
Incremental queries
- Register a set of standing queries
- Continuously evaluate queries on changes
- The Rete algorithm (1974)
- Originally for rule-based expert systems
- Indexes the graph and caches interim query results
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
div
STRAIGHT
Trailing the switch
ON
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
c d e g f div 2
NEXT NEXT STRAIGHT TOP
a b 1
NEXT NEXT ON ON
div
STRAIGHT
Trailing the switch
ON
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
c d e g f div 2
NEXT NEXT STRAIGHT TOP
a b 1
NEXT NEXT ON ON
div
STRAIGHT
Trailing the switch
ON
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
c d e g f div 2
NEXT NEXT STRAIGHT TOP
a b 1
NEXT NEXT ON ON
div
STRAIGHT
Trailing the switch
ON
a 1
ON
e 2
ON
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
e 2
ON
a 1
ON
c d e g f div 2
NEXT NEXT STRAIGHT TOP
a b 1
NEXT NEXT ON ON
div
STRAIGHT
Trailing the switch
ON
a 1
ON
e 2
ON
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
e 2
ON
a 1
ON
c d e g f div 2
NEXT NEXT STRAIGHT TOP
a b 1
NEXT NEXT ON ON
div
STRAIGHT
Trailing the switch
ON
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
e 2
ON
a 1
ON
c d e g f div 2
NEXT NEXT STRAIGHT TOP
a b 1
NEXT NEXT ON ON
div
STRAIGHT
Trailing the switch
ON
e div
STRAIGHT
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
e 2
ON
a 1
ON
c d e g f div 2
NEXT NEXT STRAIGHT TOP
a b 1
NEXT NEXT ON ON
div
STRAIGHT
Trailing the switch
ON
e div
STRAIGHT
e div
STRAIGHT
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
e div
STRAIGHT
e 2
ON
a 1
ON
c d e g f div 2
NEXT NEXT STRAIGHT TOP
a b 1
NEXT NEXT ON ON
div
STRAIGHT
Trailing the switch
ON
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
e div
STRAIGHT
e 2
ON
a 1
ON
c d e g f div 2
NEXT NEXT STRAIGHT TOP
a b 1
NEXT NEXT ON ON
div
STRAIGHT
Trailing the switch
ON
e div
STRAIGHT
e 2
ON
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
e div
STRAIGHT
e 2
ON
a 1
ON
c d e g f div 2
NEXT NEXT STRAIGHT TOP
a b 1
NEXT NEXT ON ON
div
STRAIGHT
Trailing the switch
ON
e div
STRAIGHT
e 2
ON
e div 2
STRAIGHT ON
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
e div
STRAIGHT
e 2
ON
a 1
ON
e div
STRAIGHT
2
ON
c d e g f div 2
NEXT NEXT STRAIGHT TOP
a b 1
NEXT NEXT ON ON
div
STRAIGHT
Trailing the switch
ON
e div
STRAIGHT
e 2
ON
e div 2
STRAIGHT ON
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
e div
STRAIGHT
e 2
ON
a 1
ON
div
STRAIGHT ON
c d e g f div 2
NEXT NEXT STRAIGHT TOP
a b 1
NEXT NEXT ON ON
div
STRAIGHT
Trailing the switch
ON
e 2 div
STRAIGHT ON
e 2
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
e div
STRAIGHT
e 2
ON
a 1
ON
div
STRAIGHT ON
e div
STRAIGHT
2
ON
c d e g f div 2
NEXT NEXT STRAIGHT TOP
a b 1
NEXT NEXT ON ON
div
STRAIGHT
Trailing the switch
ON
e 2 div
STRAIGHT ON
e 2
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
e div
STRAIGHT
e 2
ON
a 1
ON
e div
STRAIGHT
2
ON
e div
STRAIGHT
2
ON
c d e g f div 2
NEXT NEXT STRAIGHT TOP
a b 1
NEXT NEXT ON ON
div
STRAIGHT
Trailing the switch
ON
div 2
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
e div
STRAIGHT
e 2
ON
a 1
ON
e div
STRAIGHT
2
ON
e div
STRAIGHT
2
ON
div 2 c d e g f div 2
NEXT NEXT STRAIGHT TOP
a b 1
NEXT NEXT ON ON
div
STRAIGHT
Trailing the switch
ON
div 2
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
e div
STRAIGHT
e 2
ON
a 1
ON
e div
STRAIGHT
2
ON
e div
STRAIGHT
2
ON
div 2 c d e g f div 2
NEXT NEXT STRAIGHT TOP
a b 1
NEXT NEXT ON ON
div
STRAIGHT
Trailing the switch
ON
div 2
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
e div
STRAIGHT
e 2
ON
a 1
ON
e div
STRAIGHT
2
ON
e div
STRAIGHT
2
ON
div 2 c e g f div
NEXT NEXT STRAIGHT TOP
a b 1
NEXT NEXT ON
div
STRAIGHT
Trailing the switch
ON
div
ON
2 d
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
e div
STRAIGHT
d 2
ON
a 1
ON
e div
STRAIGHT
2
ON
e div
STRAIGHT
2
ON
div 2 c e g f div
NEXT NEXT STRAIGHT TOP
a b 1
NEXT NEXT ON
div
STRAIGHT
Trailing the switch
ON
div
ON
2 d
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
e div
STRAIGHT
d 2
ON
a 1
ON
e div
STRAIGHT
2
ON
div 2 c e g f div
NEXT NEXT STRAIGHT TOP
a b 1
NEXT NEXT ON
div
STRAIGHT
Trailing the switch
ON
div
ON
2 d
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
e div
STRAIGHT
d 2
ON
a 1
ON
div 2 c e g f div
NEXT NEXT STRAIGHT TOP
a b 1
NEXT NEXT ON
div
STRAIGHT
Trailing the switch
ON
div
ON
2 d
πt.number, sw σsw.position = ′diverging′
⋈
STRAIGHT ON
e div
STRAIGHT
d 2
ON
a 1
ON
c e g f div
NEXT NEXT STRAIGHT TOP
a b 1
NEXT NEXT ON
div
STRAIGHT
Trailing the switch
ON
div
ON
2 d
Batch vs. incremental queries
- Batch queries
(pull / request-driven):
- 1. Client selects a query
- 2. Results are calculated
- Query results
- btained on demand
Batch vs. incremental queries
- Batch queries
(pull / request-driven):
- 1. Client selects a query
- 2. Results are calculated
- Query results
- btained 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
Incremental query engines
- CLIPS
C structures NASA
- Drools
POJO Red Hat
- VIATRA
EMF BME / IncQuery Labs.
Incremental query engines
- CLIPS
C structures NASA
- Drools
POJO Red Hat
- VIATRA
EMF BME / IncQuery Labs.
- INSTANS
RDF Aalto University
- i3QL
POJO TU Darmstadt
- IncQuery-D
RDF BME
Incremental query engines
- CLIPS
C structures NASA
- Drools
POJO Red Hat
- VIATRA
EMF BME / IncQuery Labs.
- INSTANS
RDF Aalto University
- i3QL
POJO TU Darmstadt
- IncQuery-D
RDF BME
- No implementations for property graphs yet
ingraph
- An incremental, in-memory graph query engine
ingraph
- An incremental, in-memory graph query engine
ingraph client
ingraph
- An incremental, in-memory graph query engine
ingraph client
register queries
ingraph
- An incremental, in-memory graph query engine
ingraph client
register queries update graph
ingraph
- An incremental, in-memory graph query engine
ingraph client
register queries query results update graph
ingraph
- An incremental, in-memory graph query engine
ingraph client
register queries query results change notifications update graph
MATCH (t:Train)-[:ON]->(seg:Segment) <-[:STRAIGHT]-(sw:Switch) WHERE sw.position = 'diverging' RETURN t.number, sw
- penCypher
query
MATCH (t:Train)-[:ON]->(seg:Segment) <-[:STRAIGHT]-(sw:Switch) WHERE sw.position = 'diverging' RETURN t.number, sw
- penCypher
query Query syntax tree
MATCH (t:Train)-[:ON]->(seg:Segment) <-[:STRAIGHT]-(sw:Switch) WHERE sw.position = 'diverging' RETURN t.number, sw
Query parser
- penCypher
query Query syntax tree
MATCH (t:Train)-[:ON]->(seg:Segment) <-[:STRAIGHT]-(sw:Switch) WHERE sw.position = 'diverging' RETURN t.number, sw
Query parser
- penCypher
query Relational algebra model Query syntax tree
MATCH (t:Train)-[:ON]->(seg:Segment) <-[:STRAIGHT]-(sw:Switch) WHERE sw.position = 'diverging' RETURN t.number, sw
Relational algebra builder Query parser
- penCypher
query Relational algebra model Query syntax tree
MATCH (t:Train)-[:ON]->(seg:Segment) <-[:STRAIGHT]-(sw:Switch) WHERE sw.position = 'diverging' RETURN t.number, sw
Relational algebra builder Query parser
- penCypher
query Relational algebra model Query syntax tree
Relational algebra model Rete network Rete network model
Relational algebra model Rete network Rete network model Transformer and optimizer VIATRA
Relational algebra model Rete network Rete network model Transformer and optimizer VIATRA
Relational algebra model Rete network Rete network model Transformer and optimizer Query deployer VIATRA
FORMALIZATION OF OPENCYPHER
Relational algebra
- Standard relational algebra
- 𝜌, 𝜏
- ∪,∩,∖
- ×, ⋈
- Common extensions
- 𝜀 – duplicate elimination
- 𝛿 – grouping
- 𝜐 – sorting
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
Additional extensions
GetEdges: returns a graph relation containing all edges of the underlying graph G
Gábor Szárnyas, József Marton:
- penCypher specification, Technical report
http://docs.inf.mit.bme.hu/ingraph/pub/
- pencypher-report.pdf
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
EXAMPLE QUERIES
Uniqueness of edges
Get neighbours
Filter out based on node prop name
Use multiple MATCH clauses to do a Cartesian product
Two subgraphs
SwitchMonitored
INCREMENTAL GRAPH QUERIES WITH OPENCYPHER
- penCypher constructs
- Standard constructs
- pattern matching
- filtering
- lists, maps
- data manipulation
- variable length paths
- penCypher constructs
- Standard constructs
- pattern matching
- filtering
- lists, maps
- data manipulation
- variable length paths
- Legacy constructs
- indexing, constraints
- regular expressions
- some list functions,
including reduce
- most predicate functions
- shortest path functions
- CASE expressions
- id()
- penCypher constructs
- Standard constructs
- pattern matching
- filtering
- lists, maps
- data manipulation
- variable length paths
- Legacy constructs
- indexing, constraints
- regular expressions
- some list functions,
including reduce
- most predicate functions
- shortest path functions
- CASE expressions
- id()
Difficult to handle incrementally
Challenges for incremental openCypher
- Lists
- ['a', 1, 2, true]
- ['a', [1, [2]], true]
- UNWIND
- Efficient aggregation
- min(), max()
- collect()
- Bag semantics, ORDER BY, SKIP and LIMIT
- Idea: collect(x ORDER BY x.name)
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