Skip to content

Commit 07b8dd5

Browse files
LET and FILTER clean up (#1222)
1 parent a0694e5 commit 07b8dd5

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

modules/ROOT/pages/clauses/filter.adoc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ RETURN n.name AS name, n.age AS age
128128
`FILTER` and `WHERE` are both used to apply filter to queries.
129129
However, there are a number of important differences between them that arise from the fact that `FILTER` is a clause and `WHERE` is a subclause:
130130

131-
* While `WHERE` should not be understood as a filter after the matching is finished (it should rather be seen as adding constraints to a described pattern), `FILTER` should be understood as performing post-match filtering, and not as adding constraints to a described patterns.
131+
* `FILTER` acts on entities _after_ they have been matched, whereas `WHERE` constrains what rows get matched _before_ the match is performed.
132132
* `FILTER` cannot be used within `MATCH`, `OPTIONAL MATCH`, or `WITH` clauses but only alongside them.
133133
This means that, unlike `WHERE`, `FILTER` cannot be used to add filters inside patterns.
134134

@@ -140,9 +140,9 @@ This `OPTIONAL MATCH` example highlights the differences between the `WHERE` sub
140140
.`WHERE` constraining an `OPTIONAL MATCH` pattern
141141
[source, cypher]
142142
----
143-
UNWIND [32,37,40] AS ages
144-
OPTIONAL MATCH (p:Person)
145-
WHERE p.age = ages
143+
UNWIND [32,37,40] AS ageValue
144+
OPTIONAL MATCH (p:Person)
145+
WHERE p.age = ageValue
146146
RETURN p.name AS name, p.age AS age
147147
----
148148
@@ -165,10 +165,10 @@ The same is not true if `WHERE` is exchanged for `FILTER`:
165165
.`FILTER` adding post-filtering to `OPTIONAL MATCH`
166166
[source, cypher]
167167
----
168-
UNWIND [32,37,40] AS ages
169-
OPTIONAL MATCH (p:Person)
170-
FILTER p.age = ages
171-
RETURN p.name
168+
UNWIND [32,37,40] AS ageValue
169+
OPTIONAL MATCH (p:Person)
170+
FILTER p.age = ageValue
171+
RETURN p.name AS name, p.age AS age
172172
----
173173
174174
.Result
@@ -183,7 +183,7 @@ RETURN p.name
183183
|===
184184
185185
Unlike `WHERE`, `FILTER` is not part of the `OPTIONAL MATCH` and so removes entire rows from the result set based on the condition provided within the expression.
186-
That is, when `OPTIONAL MATCH` fails to find a match and `p` is `NULL`, `FILTER p.age = ages` cannot be evaluated, causing the entire row to be removed.
186+
That is, when `OPTIONAL MATCH` fails to find a match and `p` is `NULL`, `FILTER p.age = ageValue` cannot be evaluated, causing the entire row to be removed.
187187
188188
=====
189189

modules/ROOT/pages/clauses/let.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ The fact that `LET` does not drop variables means that it can be used to chain e
186186
.Chaining expressions: comparing `LET` and `WITH`
187187
=====
188188
189-
The below query shows that variables bound by a `LET` clause be referenced by subsequent clauses without being explicitly carried over.
189+
The below query shows that variables bound by a `LET` clause can be referenced by subsequent clauses without being explicitly carried over.
190190
Specifically, the variable `isExpensive` is created in the first `LET` clause and referenced again in the subsequent clauses.
191191
Note also that the variable `p`, bound in the `MATCH` clause, is available in the final `RETURN` clause despite not being referenced in any of `LET` clauses.
192192
@@ -244,7 +244,7 @@ Unlike `WITH`, `LET` cannot perform aggregations or be combined with `DISTINCT`.
244244
For example, in the following query, `WITH` could not be replaced by `LET`:
245245

246246
.Combining `WITH DISTINCT` and aggregations on expressions
247-
[source, source]
247+
[source, cypher]
248248
----
249249
MATCH (c:Customer)-[:BUYS]->(p:Product)
250250
WITH DISTINCT c, sum(p.price) AS totalSpent
@@ -268,7 +268,7 @@ RETURN c.firstName AS customer, totalSpent
268268
|===
269269

270270
.Combining `WITH` and `LET`
271-
[source, source]
271+
[source, cypher]
272272
----
273273
MATCH (c:Customer)-[:BUYS]->(p:Product)
274274
WITH DISTINCT c, sum(p.price) AS totalSpent

0 commit comments

Comments
 (0)