-
Notifications
You must be signed in to change notification settings - Fork 59
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
Document LET
#1207
base: cypher-25
Are you sure you want to change the base?
Document LET
#1207
Conversation
This PR includes documentation updates New pages: Updated pages: |
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.
A few things pointed out, but overall this is very nice. Thank you.
@@ -178,6 +178,11 @@ For example, GQL’s graph reference values `CURRENT_GRAPH` and `CURRENT_PROPERT | |||
| xref:clauses/filter.adoc[`FILTER`] | |||
| | |||
|
|||
| GQ09 | |||
| `LET` statement | |||
| xref:clauses/let.adoc[`LET`] |
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.
Just FYI: There is a caveat to this, since there is a sub-functionality which we do not support, cf. Appendix of the CIP. However, that is much in the detail and other implementation do not support that either. Additionally, I am trying to make this bit optional in the standard. Bottom line: I would not change anything here at this point, but we may want to in the future (e.g. when making it optional in the standard fails).
m| xref::clauses/unwind.adoc[UNWIND ... [AS]] | ||
| Expands a list into a sequence of rows. | ||
m| xref::clauses/let.adoc[LET] | ||
| Assigns expressions to variables. |
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.
More correct is that the results of expressions are assigned to that variables.
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.
Alternatively, you could say something like "defines additional variables" or "binds additional variables". Not sure I like these more. Just throwing out ideas.
m| xref::clauses/filter.adoc[FILTER] | ||
| Adds filters to queries. | ||
label:new[Introduced in Neo4j 2025.03] |
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.
Didn't saw this on the FILTER
review, but I think this FILTER
is in the wrong section, since it does not project anything. Reading clauses
is probably better.
|
||
`LET` binds expressions to variables. | ||
For queries involving several chained expressions, it can be a more succinct and readable alternative to xref:clauses/with.adoc[`WITH`]. | ||
Unlike `WITH`, `LET` cannot limit the scope of variables available to subsequent clauses. |
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.
Unlike `WITH`, `LET` cannot limit the scope of variables available to subsequent clauses. | |
Unlike `WITH`, `LET` does not remove variables from the scope for subsequent clauses. |
I feel this sound more positive ... "it does not limit" is somehow slightly negatively connotated for me, while "it does not remove" is somehow slightly negatively connotated for me. ... may that is just me.
[[assigning-expressions-to-variables]] | ||
== Assigning expressions to a variable | ||
|
||
Both `Let` and `WITH` can be used to assign variables to an expression: |
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.
Both `Let` and `WITH` can be used to assign variables to an expression: | |
Both `LET` and `WITH` can be used to assign variables to an expression: |
* `LET` syntax: `LET <variable> = <expression>, <variable> = <expression>` | ||
* `WITH` syntax: `WITH <expression> AS <variable>, <expression> AS <variable>` |
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.
This may make look like they do the same, which they do not. As explained at the top and in the next section ("Variables in scope: comparing LET
and WITH
"). So, I wonder if we need that here.
May we make this section just about LET and do not mention WITH at all. It is mentioned enough at the top and in the next section.
---- | ||
|
||
[[assigning-expressions-to-variables]] | ||
== Assigning expressions to a variable |
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.
Cf. Comment on the index page. (Also the plural doesn't fit, because it is one expression per variable. That one expression may be evaluated to multiple values.)
Here is another proposal:
== Assigning expressions to a variable | |
== Assigning values to a variable |
=== Variables in scope | ||
|
||
`LET` and `WITH` behave differently in terms of what variables remain in scope for subsequent clauses. | ||
Unlike `WITH`, `LET` cannot drop variables from the scope of subsequent clauses. |
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.
Unlike `WITH`, `LET` cannot drop variables from the scope of subsequent clauses. | |
Unlike `WITH`, `LET` does not drop variables from the scope of subsequent clauses. |
cf. above. I like this version with "drop" over my own suggestion from above.
Or more LET
-oriented:
Unlike `WITH`, `LET` cannot drop variables from the scope of subsequent clauses. | |
`LET` does not drop variables from the scope of subsequent clauses, while `WITH` does. |
(or the other way around).
We should pay attention that the page works for someone who is not familiar with WITH
.
[[chaining-expressions]] | ||
=== Chaining expressions | ||
|
||
The fact that `LET` does not drop variables means that it can be used to chain expressions in a clear and concise manner, where variables bound in one `LET` clause can be referenced by subsequent clauses. |
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.
🎉
---- | ||
MATCH (c:Customer)-[:BUYS]->(p:Product) | ||
WITH DISTINCT c, sum(p.price) AS totalSpent | ||
LET fullName = c.firstName + ' ' + c.lastName, |
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.
LET fullName = c.firstName + ' ' + c.lastName, | |
LET fullName = c.firstName + ' ' + c.lastName |
No description provided.