Skip to content

NEXT documentation #1273

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

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

NEXT documentation #1273

wants to merge 5 commits into from

Conversation

rsill-neo4j
Copy link
Contributor

No description provided.

@neo4j-docops-agent
Copy link
Collaborator

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

New pages:

Updated pages:

Copy link
Contributor

@JoelBergstrand JoelBergstrand left a comment

Choose a reason for hiding this comment

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

Great work Richard! I added som thought and edits, some which we talked about during the meeting, some that I came up with now.

@@ -188,6 +189,13 @@ For example, GQL’s graph reference values `CURRENT_GRAPH` and `CURRENT_PROPERT
| xref:clauses/limit.adoc[`LIMIT`], xref:clauses/order-by.adoc[`ORDER BY`]
| Cypher requires using the xref:clauses/with.adoc[`WITH`] clause, which GQL does not.

| GQ20
| `NEXT` statement
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
| `NEXT` statement
| Advanced linear composition with NEXT

Comment on lines +195 to +197
| The GQL standard includes a `YIELD` clause for its `NEXT` statement.
The purpose of this `YIELD` clause is to ensure compatible behavior with SQL as it uses double quotes for delimiting identifiers.
Cypher on the other hand uses double quotes for strings and backticks for quoting and thus having a `YIELD` clause does not provide additional use in Cypher.
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
| The GQL standard includes a `YIELD` clause for its `NEXT` statement.
The purpose of this `YIELD` clause is to ensure compatible behavior with SQL as it uses double quotes for delimiting identifiers.
Cypher on the other hand uses double quotes for strings and backticks for quoting and thus having a `YIELD` clause does not provide additional use in Cypher.
| The GQL standard includes a `YIELD` clause for its `NEXT` statement which Cypher does not implement.

Comment on lines +236 to +237
| Introduction of `NEXT` which allows for linear composition of queries into a sequence.
For more information, see xref:queries/composed-queries/sequential-queries.adoc[].
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
| Introduction of `NEXT` which allows for linear composition of queries into a sequence.
For more information, see xref:queries/composed-queries/sequential-queries.adoc[].
| New `NEXT` keyword used for linear composition of queries.
For more information, see xref:queries/composed-queries/sequential-queries.adoc[].

Copy link
Contributor

Choose a reason for hiding this comment

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

The examples below seem to link the pahe in the keyword name.

Comment on lines +148 to +150
== Interactions with `CALL` subqueries and `WITH`

You can use `NEXT` to rewrite queries containing `CALL` subqueries or a `WITH` clause.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm trying to what makes most sense to present. The above simple examples show in my mind the same thing as what we want to show with the WITH part in this section. I think it could be better to remove WITH from this section. If we want a with case we need an example where the readability greatly improves by using NEXT. That's my thoughts at least.

Suggested change
== Interactions with `CALL` subqueries and `WITH`
You can use `NEXT` to rewrite queries containing `CALL` subqueries or a `WITH` clause.
== Interactions with `CALL` subqueries
You can use `NEXT` to rewrite queries containing `CALL` subqueries.

Comment on lines +203 to +249
[[with-rewrite]]
.Rewriting a `WITH` query
====
[cols="1,1"]
|===
a|
.`WITH`
[source, cypher]
----
LET a = 1
WITH a
LET b = a + 1
WITH a, b
LET c = a + b + 1
WITH b, c
LET d = b + c
RETURN d
----
a|
.`NEXT`
[source, cypher]
----
LET a = 1
RETURN a

NEXT

LET b = a + 1
RETURN a, b

NEXT

LET c = a + b + 1
RETURN b, c

NEXT

LET d = b + c
RETURN d
----
|===
====


Variables which are local to a query and which are not explicitly returned are not accessible by subsequent queries in the context of `NEXT`.
This allows you to control variable scope similarly to what you can do with `WITH`, see xref:clauses/with.adoc#variable-scope[Control variables in scope]: in <<with-rewrite>>, each occurrence of `WITH` is replaced by a `RETURN` and a `NEXT`, preserving the variable scope.

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
[[with-rewrite]]
.Rewriting a `WITH` query
====
[cols="1,1"]
|===
a|
.`WITH`
[source, cypher]
----
LET a = 1
WITH a
LET b = a + 1
WITH a, b
LET c = a + b + 1
WITH b, c
LET d = b + c
RETURN d
----
a|
.`NEXT`
[source, cypher]
----
LET a = 1
RETURN a
NEXT
LET b = a + 1
RETURN a, b
NEXT
LET c = a + b + 1
RETURN b, c
NEXT
LET d = b + c
RETURN d
----
|===
====
Variables which are local to a query and which are not explicitly returned are not accessible by subsequent queries in the context of `NEXT`.
This allows you to control variable scope similarly to what you can do with `WITH`, see xref:clauses/with.adoc#variable-scope[Control variables in scope]: in <<with-rewrite>>, each occurrence of `WITH` is replaced by a `RETURN` and a `NEXT`, preserving the variable scope.
Variables which are local to a query and which are not explicitly returned are not accessible by subsequent queries in the context of `NEXT`. This allows you to control variable scope similarly to what you can do with `WITH`, see xref:clauses/with.adoc#variable-scope[Control variables in scope].

Copy link
Contributor

Choose a reason for hiding this comment

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

See above reasoning.

====


== Interactions with conditional queries
Copy link
Contributor

Choose a reason for hiding this comment

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

Really like this example!

== Interactions with conditional queries

[[next-and-conditional]]
.`NEXT` in a conditional query
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
.`NEXT` in a conditional query
. Conditional queries in `NEXT`

Comment on lines +311 to +312
[[next-and-union]]
.`NEXT` in a query using `UNION`
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this example is fine and easy to reason about, maybe not the most exciting creation ever but it does the job.

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