A Neo4j Path Through the Christmas Holidays.

Dashing through the snow with arrows, triangles, paths, stumps, Cypher queries and Lee Majors.

Dan Flavin
Neo4j Developer Blog
4 min readDec 21, 2020

--

Image drawn with arrows.app

The classic Neo4j arrows web tool has been used to sketch out initial Neo4j graph constructs for what feels like a long and never ending winters nap. It is great tool built by Neo4j engineers in their spare time as a Neo4j Labs project, but it is getting a little past its expiration date. Fortunately those same wonderful engineers took the spirit of the holiday season to heart. There is now available a much more functional version of the arrows tool available on the arrows.app site (versus the old tool was found at the apc jones site). There will probably be a blog post soon detailing the new arrows app, but until then you can go to the Neo4j Labs arrows.app documentation page to for an introduction.

Our Christmas tree image above was created using the new arrows.app and shared internally by one of the Neo4j engineers. It brought joyous thoughts of Christmas gifts and warm family holidays past, present, and future. Obviously it also brought happy thoughts of Cypher query language patterns.

The image could be used as the graph in the Using the Neo4j Graph Database and Cypher To Solve This Brain Teaser. Why Argue? post. I use that post as background material for explaining Cypher queries and graph pattern concepts during Neo4j field engineer led education sessions¹. The post attempts to illustrate the fundamental power of graph patterns in a Cypher query counting the number of triangles embedded in a triangle stored as a graph. The graph used as an example in the post is symmetrical and looks like the tree image above, minus the bottom “stump”. Attendees to the sessions have asked if the Cypher query used to count triangles would still return valid results if the triangle symmetry is broken by adding or removing nodes and relationships from the graph. The “stump” in the tree diagram above is an example of one such modification to the graph data. Spoiler: Of course the query would still return the correct answer.

Creating a graph using the new arrows.app to add the “stump” following the triangle graph pattern is represented by the :Point nodes with the properties of pID 9 and 10:

A small “xmas” tree to for counting embedded triangles

How many embedded triangle patterns exist in the this graph? There are 12 without the bottom “stump” and 13 with. Why? Because there’s one more triangle pattern starting from the :Point node pID:0 that includes the nodes with the properties pID:9 and pID:10 that is part of our triangle counting query:

See the original post for an explanation and to see how the graph and query pattern were developed.

What would happen if a mean old Grinch tries to ruin our graph Christmas by stealing all the :Nodes and :Relationships that make up our tree?

Of course the Grinch would puzzle and then say “I must start with node (:Point {pID:2}) because it belongs to little Cindy Lou Who. A Who who is no more than two”. Just to keep things interesting, let’s mash-up and and say that the mean old Grinch was only able to get away with Cindy Lou Who’s node (:Point {pID:2}) before his nefarious plan is thwarted by Lee Majors as in the movie Scrooged.

We’d end up with a sad looking tree graph like so:

You’re a mean one, Mr. Grinch

Not to worry! We lost a node, but little Cindy Lou Who and the Whos down in Whoville are still happy, because they know that it’s the triangles that count! Our query returns 4, the correct number of triangles based on our query pattern.

Best wishes and here’s to everyone having a safe, healthy and happy year!

¹ There are thorough and free online Neo4j courses covering Cypher and the Neo4j graph database in detail available from the Neo4j Graph Academy. You can even become a Neo4j Certified Developer through the Graph Academy!

--

--

Neo4j Developer Blog
Neo4j Developer Blog

Published in Neo4j Developer Blog

Developer Content around Graph Databases, Neo4j, Cypher, Data Science, Graph Analytics, GraphQL and more.

Dan Flavin
Dan Flavin

Written by Dan Flavin

A Neo4j Field Engineer working with graph technology and concepts after becoming a true graph advocate by surviving an untold number of database technologies.