-
Notifications
You must be signed in to change notification settings - Fork 64
Add docs for new COLLECT subqueries #398
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
Conversation
|
Looks like you've updated the documentation! Check out your changes at https://neo4j-docs-cypher-398.surge.sh |
b37b5fa to
91f3794
Compare
91f3794 to
9f1e870
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could avoid using what we want to explain (collect) in the definition if possible?
| A `COLLECT` subquery expression can be used to collect the rows returned by the subquery into a list. | |
| A `COLLECT` subquery expression can be used to create a list with the rows returned by a given subquery. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe give an example where we have shadowing and the query would fail?
ncordon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add an example with several pattern expressions in the query?
9f1e870 to
98c8278
Compare
JPryce-Aklundh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very good - just a few suggestions 👍
And the test has picked up one failed query
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Any non-writing query is allowed. `COLLECT` subqueries differ from `COUNT` and `EXISTS` subqueries in that the final `RETURN` clause is mandatory. | |
| Any non-writing query is allowed. | |
| `COLLECT` subqueries differ from `COUNT` and `EXISTS` subqueries in that the final `RETURN` clause is mandatory. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at the query, my first thought was why does this show me who has more than one dog? Taking a look at the graph, I understand what you mean, but would it not be more clear to write "outputs the owners of the dog named Ozzy"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the second "scope" be modified accordingly? (or in some other way to clarify further what "this" scope means?)
| Variables introduced by the `MATCH` clause and the outside scope can be used in this scope. | |
| Variables introduced by the `MATCH` clause and the outside scope can be used in the inner scope. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| In the below example, the outer variable `name` is being shadowed and will result in an error. | |
| In the below example, the outer variable `name` is shadowed and will therefore throw an error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is restricted? The use of COLLECT altogether when using admin commands, or its location when using admin commands? I am using the former, so maybe this could work:
| `COLLECT` can be used in any position in a query, with the exception of administration commands, where it is restricted. | |
| `COLLECT` can be used in any position in a query, with the exception of administration commands, where the `COLLECT` expression is restricted. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| See a few examples below: | |
| See a few examples below of how `COLLECT` can be used in different positions within a query: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the blank line at the end of the query intentional? I notice it below as well.
| ---- | |
| MATCH (person:Person) WHERE person.name = "Peter" | |
| SET person.dogNames = COLLECT { MATCH (person)-[:HAS_DOG]->(d:Dog) RETURN d.name } | |
| RETURN person.dogNames as dogNames | |
| ---- | |
| ---- | |
| MATCH (person:Person) WHERE person.name = "Peter" | |
| SET person.dogNames = COLLECT { MATCH (person)-[:HAS_DOG]->(d:Dog) RETURN d.name } | |
| RETURN person.dogNames as dogNames | |
| ---- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope 😅
8f17429 to
3ef52fd
Compare
JPryce-Aklundh
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Just a few suggestions from me 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The following query collects all persons by their dog's names, | |
| The following query collects all persons by their dogs' names, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| When using `COLLECT` over the function `collect()` it is important to note that they have different behavior surrounding `null` values. | |
| `COLLECT` does not handle `null` values in the same way that function `collect()` does. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The `collect()` function automatically removes null values. | |
| The `collect()` function automatically removes `null` values. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| `COLLECT` will not remove them automatically, however, they can be removed by simply adding a filtering step in the subquery. | |
| `COLLECT` will not remove `null values` automatically. | |
| However, they can be removed by adding a filtering step in the subquery. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should the backticks be around just null here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, sorry!
349c85e to
d0d9cd9
Compare
Docs for Collect Subqueries: https://github.com/neo-technology/neo4j/pull/19242