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

Document LET #1207

Open
wants to merge 5 commits into
base: cypher-25
Choose a base branch
from
Open

Conversation

JPryce-Aklundh
Copy link
Collaborator

No description provided.

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

This PR includes documentation updates
View the updated docs at https://neo4j-docs-cypher-1207.surge.sh

New pages:

Updated pages:

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.

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`]
Copy link
Contributor

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.
Copy link
Contributor

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.

Copy link
Contributor

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.

Comment on lines 42 to +44
m| xref::clauses/filter.adoc[FILTER]
| Adds filters to queries.
label:new[Introduced in Neo4j 2025.03]
Copy link
Contributor

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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
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:
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Comment on lines +66 to +67
* `LET` syntax: `LET <variable> = <expression>, <variable> = <expression>`
* `WITH` syntax: `WITH <expression> AS <variable>, <expression> AS <variable>`
Copy link
Contributor

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
Copy link
Contributor

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:

Suggested change
== 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.
Copy link
Contributor

Choose a reason for hiding this comment

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

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

Suggested change
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.
Copy link
Contributor

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,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
LET fullName = c.firstName + ' ' + c.lastName,
LET fullName = c.firstName + ' ' + c.lastName

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