You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| `allReduce(accumulator = initial, stepVariable IN list \| reductionFunction, predicate) :: BOOLEAN`
379
-
| Returns true if, during the stepwise evaluation of a value across the elements in a given `LIST<ANY>`, the accumulated result satisfies a specified predicate at every step, allowing for the early pruning of paths that do not meet the predicate. label:new[Introduced in Neo4j 2025.08]
379
+
| Returns true if, during the stepwise evaluation of a value across the elements in a given `LIST<ANY>`, the accumulated result satisfies a specified predicate at every step.
380
+
Where that list is a group variable defined in a quantified path pattern, it allows for the early pruning of paths that do not satisfy the predicate. label:new[Introduced in Neo4j 2025.08]
Copy file name to clipboardExpand all lines: modules/ROOT/pages/functions/predicate.adoc
+14-17Lines changed: 14 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -109,7 +109,8 @@ RETURN all(i in emptyList WHERE true) as allTrue, all(i in emptyList WHERE false
109
109
.Details
110
110
|===
111
111
| *Syntax* 3+| `allReduce(accumulator = initial, stepVariable IN list \| reductionFunction, predicate)`
112
-
| *Description* 3+| Returns true if, during the stepwise evaluation of a value across the elements in a given LIST<ANY>, the accumulated result satisfies a specified predicate at every step, allowing for the early pruning of paths that do not meet the predicate.
112
+
| *Description* 3+| Returns true if, during the stepwise evaluation of a value across the elements in a given `LIST<ANY>`, the accumulated result satisfies a specified predicate at every step.
113
+
Where that list is a xref:patterns/variable-length-patterns.adoc#group-variables[group variable] defined in a xref:patterns/variable-length-patterns.adoc#quantified-path-patterns[quantified path pattern], it allows for the early pruning of paths that do not satisfy the predicate.
| `accumulator` | `ANY` | A variable that holds the result of the `reductionFunction` as the `list` is iterated.
115
116
It is initialized with the value of `initial`.
@@ -135,24 +136,21 @@ It has access to the variable `accumulator`, but not `stepVariable`.
135
136
.allReduce()
136
137
======
137
138
138
-
`allReduce()` is designed to optimize path expansions.
139
-
140
-
The below query finds `KNOWS` paths with a length of `3` where the cumulative age stays between `60` and `190`.
141
-
Paths exceeding this range at any step are pruned.
142
-
For example, a path starting with a node whose `age` value is less than `60` is automatically excluded, as is a path with a sequence such as `["Liam Neeson (70)", "Keanu Reeves (58)", "Kathryn Bigelow (71)"]` because its aggregated `age` value exceeds `190`.
139
+
The below query finds `KNOWS` paths with a length of `3` where the `accumulator` begins with first node's `age` and the accumulated `age` values of all nodes in the path never exceeds `230`.
140
+
Paths that do not meet this requirement are excluded, such as the path with the sequence `["Keanu Reeves (58)", "Carrie Anne Moss (55)", "Guy Pearce (55)", "Liam Neeson (70)"]` which has an aggregated `age` value of `238`.
143
141
144
142
.Find aggregated ages within a boundary
145
143
// tag::functions_predicate_allreduce_boundary[]
146
144
[source, cypher]
147
145
----
148
-
MATCH (()-[:KNOWS]-(n)){3}
146
+
MATCH (s) (()-[:KNOWS]-(n)){3}
149
147
WHERE allReduce(
150
-
acc = 0,
148
+
acc = s.age,
151
149
node IN n | acc + node.age,
152
-
60 < acc < 190
150
+
acc < 230
153
151
)
154
-
RETURN [i IN n | i.name || " (" + toString(i.age) || ")"] AS ageSequence,
155
-
reduce(acc = 0, node IN n | acc + node.age) AS aggregatedAges
152
+
RETURN [i IN [s] + n | i.name || " (" + toString(i.age) || ")"] AS ageSequence,
153
+
reduce(acc = 0, node IN [s] + n | acc + node.age) AS aggregatedAges
0 commit comments