Multi-Entity Query Visualization
Run the Multi-Entity Query Visualization MicroSim Fullscreen
Edit in the p5.js Editor
About This MicroSim
The chapter's sample query crosses employees, a project, departments, communication edges, and a license in a single statement. That is a lot to read at once. This MicroSim runs the query one clause at a time against a small graph of eight nodes so you can watch the pattern narrow from three candidates to two result rows.
The question the query answers: Which employees work on the Cloud Migration project, communicate daily with someone outside their own department, and hold a Jira license?
The sample graph contains:
- Four
:Employeenodes: Maria and James (Engineering), Carlos and Aisha (Product) - Two
:Departmentnodes, one:Projectnode (Cloud Migration), and one:Licensenode (Jira) WORKS_ON,WORKS_IN,COMMUNICATES_WITH(daily and weekly), andHOLDS_LICENSEedges
At each step the graph highlights what the current clause matches, the query panel marks the lines being executed, and the table underneath records the bindings found so far for each candidate e.
A conceptual trace
A real graph database chooses its own execution order with a query planner, and it matches the whole MATCH pattern together. The clause-by-clause order shown here is a teaching model. The result rows are the same either way.
How to Use
- Press Next to execute one clause, or Play to run all seven steps automatically. Back returns to the previous step and Reset returns to the start.
- Before each press of Next, predict which nodes and edges will light up, and which rows of the table will change.
- Watch for the two places where the pattern eliminates something:
- The
WHERE myDept <> otherDeptstep crosses out the daily edges between Maria and James, because both are in Engineering. - The
HOLDS_LICENSEstep drops Carlos as a candidate, because he has no Jira license.
- The
- Hover over any node to see its properties.
- Use the Speed slider to change how long each step stays on screen during playback.
- Uncheck Show Query to give the graph the full width. On narrow screens the query is hidden until you check the box.
The small gold e tag marks the employees that are still candidates for the variable e. A red tag with a line through it marks a candidate that has been dropped.
Iframe Embed Code
You can add this MicroSim to any web page by adding this to your HTML:
1 2 3 4 | |
Lesson Plan
Learning Objective
Students will execute a multi-entity Cypher query and trace the traversal path through the organizational graph model. (Bloom's Taxonomy: Apply)
Audience
College students and working professionals in information systems, human resources analytics, and enterprise architecture.
Duration
15 minutes
Prerequisites
- Cypher
MATCH,WHERE,RETURN, andORDER BY - The node types and edge types of the organizational graph model from this chapter
Activities
- Read the query (3 min): With the MicroSim at Step 1, read the Cypher text. In your own words, write the question it answers.
- Predict and step (7 min): Press Next once per clause. Before each press, write down which employees you expect to remain as candidates. Compare your prediction with the table.
- Explain the result (3 min): At the final step, explain why Maria has a
cross_dept_contactsvalue of 2 even though she has three daily contacts, and why Carlos does not appear at all. - Modify the query on paper (2 min): Change
{frequency: 'daily'}to{frequency: 'weekly'}. Using the graph, work out which rows would be returned.
Discussion Questions
- Carlos passes every clause except the last one. What would the result be if the
HOLDS_LICENSEline were removed? - The query uses
count(DISTINCT other). In this dataset, wouldcount(other)give a different answer? When could it? - How many tables and joins would the same question need in a relational database?
Assessment
Students are given a different question about the same graph, for example "Which employees in Product communicate daily with someone on the Cloud Migration project?", and write the Cypher query, list the nodes and edges it matches, and give the result rows.
References
- Neo4j Cypher Manual - Neo4j - Reference for
MATCHpatterns,WHEREfiltering, aggregation withcount(DISTINCT ...), andORDER BY. - Robinson, I., Webber, J., & Eifrem, E. (2015). Graph Databases (2nd ed.). O'Reilly Media.
- Cypher (query language) - Wikipedia - Overview of the declarative graph query language used in this book.
- p5.js Reference - p5.js - Documentation for the JavaScript library used to build this MicroSim.