Skip to content

Commit 4513a02

Browse files
Expressions tags for 25 (#1253)
Co-authored-by: Richard Sill <[email protected]>
1 parent e2d83c0 commit 4513a02

15 files changed

+172
-12
lines changed

modules/ROOT/pages/clauses/where.adoc

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ CREATE (andy:Swedish:Person {name: 'Andy', age: 36}),
4343
== Basic filtering
4444

4545
.Filter on a node label
46-
// tag::clauses_where_in_match_clause[]
46+
// tag::clauses_where_node_label[]
4747
[source, cypher]
4848
----
4949
MATCH (n)
5050
WHERE n:Swedish
5151
RETURN n.name AS name
5252
----
53-
// end::clauses_where_in_match_clause[]
53+
// end::clauses_where_node_label[]
5454

5555
.Result
5656
[role="queryresult",options="header,footer",cols="1*<m"]
@@ -63,12 +63,14 @@ RETURN n.name AS name
6363
|===
6464

6565
.Filter on a node property
66+
// tag::clauses_where_node_property[]
6667
[source, cypher]
6768
----
6869
MATCH (n:Person)
6970
WHERE n.age < 35
7071
RETURN n.name AS name, n.age AS age
7172
----
73+
// end::clauses_where_node_property[]
7274

7375
.Result
7476
[role="queryresult",options="header,footer",cols="2*<m"]
@@ -115,12 +117,14 @@ To filter on a property using a dynamically computed name, use square brackets `
115117
----
116118

117119
.Filter on a dynamically computed node property
120+
// tag::clauses_where_dynamic[]
118121
[source, cypher]
119122
----
120123
MATCH (n:Person)
121124
WHERE n[$propname] > 40
122125
RETURN n.name AS name, n.age AS age
123126
----
127+
// end::clauses_where_dynamic[]
124128

125129
.Result
126130
[role="queryresult",options="header,footer",cols="2*<m"]
@@ -185,12 +189,14 @@ In this case, `name` is the only variable in scope for the `RETURN` clause.
185189
=== Fixed-length patterns
186190

187191
.`WHERE` inside a node pattern
192+
// tag::clauses_where_node_pattern[]
188193
[source, cypher]
189194
----
190195
WITH 35 AS minAge
191196
MATCH (a:Person WHERE a.name = 'Andy')-[:KNOWS]->(b:Person WHERE b.age > minAge)
192197
RETURN b.name AS name
193198
----
199+
// end::clauses_where_node_pattern[]
194200

195201
.Result
196202
[role="queryresult",options="header,footer",cols="1*<m"]
@@ -269,13 +275,15 @@ RETURN [(a)-[r:KNOWS WHERE r.since < minYear]->(b:Person) | r.since] AS years
269275
If matching for variable length patterns, `WHERE` can only be used together with the xref:patterns/variable-length-patterns.adoc#quantified-path-patterns[quantified path pattern] or xref:patterns/variable-length-patterns.adoc#quantified-relationships[quantified relationships] syntax.
270276

271277
.Allowed - `WHERE` predicate inside a quantified relationship
278+
// tag::clauses_where_var_length[]
272279
[source, cypher]
273280
----
274281
MATCH p = (a:Person {name: "Andy"})-[r:KNOWS WHERE r.since < 2011]->{1,4}(:Person)
275282
RETURN [n IN nodes(p) | n.name] AS paths
276283
----
284+
// end::clauses_where_var_length[]
277285

278-
Note that any path´s including `Timothy` and `Susan` are excluded by the `WHERE` predicate, since their incoming `KNOWS` relationships both have a `since` value that is higher than `2011.`
286+
Note that any paths including `Timothy` and `Susan` are excluded by the `WHERE` predicate, since their incoming `KNOWS` relationships both have a `since` value that is higher than `2011.`
279287

280288
.Result
281289
[role="queryresult",options="header,footer",cols="1*<m"]

modules/ROOT/pages/expressions/conditional-expressions.adoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ END
7575
[[case-simple-examples]]
7676
=== Example
7777

78+
// tag::expressions_conditional_expressions_simple[]
7879
[source, cypher]
7980
----
8081
MATCH (n:Person)
@@ -85,6 +86,8 @@ CASE n.eyes
8586
ELSE 3
8687
END AS result, n.eyes
8788
----
89+
// end::expressions_conditional_expressions_simple[]
90+
8891

8992
[role="queryresult",options="header,footer",cols="2*<m"]
9093
|===
@@ -148,6 +151,7 @@ END
148151
[[case-extended-simple-examples]]
149152
=== Example
150153

154+
// tag::expressions_conditional_expressions_extended_simple[]
151155
[source, cypher]
152156
----
153157
MATCH (n:Person)
@@ -162,6 +166,7 @@ CASE n.age
162166
ELSE "Adult"
163167
END AS result
164168
----
169+
// end::expressions_conditional_expressions_extended_simple[]
165170

166171
[role="queryresult",options="header,footer",cols="2*<m"]
167172
|===
@@ -212,6 +217,7 @@ In this case, the predicate is tested to find a valid alternative.
212217
[[case-generic-examples]]
213218
=== Example
214219

220+
// tag::expressions_conditional_expressions_generic[]
215221
[source, cypher]
216222
----
217223
MATCH (n:Person)
@@ -222,6 +228,7 @@ CASE
222228
ELSE 3
223229
END AS result, n.eyes, n.age
224230
----
231+
// end::expressions_conditional_expressions_generic[]
225232

226233
[role="queryresult",options="header,footer",cols="3*<m"]
227234
|===
@@ -299,6 +306,7 @@ For more information about `null`, see xref:values-and-types/working-with-null.a
299306

300307
The results of a `CASE` expression can be used to set properties on a node or relationship.
301308

309+
// tag::expressions_conditional_expressions_properties[]
302310
[source, cypher]
303311
----
304312
MATCH (n:Person)
@@ -311,6 +319,7 @@ END AS colorCode
311319
SET n.colorCode = colorCode
312320
RETURN n.name, n.colorCode
313321
----
322+
// end::expressions_conditional_expressions_properties[]
314323

315324
[role="queryresult",options="header,footer",cols="2*<m"]
316325
|===

modules/ROOT/pages/expressions/list-expressions.adoc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ The subscript operator, `[]`, can be used to access specific elements in a `LIST
4141
`[-1]` refers to the last element in a `LIST`, `[-2]` to the penultimate element, and so on.
4242

4343
.Access individual elements in a `LIST`
44+
// tag::expressions_list_element_access[]
4445
[source, cypher]
4546
----
4647
WITH [1, 2, 3, 4] AS list
4748
RETURN list[0] AS firstElement,
4849
list[2] AS thirdElement,
4950
list[-1] AS finalElement
5051
----
52+
// end::expressions_list_element_access[]
5153

5254
.Result
5355
[role="queryresult",options="header,footer",cols="3*<m"]
@@ -87,11 +89,13 @@ RETURN list[$myIndex] AS secondElement
8789
|===
8890

8991
.Access a `LIST` within a nested `LIST`
92+
// tag::expressions_list_nested_list_access[]
9093
[source, cypher]
9194
----
9295
WITH [[1, 2], [3, 4], [5, 6]] AS nestedList
9396
RETURN nestedList[1] AS secondList
9497
----
98+
// end::expressions_list_nested_list_access[]
9599

96100
.Result
97101
[role="queryresult",options="header,footer",cols="1*<m"]
@@ -104,12 +108,14 @@ RETURN nestedList[1] AS secondList
104108
|===
105109

106110
.Access specific elements in a nested `LIST`
111+
// tag::expressions_list_nested_list_specific_element_access[]
107112
[source, cypher]
108113
----
109114
WITH [[1, 2], [3, 4], [5, 6]] AS nestedList
110115
RETURN nestedList[1] AS secondList,
111116
nestedList[1][0] AS firstElementOfSecondList
112117
----
118+
// end::expressions_list_nested_list_specific_element_access[]
113119

114120
.Result
115121
[role="queryresult",options="header,footer",cols="2*<m"]
@@ -189,13 +195,15 @@ This allows for extracting a subset of a `LIST` rather than a single element.
189195
List slicing is inclusive at the start of the range, but exclusive at the end (e.g. `list[start..end]` includes `start`, but excludes `end`).
190196

191197
.Slice operations on a `LIST`
198+
// tag::expressions_list_slicing[]
192199
[source, cypher]
193200
----
194201
WITH [1, 2, 3, 4, 5, 6] AS list
195202
RETURN list[2..4] AS middleElements,
196203
list[..2] AS noLowerBound,
197204
list[2..] AS noUpperBound
198205
----
206+
// end::expressions_list_slicing[]
199207

200208
.Result
201209
[role="queryresult",options="header,footer",cols="3*<m"]
@@ -210,13 +218,15 @@ RETURN list[2..4] AS middleElements,
210218
Negative indexing in list slicing references elements from the end of the `LIST`; `..-1` excludes the last element, `..-2` excludes the last two elements, and so on.
211219

212220
.Negative indexing and list slicing
221+
// tag::expressions_list_negative_slicing[]
213222
[source, cypher]
214223
----
215224
WITH [1, 2, 3, 4, 5, 6] AS list
216225
RETURN list[..-1] AS finalElementRemoved,
217226
list[..-2] AS finalTwoElementsRemoved,
218227
list[-3..-1] AS removedFirstThreeAndLast
219228
----
229+
// end::expressions_list_negative_slicing[]
220230

221231
.Result
222232
[role="queryresult",options="header,footer",cols="3*<m"]
@@ -251,11 +261,13 @@ RETURN nestedList[0..2] AS slicedNestedList
251261
Slicing inner `LIST` values require two `[]` operators; the first `[]` accesses elements from the outer `LIST`, while the second slices or accesses elements from the inner `LIST`.
252262

253263
.Slice inner `LIST`
264+
// tag::expressions_list_slice_inner_list[]
254265
[source, cypher]
255266
----
256267
WITH [[1, 2, 3], [4, 5, 6], [7, 8, 9]] AS nestedList
257268
RETURN nestedList[1][0..2] AS slicedInnerList
258269
----
270+
// end::expressions_list_slice_inner_list[]
259271

260272
.Result
261273
[role="queryresult",options="header,footer",cols="1*<m"]
@@ -293,11 +305,13 @@ Cypher contains two list concatenation operators: `||` and `+`.
293305
`||` is xref:appendix/gql-conformance/index.adoc[GQL conformant], while `+` is not.
294306

295307
.List concatenation using `||` and `+`
308+
// tag::expressions_list_concatenation[]
296309
[source, cypher]
297310
----
298311
RETURN [1,2] || [3,4] AS list1,
299312
[1,2] + [3,4] AS list2
300313
----
314+
// end::expressions_list_concatenation[]
301315

302316
.Result
303317
[role="queryresult",options="header,footer",cols="2*<m"]
@@ -353,12 +367,14 @@ The `+` operator can add elements to the beginning or end of a `LIST` value.
353367
This is not possible using the `||` operator.
354368

355369
.Add elements to the beginning and end of a `LIST`
370+
// tag::expressions_list_add_elements[]
356371
[source, cypher]
357372
----
358373
WITH [1, 2, 3, 4] AS list
359374
RETURN 0 + list AS newBeginning,
360375
list + 5 AS newEnd
361376
----
377+
// end::expressions_list_add_elements[]
362378

363379
.Result
364380
[role="queryresult",options="header,footer",cols="2*<m"]
@@ -458,11 +474,13 @@ RETURN [x IN range(0,5) | x * 10] AS result
458474

459475

460476
.List comprehension with both an expression and filtering
477+
// tag::expressions_list_comprehension[]
461478
[source, cypher]
462479
----
463480
WITH [1, 2, 3, 4, 5] AS list
464481
RETURN [n IN list WHERE n > 2 | n] AS filteredList
465482
----
483+
// end::expressions_list_comprehension[]
466484

467485
.Result
468486
[role="queryresult",options="header,footer",cols="1*<m"]
@@ -498,13 +516,15 @@ RETURN [listIndex IN range(0, size(list)-1) | toString(listIndex) || ': ' || toS
498516
The below query iterates over the `skills` property of each `Person` node and creates a new `LIST` by xref:expressions/string-operators.adoc[concatenating the `STRING`] `" expert"` to each element in `skills`.
499517

500518
.Modify `LIST` properties using list comprehension
519+
// tag::expressions_list_comprehension_properties[]
501520
[source, cypher]
502521
----
503522
MATCH (p:Person) WHERE p.skills IS NOT NULL
504523
ORDER BY p.name
505524
RETURN p.name AS name,
506525
[skill IN p.skills | skill + " expert"] AS modifiedSkills
507526
----
527+
// end::expressions_list_comprehension_properties[]
508528

509529
.Result
510530
[role="queryresult",options="header,footer",cols="2*<m"]
@@ -524,11 +544,13 @@ RETURN p.name AS name,
524544
The next query uses the xref:functions/aggregating.adoc#functions-collect[`collect()`] function to gather all `Person` nodes into a `LIST`, and the `WHERE 'Python' IN person.skills` predicate filters that list to include only those nodes whose `skills` property contains `Python`.
525545

526546
.List comprehension with a `WHERE` predicate
547+
// tag::expressions_list_comprehension_where[]
527548
[source, cypher]
528549
----
529550
MATCH (p:Person)
530551
RETURN [person IN collect(p) WHERE 'Python' IN person.skills | person.name] AS pythonExperts
531552
----
553+
// end::expressions_list_comprehension_where[]
532554

533555
.Result
534556
[role="queryresult",options="header,footer",cols="1*<m"]
@@ -543,10 +565,12 @@ RETURN [person IN collect(p) WHERE 'Python' IN person.skills | person.name] AS p
543565
List comprehension can be used to remove any unknown `NULL` values when concatenating `LIST` values.
544566

545567
.List comprehension to remove `NULL` values during list concatenation
568+
// tag::expressions_list_comprehension_concatenation_remove_null[]
546569
[source, cypher]
547570
----
548571
RETURN [x IN ([1, null, 3] || [null, 5, null]) WHERE x IS NOT NULL] AS listWithoutNull
549572
----
573+
// end::expressions_list_comprehension_concatenation_remove_null[]
550574

551575
.Result
552576
[role="queryresult",options="header,footer",cols="1*<m"]
@@ -572,11 +596,13 @@ Pattern comprehension is used to create new `LIST` values by matching graph patt
572596
The below query retrieves a list of names of people who work for `Alice` by using pattern comprehension extract the names of `employees` into a `LIST`.
573597

574598
.Pattern comprehension on a fixed-length pattern
599+
// tag::expressions_list_pattern_comprehension[]
575600
[source, cypher]
576601
----
577602
MATCH (alice:Person {name: 'Alice'})
578603
RETURN [(employee:Person)-[:WORKS_FOR]->(alice) | employee.name] AS employees
579604
----
605+
// end::expressions_list_pattern_comprehension[]
580606

581607
.Result
582608
[role="queryresult",options="header,footer",cols="1*<m"]
@@ -591,11 +617,13 @@ RETURN [(employee:Person)-[:WORKS_FOR]->(alice) | employee.name] AS employees
591617
Pattern comprehensions can include `WHERE` predicates.
592618

593619
.Pattern comprehension including a `WHERE` predicate
620+
// tag::expressions_list_pattern_comprehension_where[]
594621
[source, cypher]
595622
----
596623
MATCH (alice:Person {name: 'Alice'})
597624
RETURN [(employee:Person)-[:WORKS_FOR]->(alice) WHERE employee.age > 30 | employee.name || ', ' || toString(employee.age)] AS employeesAbove30
598625
----
626+
// end::expressions_list_pattern_comprehension_where[]
599627

600628
.Result
601629
[role="queryresult",options="header,footer",cols="1*<m"]
@@ -622,6 +650,7 @@ The below query uses a pattern comprehension to collect the skills of all superi
622650
The xref:functions/list.adoc#functions-reduce[`reduce()`] function concatenates these skills into a single `LIST`, and xref:clauses/unwind.adoc[`UNWIND`] is used to flatten this `LIST` before returning the distinct skills in a new `LIST`.
623651

624652
.Allowed: variable-length pattern comprehension using variable-length relationship syntax
653+
// tag::expressions_list_pattern_comprehension_var_length[]
625654
[source, cypher]
626655
----
627656
MATCH (cecil:Person {name: 'Cecil'})
@@ -630,6 +659,7 @@ WITH reduce(accumulatedSkills = [], superiorSkills IN allSuperiorsSkills | accum
630659
UNWIND allSkills AS superiorsSkills
631660
RETURN collect(DISTINCT superiorsSkills) AS distinctSuperiorsSkills
632661
----
662+
// end::expressions_list_pattern_comprehension_var_length[]
633663

634664
.Result
635665
[role="queryresult",options="header,footer",cols="1*<m"]

0 commit comments

Comments
 (0)