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.
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.
Choose a Direction
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.
1-- Orders Avery placed2MATCH(i:individual)-[:customerOrder]->(order:salesOrder)WHERE i.name = 'Avery'34-- The customer for order O-1005MATCH(order:salesOrder)<-[:customerOrder]-(i:individual)WHERE order.orderId = 'O-100'67-- A customer and an order connected in either writing8MATCH(i:individual)-[:customerOrder]-(order:salesOrder)
Repeat a Hop
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.
1-- Avery's products: customer -> order -> product2MATCH(i:individual)-[]-{2}(product:product)34-- Avery's products, plus products reached through another customer's order5MATCH(i:individual)-[]-{2,4}(product:product)
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.
1MATCH(i:individual)-[e WHERE e.createdDate IS NOT NULL]-{2}(:product)
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.
Example: Products Connected to Avery
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.
1WITH pg AS PROPERTY GRAPH (...)2SELECT * FROM GRAPH_TABLE(pg3 MATCH(i:individual)-[]-{2,4}(product:product)4 WHERE i.name = 'Avery'5 COLUMNS (6 i.name AS individual_name,7 product.productId AS product_id,8 product.name AS product_name9)10)AS gt;
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.
1WITH pg AS PROPERTY GRAPH (...)2SELECT * FROM GRAPH_TABLE(pg3 MATCH(i:individual)-[]-{4}(other:individual)4 WHERE i.name = 'Avery'5 COLUMNS (6 i.individualId AS individual_id,7 other.individualId AS connected_individual_id,8 other.name AS connected_individual_name9)10)AS gt;