Path Patterns and Quantifiers
Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API
A MATCH path is a walk through your graph. Such as customer, then order, then product. This page shows how to follow more than one hop, choose a direction, and repeat a hop.
The examples use the commerce graph from Defining a Property Graph.
Chain the walk in the order the objects interact with each other. Such as how a shopper’s order actually happens.
This pattern finds two different customers who ordered the same product.
Read it as: start at one customer, go to their order, go to the product, then walk back out through another order to another customer.
You can leave out a vertex or edge at either end. Data 360 SQL fills in an anonymous element.
| Written pattern | Same as |
|---|---|
MATCH -[e:customerOrder]->(order:salesOrder) | MATCH ()-[e:customerOrder]->(order:salesOrder) |
MATCH (i:individual)-[e:customerOrder]-> | MATCH (i:individual)-[e:customerOrder]->() |
MATCH -[:orderProduct]->(product:product)<-[:orderProduct]- | MATCH ()-[:orderProduct]->(product:product)<-[:orderProduct]-() |
Separate independent patterns with commas. If two patterns reuse the same variable name, Data 360 SQL fuses them into one connected pattern. That’s how (item:product), (item:featured) keeps only products that are also featured.
The arrow says which way to traverse the edge between two objects.
| Pattern | Direction | Meaning |
|---|---|---|
(a)-[e]->(b) | Right | Walk from a to b. |
(a)<-[e]-(b) | Left | Walk from b to a. |
(a)-[e]-(b) | Either | Walk either way. A one-way edge that isn’t a self-loop can match twice, once in each writing. |
A quantifier repeats an edge a set number of times. Put it on the edge, not on the vertex.
| Quantifier | Meaning |
|---|---|
{n} | Exactly n hops. |
{m,n} | Between m and n hops, inclusive. |
A quantifier works on a right, left, or either-way edge.
In the commerce graph, one hop is not enough to reach a product. Customer to order is one hop. Order to product is the second hop.
Hops in the middle aren’t limited to a label.
These patterns omit the edge label because the two hops use different labels: customerOrder, then orderProduct. An unlabeled edge can match either one.
You can filter every repeated hop.
A variable on a quantified edge is a group variable. The local WHERE runs on every hop, which is why e.createdDate IS NOT NULL can require a date on both the order hop and the line-item hop. Don’t use that variable in the outer WHERE or COLUMNS.
These forms aren’t supported yet: {0,2}, {2,}, *, +, ?, and shortest-path queries.
A two-hop path is Avery’s own product. A four-hop path can reach a product through another customer who ordered something Avery also ordered. The ending :product label drops paths that stop on an order or another customer.
The query returns one row for each path. The same product can appear more than once if more than one path reaches it.
This query returns other customers connected to Avery by exactly four hops: Avery → order → shared product → other order → other customer.