Skip to content

Commit 5f2a64b

Browse files
initial
1 parent 737104d commit 5f2a64b

File tree

7 files changed

+135
-6
lines changed

7 files changed

+135
-6
lines changed

modules/ROOT/content-nav.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
** xref:clauses/call.adoc[]
1616
** xref:clauses/create.adoc[]
1717
** xref:clauses/delete.adoc[]
18+
** xref:clauses/filter.adoc[]
1819
** xref:clauses/finish.adoc[]
1920
** xref:clauses/foreach.adoc[]
2021
** xref:clauses/limit.adoc[]
Lines changed: 1 addition & 0 deletions
Loading

modules/ROOT/pages/appendix/gql-conformance/supported-optional.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ For example, GQL’s graph reference values `CURRENT_GRAPH` and `CURRENT_PROPERT
173173
| xref:queries/composed-queries/combined-queries.adoc[`UNION`]
174174
|
175175

176+
| GQ08
177+
| `FILTER` statement
178+
| xref:clauses/filter.adoc[`FILTER`]
179+
|
180+
176181
| GQ13
177182
| `ORDER BY` and page statement: `LIMIT`
178183
| xref:clauses/limit.adoc[`LIMIT`], xref:clauses/order-by.adoc[`ORDER BY`]
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
= FILTER
2+
:description:
3+
4+
[[example-graph]]
5+
== Example graph
6+
7+
The following graph is used for the examples below:
8+
9+
image::filter_clause.svg[width="700",role="middle"]
10+
11+
To recreate the graph, run the following query in an empty Neo4j database:
12+
13+
[source, cypher, role=test-setup]
14+
----
15+
CREATE (andy:Swedish:Person {name: 'Andy', age: 36}),
16+
(timothy:Person {name: 'Timothy', age: 38}),
17+
(peter:Person {name: 'Peter', age: 35}),
18+
(lisa:Person {name: 'Lisa', age: 48}),
19+
(john:Person {name: 'John', age: 40}),
20+
(susan:Person {name: 'Susan', age: 32}),
21+
(andy)-[:KNOWS {since: 2012}]->(timothy),
22+
(andy)-[:KNOWS {since: 1999}]->(peter),
23+
(peter)-[:KNOWS {since: 2005}]->(lisa),
24+
(lisa)-[:KNOWS {since: 2010}]->(john),
25+
(john)-[:KNOWS {since: 2021}]->(susan)
26+
----
27+
28+
29+
== Basic filtering
30+
31+
MATCH (n)
32+
FILTER n:Swedish
33+
RETURN n.name AS name
34+
35+
MATCH (n:Person)
36+
FILTER n.age < 35
37+
RETURN n.name AS name, n.age AS age
38+
39+
MATCH (p:Person)-[r:KNOWS]->(n:Person)
40+
FILTER r.since > 2000
41+
RETURN p.name, n.name
42+
43+
== Filter on dynamic properties
44+
45+
MATCH (n:Person)
46+
FILTER n[$propname] > 40
47+
RETURN n.name AS name, n.age AS age
48+
49+
== `WITH`, `WHERE`, and `FILTER`
50+
51+
=== FILTER as a substitute for `WITH * WHERE`
52+
* Filter makes WITH * WHERE ... redundant
53+
54+
UNWIND [1, 2, 3, 4, 5, 6] AS x
55+
WITH x
56+
WHERE x > 2
57+
RETURN x
58+
59+
same as
60+
61+
UNWIND [1, 2, 3, 4, 5, 6] AS x
62+
FILTER > 2
63+
RETURN x
64+
65+
load csv
66+
67+
.companies.csv
68+
[source, csv, filename="companies.csv"]
69+
----
70+
Id,Name,Location,Email,BusinessType
71+
1,Neo4j,San Mateo,[email protected],P
72+
73+
3,BBB,Chicago, ,G
74+
,CCC,Michigan,[email protected],G
75+
----
76+
77+
[source, cypher]
78+
----
79+
LOAD CSV WITH HEADERS FROM 'file:///companies.csv' AS row
80+
WITH row
81+
WHERE row.Id IS NOT NULL
82+
MERGE (c:Company {id: row.Id})
83+
----
84+
85+
[source, cypher]
86+
----
87+
LOAD CSV WITH HEADERS FROM 'file:///companies.csv' AS row
88+
FILTER row.Id IS NOT NULL
89+
MERGE (c:Company {id: row.Id})
90+
----
91+
92+
93+
* Variable scope
94+
95+
96+
* Filter cannot exist in patterns
97+
98+
99+
100+
101+
102+
103+
104+
105+
106+
107+
108+
109+
== Differences between `FILTER` and `WHERE`
110+
111+
112+
113+

modules/ROOT/pages/clauses/load-csv.adoc

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -565,26 +565,23 @@ Id,Name,Location,Email,BusinessType
565565
[source, cypher]
566566
----
567567
LOAD CSV WITH HEADERS FROM 'file:///companies.csv' AS row
568-
WITH row
569-
WHERE row.Id IS NOT NULL
568+
FILTER row.Id IS NOT NULL
570569
MERGE (c:Company {id: row.Id})
571570
----
572571
573572
.Provide a default for `null` values
574573
[source, cypher]
575574
----
576575
LOAD CSV WITH HEADERS FROM 'file:///companies.csv' AS row
577-
WITH row
578-
WHERE row.Id IS NOT NULL
576+
FILTER row.Id IS NOT NULL
579577
MERGE (c:Company {id: row.Id, hqLocation: coalesce(row.Location, "Unknown")})
580578
----
581579
582580
.Change empty `STRING` values to `null` values (not stored)
583581
[source, cypher]
584582
----
585583
LOAD CSV WITH HEADERS FROM 'file:///companies.csv' AS row
586-
WITH row
587-
WHERE row.Id IS NOT NULL
584+
FILTER row.Id IS NOT NULL
588585
MERGE (c:Company {id: row.Id})
589586
SET c.email = nullIf(trim(row.Email), "")
590587
----

modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,17 @@ a|
209209
label:functionality[]
210210
label:new[]
211211

212+
[source, cypher, role="noheader"]
213+
----
214+
215+
----
216+
217+
| New xref:clauses/filter.adoc[`FILTER`] clause.
218+
219+
a|
220+
label:functionality[]
221+
label:new[]
222+
212223
[source, cypher, role="noheader"]
213224
----
214225
WHEN false THEN RETURN 1 AS x

modules/ROOT/pages/syntax/keywords.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ Note that with future functionality, Cypher may be extended with additional keyw
164164
* `FALSE`
165165
* `FIELDTERMINATOR`
166166
* `FINISH`
167+
* `FILTER`
167168
* `FLOAT`
168169
* `FOR`
169170
* `FOREACH`

0 commit comments

Comments
 (0)