Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FILTER documentation #1198

Merged
merged 7 commits into from
Feb 27, 2025
Merged

Conversation

JPryce-Aklundh
Copy link
Collaborator

No description provided.

Copy link
Contributor

@hvub hvub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. LGTM. Two remarks inline.

Comment on lines 7 to 8
Unlike `WHERE`, `FILTER` is not a subclause, which means it can be used independently of the xref:clauses/match.adoc[`MATCH`], xref:clauses/optional-match.adoc[`OPTIONAL MATCH`], and xref:clauses/with.adoc[`WITH`] clauses.
It is not, however, as versatile as `WHERE`.
Copy link
Contributor

@hvub hvub Feb 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm.... I not sure I would say that. Yes there are way to use WHERE which do not work with FILTER. However, this comes from 1) where being a subclause 2) the context in which it is allowed. So, it is a bit of an apple and oranges comparison.

I guess you basically trying to say that they are different in some respects and the user should not think that every WHERE is 1-to-1 replaceable by a FILTER. That is certainly true. But may we can find a way to say that in a neutral way without adding a quality to it.

The main cause of the difference is exactly that FILTER is a clause while WHERE is a subclause (of multiple different clauses).

So, may be like something like this:

Suggested change
Unlike `WHERE`, `FILTER` is not a subclause, which means it can be used independently of the xref:clauses/match.adoc[`MATCH`], xref:clauses/optional-match.adoc[`OPTIONAL MATCH`], and xref:clauses/with.adoc[`WITH`] clauses.
It is not, however, as versatile as `WHERE`.
Unlike `WHERE`, `FILTER` is not a subclause, which means it can be used independently of the xref:clauses/match.adoc[`MATCH`], xref:clauses/optional-match.adoc[`OPTIONAL MATCH`], and xref:clauses/with.adoc[`WITH`] clauses.
Conversely, `FILTER` cannot be used within these clauses like `WHERE` but only next to them.

While this somewhat fulfils to aim I laid out the top, I am not sure I like for the flow. Anyway. May you have a better idea.

Alternatively, we can also consider dropping the second sentence altogether.

Or turn it into a forward reference to section "FILTER as a substitute for WITH * WHERE", like: "For more details on this difference see ..."

RETURN b.name AS name
----

For more information about how to use `WHERE` in fixed-length and variable-length pattern matching, see xref:clauses/where.adoc#filter-patterns[`WHERE` -> Filter patterns].
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One item you could add is relative to the point the docs makes somewhere that

When used with MATCH and OPTIONAL MATCH, WHERE adds constraints to the patterns described. It should not be seen as a filter after the matching is finished.

This make a different particularly with OPTIONAL MATCH.

UNWIND [32,37,40] AS age
OPTIONAL MATCH (p:Person) 
  WHERE p.age = age
RETURN p.name

returns

╒═══════╕
│p.name │
╞═══════╡
│"Susan"│
├───────┤
│null   │
├───────┤
│"John" │
└───────┘

while

UNWIND [32,37,40] AS age
OPTIONAL MATCH (p:Person) 
FILTER p.age = age
RETURN p.name

returns

╒═══════╕
│p.name │
╞═══════╡
│"Susan"│
├───────┤
│"John" │
└───────┘

@neo-technology-commit-status-publisher
Copy link
Collaborator

Thanks for the documentation updates.

The preview documentation has now been torn down - reopening this PR will republish it.

@JPryce-Aklundh JPryce-Aklundh merged commit f6b4dfd into neo4j:cypher-25 Feb 27, 2025
4 checks passed
@JPryce-Aklundh JPryce-Aklundh deleted the filter_playground branch February 27, 2025 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants