Skip to content

Conversation

@gem-neo4j
Copy link
Contributor

@gem-neo4j gem-neo4j commented Feb 8, 2023

@gem-neo4j
Copy link
Contributor Author

Collect Subqueries

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

Looks like you've updated the documentation!

Check out your changes at https://neo4j-docs-cypher-398.surge.sh

@gem-neo4j gem-neo4j force-pushed the dev_collect_subqueries branch from b37b5fa to 91f3794 Compare February 10, 2023 13:40
@gem-neo4j gem-neo4j marked this pull request as ready for review February 10, 2023 15:41
@gem-neo4j gem-neo4j force-pushed the dev_collect_subqueries branch from 91f3794 to 9f1e870 Compare February 10, 2023 15:48
Copy link
Contributor

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?

Suggested change
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.

Copy link
Contributor

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?

Copy link
Contributor

@ncordon ncordon left a 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?

@gem-neo4j gem-neo4j force-pushed the dev_collect_subqueries branch from 9f1e870 to 98c8278 Compare February 20, 2023 12:38
Copy link
Collaborator

@JPryce-Aklundh JPryce-Aklundh left a 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

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Collaborator

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"?

Copy link
Collaborator

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?)

Suggested change
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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Collaborator

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:

Suggested change
`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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
See a few examples below:
See a few examples below of how `COLLECT` can be used in different positions within a query:

Comment on lines 1051 to 1054
Copy link
Collaborator

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.

Suggested change
----
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
----

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope 😅

@gem-neo4j gem-neo4j force-pushed the dev_collect_subqueries branch from 8f17429 to 3ef52fd Compare February 28, 2023 09:47
Copy link
Collaborator

@JPryce-Aklundh JPryce-Aklundh left a 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 👍

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
The following query collects all persons by their dog's names,
The following query collects all persons by their dogs' names,

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
The `collect()` function automatically removes null values.
The `collect()` function automatically removes `null` values.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
`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.

Copy link
Contributor Author

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?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, sorry!

@gem-neo4j gem-neo4j added the 5.6 label Mar 1, 2023
@gem-neo4j gem-neo4j force-pushed the dev_collect_subqueries branch from 349c85e to d0d9cd9 Compare March 1, 2023 11:55
@JPryce-Aklundh JPryce-Aklundh merged commit 77a7c38 into neo4j:dev Mar 1, 2023
@JPryce-Aklundh JPryce-Aklundh deleted the dev_collect_subqueries branch March 1, 2023 12:58
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.

4 participants