From 294fb0d20708663c157833f442993cba03e4a618 Mon Sep 17 00:00:00 2001 From: lidiazuin Date: Wed, 30 Nov 2022 12:13:16 +0100 Subject: [PATCH 1/3] Editions made after review of the expressions section --- modules/ROOT/pages/clauses/match.adoc | 1 + modules/ROOT/pages/clauses/where.adoc | 108 ++++++++------- modules/ROOT/pages/syntax/expressions.adoc | 147 +++++++++++---------- modules/ROOT/pages/syntax/patterns.adoc | 2 + 4 files changed, 133 insertions(+), 125 deletions(-) diff --git a/modules/ROOT/pages/clauses/match.adoc b/modules/ROOT/pages/clauses/match.adoc index 9235d9601..5df105c50 100644 --- a/modules/ROOT/pages/clauses/match.adoc +++ b/modules/ROOT/pages/clauses/match.adoc @@ -311,6 +311,7 @@ Returns all actors that `ACTED_IN` *'Wall Street'*. 1+d|Rows: 3 |=== +Read more about xref:/syntax/expressions.adoc#relationship-type-expressions[relationship type expressions]. [[match-on-multiple-rel-types]] === Match on multiple relationship types diff --git a/modules/ROOT/pages/clauses/where.adoc b/modules/ROOT/pages/clauses/where.adoc index 1a062b4d8..7b7cd6bf0 100644 --- a/modules/ROOT/pages/clauses/where.adoc +++ b/modules/ROOT/pages/clauses/where.adoc @@ -10,6 +10,7 @@ * xref::clauses/where.adoc#where-introduction[Introduction] * xref::clauses/where.adoc#query-where-basic[Basic usage] + ** xref::clauses/where.adoc#node-pattern-predicates[Node pattern predicates] ** xref::clauses/where.adoc#boolean-operations[Boolean operations] ** xref::clauses/where.adoc#filter-on-node-label[Filter on node label] ** xref::clauses/where.adoc#filter-on-node-property[Filter on node property] @@ -40,7 +41,6 @@ ** xref::clauses/where.adoc#simple-range[Simple range] ** xref::clauses/where.adoc#composite-range[Composite range] * xref::clauses/where.adoc#pattern-element-predicates[Pattern element predicates] - ** xref::clauses/where.adoc#node-pattern-predicates[Node pattern predicates] ** xref::clauses/where.adoc#relationship-pattern-predicates[Relationship pattern predicates] @@ -82,7 +82,58 @@ CREATE (andy:Swedish:Person {name: 'Andy', age: 36, belt: 'white'}), [[query-where-basic]] -== Basic usage +== + +[[node-pattern-predicates]] +=== Node pattern predicates + +`WHERE` can appear inside a node pattern in a `MATCH` clause or a pattern comprehension: + + +.+WHERE+ +====== + +.Query +[source, cypher, indent=0] +---- +WITH 30 AS minAge +MATCH (a:Person WHERE a.name = 'Andy')-[:KNOWS]->(b:Person WHERE b.age > minAge) +RETURN b.name +---- + +.Result +[role="queryresult",options="header,footer",cols="1*(b WHERE b:Person) | b.name] AS friends +---- + +.Result +[role="queryresult",options="header,footer",cols="1*> in order to specify additional constraints. - -[[node-pattern-predicates]] -=== Node pattern predicates - -`WHERE` can appear inside a node pattern in a `MATCH` clause or a pattern comprehension: - - -.+WHERE+ -====== - -.Query -[source, cypher, indent=0] ----- -WITH 30 AS minAge -MATCH (a:Person WHERE a.name = 'Andy')-[:KNOWS]->(b:Person WHERE b.age > minAge) -RETURN b.name ----- - -.Result -[role="queryresult",options="header,footer",cols="1*(b WHERE b:Person) | b.name] AS friends ----- - -.Result -[role="queryresult",options="header,footer",cols="1*> but is more powerful because it allows you to use `MATCH` and `WHERE` clauses internally. Moreover, it can appear in any expression position, unlike path patterns. -If the subquery evaluates to at least one row, the whole expression will become true. +If the subquery evaluates to at least one row, the whole expression will become `true`. This also means that the system only needs to evaluate if there is at least one row and can skip the rest of the work. @@ -1038,7 +1038,7 @@ Label expressions evaluate to `true` or `false` when applied to the set of label Assuming no other filters are applied, then a label expression evaluating to `true` means the node is matched. -The following table displays whether the label expression matches the node: +The following table displays whether the label expression matches the relationship: .Label expression matches [cols="^3,^2,^2,^2,^2,^2,^2,^2,^2"] @@ -1271,22 +1271,22 @@ CREATE image:graph_label_expressions.svg[] -* xref:syntax/expressions.adoc#label-expressions-match-without-label-expression[] -* xref:syntax/expressions.adoc#label-expressions-match-on-single-node-label[] -* xref:syntax/expressions.adoc#label-expressions-match-and-expression[] -* xref:syntax/expressions.adoc#label-expressions-match-or-expression[] -* xref:syntax/expressions.adoc#label-expressions-match-not-expression[] -* xref:syntax/expressions.adoc#label-expressions-match-wildcard-expression[] -* xref:syntax/expressions.adoc#label-expressions-match-nesting-label-expression[] -* xref:syntax/expressions.adoc#label-expressions-match-predicate-label-expression[] -* xref:syntax/expressions.adoc#label-expressions-match-return-label-expression[] +* xref:syntax/expressions.adoc#label-expressions-node-pattern-without-label-expressions[] +* xref:syntax/expressions.adoc#label-expressions-node-pattern-with-single-node-label[] +* xref:syntax/expressions.adoc#label-expressions-node-pattern-with-and-expression[] +* xref:syntax/expressions.adoc#label-expressions-note-pattern-with-or-expression[] +* xref:syntax/expressions.adoc#label-expressions-node-pattern-with-not-expressions[] +* xref:syntax/expressions.adoc#label-expressions-node-pattern-with-wildcard-expression[] +* xref:syntax/expressions.adoc#label-expressions-node-pattern-with-nested-label-expressions[] +* xref:syntax/expressions.adoc#label-expressions-where-clause-with-label-expression-as-predicate[] +* xref:syntax/expressions.adoc#label-expressions-with-return-clauses[] [discrete] -[[label-expressions-match-without-label-expression]] -=== Match without label expression +[[label-expressions-node-pattern-without-label-expressions]] +=== Node pattern without label expressions -A match without a label expression returns all nodes in the graph, non withstanding if the node is empty. +A node pattern without a label expression returns all nodes in the graph, including nodes without labels. .+Label expression+ ====== @@ -1328,10 +1328,10 @@ RETURN n.name AS name [discrete] -[[label-expressions-match-on-single-node-label]] -=== Match on single node label +[[label-expressions-node-pattern-with-single-node-label]] +=== Node pattern with a single node label -A match on a single node label returns the nodes that contains the specified label. +A node pattern with a single label returns the nodes that contain the specified label. .+Label expression+ @@ -1370,10 +1370,10 @@ RETURN n.name AS name [discrete] -[[label-expressions-match-and-expression]] -=== Match with an `AND` expression for the node labels +[[label-expressions-node-pattern-with-and-expression]] +=== Node pattern with an `AND` expression for the node labels -A match with an `AND` expression for the node label returns the nodes that contains both the specified labels. +A node pattern with an `AND` expression for the node label returns the nodes that contain both of the specified labels. .+Label expression+ @@ -1411,10 +1411,10 @@ RETURN n.name AS name [discrete] -[[label-expressions-match-or-expression]] -=== Match with an `OR` expression for the node labels +[[label-expressions-note-pattern-with-or-expression]] +=== Node pattern with an `OR` expression for the node labels -A match with an `OR` expression for the node label returns the nodes that contains either of the specified labels. +A match with `OR` expressions for the node label returns the nodes that contain either of the specified labels. .+Label expression+ @@ -1456,10 +1456,10 @@ RETURN n.name AS name [discrete] -[[label-expressions-match-not-expression]] -=== Match with a `NOT` expression for the node labels +[[label-expressions-node-pattern-with-not-expressions]] +=== Node pattern with `NOT` expressions for the node labels -A match with a `NOT` expression for the node label returns the nodes that does not contain the specified label. +A node pattern with a `NOT` expression for the node label returns the nodes that do not contain the specified label. .+Label expression+ @@ -1499,10 +1499,10 @@ RETURN n.name AS name [discrete] -[[label-expressions-match-wildcard-expression]] -=== Match with a `Wildcard` expression for the node labels +[[label-expressions-node-pattern-with-wildcard-expression]] +=== Node pattern with a `Wildcard` expression for the node labels -A match with a `Wildcard` expression for the node label returns the nodes that contains any label. +A node pattern with a `Wildcard` expression for the node label returns all the nodes that contain at least one label. .+Label expression+ @@ -1545,10 +1545,10 @@ RETURN n.name AS name [discrete] -[[label-expressions-match-nesting-label-expression]] -=== Match with a nesting of label expressions for the node labels +[[label-expressions-node-pattern-with-nested-label-expressions]] +=== Node pattern with nested label expressions -A match with a nesting of label expressions for the node label returns the nodes for which the full expression is `true`. +A node pattern with nested label expressions returns the nodes for which the full expression is `true`. .+Label expression+ @@ -1589,8 +1589,8 @@ RETURN n.name AS name [discrete] -[[label-expressions-match-predicate-label-expression]] -=== Match with label expressions in the predicate +[[label-expressions-where-clause-with-label-expression-as-predicate]] +=== `WHERE` clause with label expressions as a predicate A label expression can also be used as a predicate in the `WHERE` clause. @@ -1635,10 +1635,10 @@ RETURN n.name AS name [discrete] -[[label-expressions-match-return-label-expression]] -=== Match with label expressions in the return +[[label-expressions-with-return-clauses]] +=== Label expressions in the `WITH` and `RETURN` clauses -A label expression can also be used in the `WITH` or `RETURN` statement. +A label expression can also be used in a `WITH` or a `RETURN` clause. .+Label expression+ @@ -1700,6 +1700,10 @@ So for example the expressions: `(a)-[r:R&Q]-(b)` or `(a)-[r:!%]-(b)` will never That means that `()-[r:!R*]-()` is not allowed, whereas `()-[r:Q|R*]-()` is allowed. ==== +[NOTE] +==== +Relationships must have exactly one type so for example, `(a)-[r:R&Q]-(b)` or `(a)-[r:!%]-(b)` will never return any results. +==== The following table displays whether the relationship type expression matches the relationship: @@ -1782,17 +1786,20 @@ The following table displays whether the relationship type expression matches th |=== +Label expressions cannot be combined with label syntax. +For example, `:A:B&C` will throw an error. +Instead, use either `:A&B&C` or `:A:B:C`. *Examples:* -* xref:syntax/expressions.adoc#relationship-type-expressions-match-without-relationship-type-expression[] -* xref:syntax/expressions.adoc#relationship-type-expressions-match-on-single-relationship-type[] -* xref:syntax/expressions.adoc#relationship-type-expressions-match-or-expression[] -* xref:syntax/expressions.adoc#relationship-type-expressions-match-not-expression[] -* xref:syntax/expressions.adoc#relationship-type-expressions-match-nesting-type-expression[] -* xref:syntax/expressions.adoc#relationship-type-expressions-match-predicate-type-expression[] -* xref:syntax/expressions.adoc#relationship-type-expressions-match-return-type-expression[] -* xref:syntax/expressions.adoc#relationship-type-expressions-match-case-type-expression[] +* xref:syntax/expressions.adoc#relationship-type-expressions-pattern-without-relationship-type-expression[] +* xref:syntax/expressions.adoc#relationship-type-expressions-pattern-on-single-relationship-type[] +* xref:syntax/expressions.adoc#relationship-type-expressions-pattern-with-or-expression[] +* xref:syntax/expressions.adoc#relationship-type-expressions-pattern-with-not-expression[] +* xref:syntax/expressions.adoc#relationship-type-expressions-pattern-nested-type-expression[] +* xref:syntax/expressions.adoc#relationship-type-expressions-pattern-predicate-type-expression[] +* xref:syntax/expressions.adoc#relationship-type-expressions-pattern-with-return-type-expression[] +* xref:syntax/expressions.adoc#relationship-type-expressions-case-type-label-expression[] The following graph is used for the examples below: @@ -1801,13 +1808,13 @@ image:graph_relationship_type_expressions.svg[] [discrete] -[[relationship-type-expressions-match-without-relationship-type-expression]] -=== Match without relationship type expression +[[relationship-type-expressions-pattern-without-relationship-type-expression]] +=== Relationship pattern without relationship type expression -A match without a relationship type expression returns all relationships in the graph. +A relationship pattern without a relationship type expression returns all relationships in the graph. -.Relationship type expression +.Relationship type expressions ====== //// @@ -1838,10 +1845,10 @@ RETURN r.name as name [discrete] -[[relationship-type-expressions-match-on-single-relationship-type]] -=== Match on single relationship type +[[relationship-type-expressions-pattern-on-single-relationship-type]] +=== Relationship pattern with a single relationship type -A match on a single relationship type returns the relationships that contains the specified type. +A relationship pattern with a single relationship type returns the relationships that contain the specified type. .Relationship type expression @@ -1873,10 +1880,10 @@ RETURN r.name AS name [discrete] -[[relationship-type-expressions-match-or-expression]] -=== Match with an `OR` expression for the relationship types +[[relationship-type-expressions-pattern-with-or-expression]] +=== Relationship pattern with an `OR` expression for the relationship types -A match with an `OR` expression for the relationship type returns the relationships that contains either of the specified types. +A relationship pattern with an `OR` expression for the relationship type returns all relationships that contain either of the specified types. .Relationship type expression @@ -1902,10 +1909,10 @@ RETURN r.name AS name [discrete] -[[relationship-type-expressions-match-not-expression]] -=== Match with a `NOT` expression for the relationship types +[[relationship-type-expressions-pattern-with-not-expression]] +=== Relationship pattern with a `NOT` expression for the relationship types -A match with a `NOT` expression for the relationship type returns the relationships that does not contain the specified type. +A relationship pattern with a `NOT` expression for the relationship type returns all relationships that do not contain the specified type. .Relationship type expression @@ -1938,10 +1945,10 @@ RETURN r.name AS name [discrete] -[[relationship-type-expressions-match-nesting-type-expression]] -=== Match with a nesting of relationship type expressions for the relationship types +[[relationship-type-expressions-pattern-nested-type-expression]] +=== Relationship pattern with a nested relationship type expression -A match with a nesting of relationship type expressions for the relationship type returns the nodes for which the full expression is `true`. +A relationship pattern with a nested relationship type expression returns all relationships for which the full expression is `true`. .Relationship type expression @@ -1973,8 +1980,8 @@ RETURN r.name as name [discrete] -[[relationship-type-expressions-match-predicate-type-expression]] -=== Match with relationship type expressions in the predicate +[[relationship-type-expressions-pattern-predicate-type-expression]] +=== `WHERE` clause with a relationship type expression in the predicate A relationship type expression can also be used as a predicate in the `WHERE` clause. @@ -2010,10 +2017,10 @@ RETURN r.name AS name [discrete] -[[relationship-type-expressions-match-return-type-expression]] -=== Match with relationship type expression in the return +[[relationship-type-expressions-pattern-with-return-type-expression]] +=== `WITH` and `RETURN` clauses with a relationship type expression -A relationship type expression can also be used in the `WITH` or `RETURN` statement. +A relationship type expression can also be used in the `WITH` or `RETURN` clauses. .Relationship type expression @@ -2047,10 +2054,10 @@ RETURN r:R1|R2 AS result [discrete] -[[relationship-type-expressions-match-case-type-expression]] -=== Match with relationship type expression and node label expression in a case +[[relationship-type-expressions-case-type-label-expression]] +=== `CASE` expression with relationship type and label expressions -A relationship type expression and a label expression can also be used in a case statement. +A relationship type expression and a label expression can also be used in `CASE` expressions. .Relationship type expression diff --git a/modules/ROOT/pages/syntax/patterns.adoc b/modules/ROOT/pages/syntax/patterns.adoc index d2539cec1..378d470fd 100644 --- a/modules/ROOT/pages/syntax/patterns.adoc +++ b/modules/ROOT/pages/syntax/patterns.adoc @@ -45,6 +45,8 @@ For example: This simple pattern describes a single node, and names that node using the variable `a`. +You can specify additional constraints by introducing xref::/clauses/where.adoc#node-pattern-predicates[node pattern predicates]. + [[cypher-pattern-related-nodes]] == Patterns for related nodes From 7dc02afb80d81ede063887a86ce1371d83c685ee Mon Sep 17 00:00:00 2001 From: lidiazuin Date: Wed, 30 Nov 2022 12:14:50 +0100 Subject: [PATCH 2/3] Putting back a title that was mistakenly removed --- modules/ROOT/pages/clauses/where.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/ROOT/pages/clauses/where.adoc b/modules/ROOT/pages/clauses/where.adoc index 7b7cd6bf0..5174d8b58 100644 --- a/modules/ROOT/pages/clauses/where.adoc +++ b/modules/ROOT/pages/clauses/where.adoc @@ -82,7 +82,7 @@ CREATE (andy:Swedish:Person {name: 'Andy', age: 36, belt: 'white'}), [[query-where-basic]] -== +== Basic usage [[node-pattern-predicates]] === Node pattern predicates From bbc4462fd17e46ccd93ef68c9813748436f37a1e Mon Sep 17 00:00:00 2001 From: lidiazuin Date: Wed, 30 Nov 2022 14:25:36 +0100 Subject: [PATCH 3/3] Edition after review --- modules/ROOT/pages/syntax/expressions.adoc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/ROOT/pages/syntax/expressions.adoc b/modules/ROOT/pages/syntax/expressions.adoc index 51580b316..c07783c84 100644 --- a/modules/ROOT/pages/syntax/expressions.adoc +++ b/modules/ROOT/pages/syntax/expressions.adoc @@ -76,7 +76,7 @@ There may be an underscore between the `0x` or `0o` and the digits for hexadecim [[query-syntax-case]] -== `CASE` expression +== `CASE` expressions Generic conditional expressions may be expressed using the `CASE` construct. Two variants of `CASE` exist within Cypher: the simple form, which allows an expression to be compared against multiple values, and the generic form, which allows multiple conditional statements to be expressed. @@ -1702,7 +1702,8 @@ That means that `()-[r:!R*]-()` is not allowed, whereas `()-[r:Q|R*]-()` is allo [NOTE] ==== -Relationships must have exactly one type so for example, `(a)-[r:R&Q]-(b)` or `(a)-[r:!%]-(b)` will never return any results. +Relationships must have exactly one type. +For example `(a)-[r:R&Q]-(b)` or `(a)-[r:!%]-(b)` will never return any results. ==== The following table displays whether the relationship type expression matches the relationship: