Label Expressions

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

A label is the name you gave a vertex or edge in the graph definition, such as individual or orderProduct. A label expression lets you combine those names.

Write the expression after the colon: (v:<label_expression>) for an object, -[e:<label_expression>]-> for a connection.

Operators 

OperatorNameMeaningEcommerce example
:LabelLabelHas this label(i:individual)
&ConjunctionHas both labels(i:individual & loyaltyMember)
|DisjunctionHas either label(item:individual | product)
!NegationDoesn’t have this label(v:!loyaltyMember)
%WildcardAny vertex or any edge(item:%)

A bare (v) is the same as (v:%).

Operators bind in this order: !, then &, then |. So individual | product & featured means individual | (product & featured). And !individual & product means (!individual) & product. Use parentheses to override the default. To negate a negation, parenthesize the inner expression: !(!individual).

1WITH pg AS PROPERTY GRAPH (...)
2SELECT * FROM GRAPH_TABLE(pg
3    MATCH (item:(individual | product) & featured)
4    COLUMNS (item.name)
5) AS gt;

That matches a featured product, not a featured customer, unless you also gave customers the featured label.

Extra Labels for These Examples 

The commerce graph in Defining a Property Graph has one label per table. Use this copy of that definition, with extra labels, for the examples on this page.

Don’t put loyaltyMember on every customer if you want individual & !loyaltyMember to return rows. This definition uses a second Individual vertex table, otherCustomers, for customers who aren’t loyalty members. Filter each Individual table so the same customer isn’t in both, or every customer still matches loyaltyMember through loyaltyCustomers.

1WITH pg AS PROPERTY GRAPH (
2    VERTEX TABLES (
3        (SELECT * FROM ssot__Individual__dlm WHERE ssot__Id__c IN ('I-100'))
4            AS loyaltyCustomers KEY (ssot__Id__c)
5            LABEL individual PROPERTIES (
6                ssot__Id__c AS individualId,
7                ssot__FirstName__c AS name
8            )
9            LABEL loyaltyMember,
10        (SELECT * FROM ssot__Individual__dlm WHERE ssot__Id__c NOT IN ('I-100'))
11            AS otherCustomers KEY (ssot__Id__c)
12            LABEL individual PROPERTIES (
13                ssot__Id__c AS individualId,
14                ssot__FirstName__c AS name
15            ),
16        ssot__SalesOrder__dlm AS orders KEY (ssot__Id__c)
17            LABEL salesOrder PROPERTIES (
18                ssot__Id__c AS orderId,
19                ssot__Name__c AS name
20            ),
21        ssot__GoodsProduct__dlm AS products KEY (ssot__Id__c)
22            LABEL product PROPERTIES (
23                ssot__Id__c AS productId,
24                ssot__Name__c AS name
25            )
26            LABEL featured
27            LABEL seasonal
28    )
29    EDGE TABLES (
30        ssot__SalesOrder__dlm AS loyaltyOrders KEY (ssot__Id__c)
31            SOURCE KEY (ssot__SoldToCustomerId__c) REFERENCES loyaltyCustomers
32            DESTINATION KEY (ssot__Id__c) REFERENCES orders
33            LABEL customerOrder PROPERTIES (
34                ssot__CreatedDate__c AS createdDate
35            ),
36        ssot__SalesOrder__dlm AS otherOrders KEY (ssot__Id__c)
37            SOURCE KEY (ssot__SoldToCustomerId__c) REFERENCES otherCustomers
38            DESTINATION KEY (ssot__Id__c) REFERENCES orders
39            LABEL customerOrder PROPERTIES (
40                ssot__CreatedDate__c AS createdDate
41            ),
42        ssot__SalesOrderProduct__dlm AS orderProducts KEY (ssot__Id__c)
43            SOURCE KEY (ssot__SalesOrderId__c) REFERENCES orders
44            DESTINATION KEY (ssot__ProductId__c) REFERENCES products
45            LABEL orderProduct
46            LABEL promotionOrderProduct PROPERTIES (
47                ssot__CreatedDate__c AS createdDate,
48                ssot__OrderedQuantity__c AS quantity
49            )
50    )
51)

The two Individual subqueries keep loyalty members and other customers in separate vertex tables. The two customerOrder edge tables give both groups a path to orders.

Customers Who Are Loyalty Members 

1WITH pg AS PROPERTY GRAPH (...)
2SELECT * FROM GRAPH_TABLE(pg
3    MATCH (i:individual & loyaltyMember)
4    COLUMNS (i.individualId, i.name)
5) AS gt;

Customers or Products 

1WITH pg AS PROPERTY GRAPH (...)
2SELECT * FROM GRAPH_TABLE(pg
3    MATCH (item:individual | product)
4    COLUMNS (item.name)
5) AS gt;

Customers Who Aren't Loyalty Members 

1WITH pg AS PROPERTY GRAPH (...)
2SELECT * FROM GRAPH_TABLE(pg
3    MATCH (i:individual & !loyaltyMember)
4    COLUMNS (i.name)
5) AS gt;

Regular or Promotion Line Items 

1WITH pg AS PROPERTY GRAPH (...)
2SELECT * FROM GRAPH_TABLE(pg
3    MATCH (i:individual)-[:customerOrder]->(:salesOrder)
4        -[line:orderProduct | promotionOrderProduct]->(product:product)
5    COLUMNS (i.individualId, product.productId, line.createdDate, line.quantity)
6) AS gt;
1WITH pg AS PROPERTY GRAPH (...)
2SELECT * FROM GRAPH_TABLE(pg
3    MATCH (i:individual)-[:customerOrder]->(:salesOrder)
4        -[line:orderProduct & promotionOrderProduct]->(product:product)
5    COLUMNS (i.individualId, product.productId, line.createdDate, line.quantity)
6) AS gt;

Featured or Seasonal Products 

Using the same variable twice keeps only the records that match both patterns.

1WITH pg AS PROPERTY GRAPH (...)
2SELECT * FROM GRAPH_TABLE(pg
3    MATCH (item:product), (item:featured | seasonal)
4    COLUMNS (item.productId, item.name)
5) AS gt;

That is the same as MATCH (item:product & (featured | seasonal)).

Related Documentation