Part 5 of 5 · 4 min read
Exercises
Easy
Easy 1: Name the two kinds of record (15 minutes)
Name the two kinds of record a property graph stores.
Done when: vertices and edges are both correctly named.
Hint
Vertices and edges.
Easy 2: Name what an edge records about direction (15 minutes)
State what two pieces of information an edge records that establish its direction.
Done when: the tail vertex (start) and the head vertex (end) are both correctly named.
Hint
The tail vertex (where the edge starts) and the head vertex (where the edge ends).
Easy 3: Name the term for following a chain of edges (15 minutes)
Name the term for following a chain of edges from a starting vertex to reach other vertices.
Done when: traversal is correctly named.
Hint
Traversal.
Medium
Medium 1: Model a relationship as vertices and edges (25 minutes)
Represent the fact that customer 501 wrote a review of book 1, giving it a rating of 4, as vertices and an edge.
Done when: a customer vertex and a book vertex are proposed, connected by an edge labeled something like REVIEWED, with the rating stored as a property on the edge itself.
Hint
A customer vertex and a book vertex connected by a REVIEWED edge, with the rating of 4 stored as a property on that edge.
Medium 2: Explain why no schema change is needed (25 minutes)
Explain why adding a new FOLLOWS_AUTHOR edge type to an existing graph requires no change to how existing WROTE edges are stored.
Done when: the explanation correctly notes that a graph has no predeclared restriction on which vertex types may connect, so a new edge label can be added independently of any existing edge type.
Hint
A graph has no predeclared restriction on which vertex types may connect, so a new edge label can be added independently, with no effect on how existing edges are stored.
Medium 3: Trace a two-step traversal (30 minutes)
Starting at book 1's vertex, trace a traversal that finds every customer who reviewed it, then every other book those same customers have also reviewed.
Done when: the trace correctly follows incoming REVIEWED edges backwards to reach the reviewing customers, then follows their outgoing REVIEWED edges forwards to reach the other books they reviewed.
Hint
Follow incoming REVIEWED edges backwards from book 1 to its reviewing customers, then follow their outgoing REVIEWED edges forwards to the other books they reviewed.
Hard
Hard 1: Decide graph versus relational for a scenario (30 minutes)
The bookstore wants to recommend books based on chains like "customers who follow an author who co-wrote a book with another author whose other books this customer has reviewed." Decide whether a graph or a relational schema fits this better, and justify it.
Done when: a graph is chosen, justified by the query following a long, multi-step chain of different relationship types, which would require a long and fragile chain of joins in a relational schema, one join per step in the chain.
Hint
A graph, since the query follows a long, multi-step chain of different relationship types, which would need one join per step, growing fragile, in a relational schema.
Hard 2: Identify what breaks a graph's flexibility (35 minutes)
Explain one real limitation of a property graph's schema-free connections, despite the flexibility they offer.
Done when: the explanation correctly notes that, because nothing restricts which vertex types may connect, the graph itself cannot catch a mistaken or nonsensical edge, such as connecting a book directly to another book with a WROTE label; any such validation has to be enforced by application code instead.
Hint
Nothing in the graph itself prevents a nonsensical edge, like connecting a book directly to another book with a WROTE label; that kind of validation has to be enforced in application code.
Hard 3: Convert a graph traversal to a relational join (40 minutes)
Using the vertices and edges relational schema from this page, write the SQL join that would answer the same question as the Cypher co-author query shown in this page.
Done when: a SQL query is produced that joins the edges table to itself (or self-joins twice), matching one edge labeled WROTE from Maria Chen's vertex to a book, and a second edge labeled WROTE from the same book to a different author vertex, correctly reproducing the two-hop traversal as an explicit join.
Hint
A query that joins the edges table to itself twice, matching a WROTE edge from Maria Chen's vertex to a book vertex, then a second WROTE edge from that same book vertex to a different author vertex.