-
Notifications
You must be signed in to change notification settings - Fork 64
Clarify CALL subquery ambiguities #1060
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -30,14 +30,9 @@ CREATE (teamA:Team {name: 'Team A'}), | |||||
| (playerF:Player {name: 'Player F', age: 35}), | ||||||
| (playerA)-[:PLAYS_FOR]->(teamA), | ||||||
| (playerB)-[:PLAYS_FOR]->(teamA), | ||||||
| (playerC)-[:PLAYS_FOR]->(teamA), | ||||||
| (playerD)-[:PLAYS_FOR]->(teamB), | ||||||
| (playerE)-[:PLAYS_FOR]->(teamC), | ||||||
| (playerF)-[:PLAYS_FOR]->(teamC), | ||||||
| (playerA)-[:FRIEND_OF]->(playerB), | ||||||
| (playerA)-[:FRIEND_OF]->(playerC), | ||||||
| (playerB)-[:FRIEND_OF]->(playerF), | ||||||
| (playerC)-[:FRIEND_OF]->(playerD), | ||||||
| (teamA)-[:OWES {dollars: 1500}]->(teamB), | ||||||
| (teamA)-[:OWES {dollars: 3000}]->(teamB), | ||||||
| (teamB)-[:OWES {dollars: 1700}]->(teamC), | ||||||
|
|
@@ -92,7 +87,6 @@ CALL () { | |||||
| SET p.age = p.age + 1 | ||||||
| RETURN p.age AS newAge | ||||||
| } | ||||||
| WITH x, newAge | ||||||
| MATCH (p:Player {name: 'Player A'}) | ||||||
| RETURN x AS iteration, newAge, p.age AS totalAge | ||||||
| ---- | ||||||
|
|
@@ -139,7 +133,7 @@ RETURN t AS team, players | |||||
| | players | ||||||
|
|
||||||
| | (:Team {name: "Team A"}) | ||||||
| | [(:Player {name: "Player C", age: 19}), (:Player {name: "Player B", age: 23}), (:Player {name: "Player A", age: 24})] | ||||||
| | (:Player {name: "Player B", age: 23}), (:Player {name: "Player A", age: 24})] | ||||||
|
|
||||||
| | (:Team {name: "Team B"}) | ||||||
| | [(:Player {name: "Player D", age: 30})] | ||||||
|
|
@@ -432,60 +426,60 @@ Similar to xref:clauses/optional-match.adoc[`OPTIONAL MATCH`] any empty rows pro | |||||
| .Difference between using `CALL` and `OPTIONAL CALL` | ||||||
| ==== | ||||||
|
|
||||||
| This example, which finds the friends of each `Player` and xref:functions/aggregating.adoc#functions-count[counts] the number of friends per player, highlights the difference between using `CALL` and `OPTIONAL CALL`. | ||||||
| This example, which finds team that each `Player` plays for, highlights the difference between using `CALL` and `OPTIONAL CALL`. | ||||||
|
|
||||||
| .Regular subquery `CALL` | ||||||
| [source, cypher] | ||||||
| ---- | ||||||
| MATCH (p:Player) | ||||||
| CALL (p) { | ||||||
| MATCH (p)-[:FRIEND_OF]->(friend:Player) | ||||||
| RETURN friend | ||||||
| MATCH (p)-[:PLAYS_FOR]->(team:Team) | ||||||
| RETURN team | ||||||
| } | ||||||
| RETURN p.name AS playerName, count(friend) AS numberOfFriends | ||||||
| ORDER BY numberOfFriends | ||||||
| RETURN p.name AS playerName, team.name AS team | ||||||
| ---- | ||||||
|
|
||||||
| .Optional subquery `CALL` | ||||||
| .Result | ||||||
| [role="queryresult",options="header,footer",cols="2*m"] | ||||||
| |=== | ||||||
| | playerName | numberOfFriends | ||||||
| | playerName | team | ||||||
|
|
||||||
| | "Player B" | 1 | ||||||
| | "Player C" | 1 | ||||||
| | "Player A" | 2 | ||||||
| | "Player A" | "Team A" | ||||||
| | "Player B" | "Team A" | ||||||
| | "Player D" | "Team B" | ||||||
| | "Player E" | "Team C" | ||||||
| | "Player F" | "Team C" | ||||||
|
|
||||||
| 2+d|Rows: 3 | ||||||
| 2+d|Rows: 5 | ||||||
| |=== | ||||||
|
|
||||||
| Note that no results are returned for `Player D`, `Player E`, and `Player F`, since they have no outgoing `FRIEND_OF` relationships connected to them. | ||||||
| Note that no results are returned for `Player C`, since they have are not connected to any `Team` with a `PLAYS_FOR` relationship. | ||||||
|
||||||
| Note that no results are returned for `Player C`, since they have are not connected to any `Team` with a `PLAYS_FOR` relationship. | |
| Note that no results are returned for `Player C`, since they are not connected to any `Team` with a `PLAYS_FOR` relationship. |
Outdated
Contributor
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.
Suggested change
| No rows are returned for `Player C`, since they have are not connected to a `Team` with a `PLAYS_FOR` relationship. | |
| No rows are returned for `Player C`, since they are not connected to a `Team` with a `PLAYS_FOR` relationship. |
Contributor
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.
Suggested change
| | playerName | team | |
| | player | team |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.