Skip to content

Conversation

JoelBergstrand
Copy link
Contributor

@JoelBergstrand JoelBergstrand commented Jul 29, 2025

Adding section on by-table semantics for NEXT, removing the section on known limitations.

@@ -383,12 +384,45 @@ RETURN customer.firstName AS plantCustomer
1+d|Rows: 6
|===

=== Leveraging by-table semantics using `UNION` after `NEXT`
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
=== Leveraging by-table semantics using `UNION` after `NEXT`
=== Leveraging by-table semantics using `UNION` after `NEXT`

(spacing only)

Copy link
Contributor

Choose a reason for hiding this comment

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

This heading is the first mention of "by-table semantics". It falls out of the sky. I think, the much earlier section "Passing values to subsequent queries", which current is without change, should make clear that NEXT passes the whole table of intermediate results to the subsequent query. Maybe even show a second example with aggregation.

On the more general level, the page currently reflects the journey we as implementor went through. But it should not — users do not care about our troubles, which meaningless to them.

The page should be present NEXT as the feature that allows to pass the whole table of intermediate result to a subsequent query.

So the effects and benefits of that should come first — instead of in the last section.

So, consider to adjust the order of the section to this:

  1. Passing values to subsequent queries
  2. Interactions with UNION queries
  3. Interactions with CALL subqueries
  4. Interactions with conditional queries

In the latter two section, it should be explicitly pointed out respectively that CALL and conditionals only pass individual rows.

The text in "Interactions with CALL subqueries" also need some adjustment. For instance "NEXT can serve as a more readable alternative to CALL subqueries." Not sure we need to hang it this high now. Maybe it is better to show example where CALL nests NEXT and vice verse to illustrate the combined effect of their by-row and by-table semantics.

@@ -383,12 +384,45 @@ RETURN customer.firstName AS plantCustomer
1+d|Rows: 6
|===

=== Leveraging by-table semantics using `UNION` after `NEXT`
Copy link
Contributor

Choose a reason for hiding this comment

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

This heading is the first mention of "by-table semantics". It falls out of the sky. I think, the much earlier section "Passing values to subsequent queries", which current is without change, should make clear that NEXT passes the whole table of intermediate results to the subsequent query. Maybe even show a second example with aggregation.

On the more general level, the page currently reflects the journey we as implementor went through. But it should not — users do not care about our troubles, which meaningless to them.

The page should be present NEXT as the feature that allows to pass the whole table of intermediate result to a subsequent query.

So the effects and benefits of that should come first — instead of in the last section.

So, consider to adjust the order of the section to this:

  1. Passing values to subsequent queries
  2. Interactions with UNION queries
  3. Interactions with CALL subqueries
  4. Interactions with conditional queries

In the latter two section, it should be explicitly pointed out respectively that CALL and conditionals only pass individual rows.

The text in "Interactions with CALL subqueries" also need some adjustment. For instance "NEXT can serve as a more readable alternative to CALL subqueries." Not sure we need to hang it this high now. Maybe it is better to show example where CALL nests NEXT and vice verse to illustrate the combined effect of their by-row and by-table semantics.

@JoelBergstrand
Copy link
Contributor Author

@hvub @rsill-neo4j, I've done a substantial rewrite and reorganization now, trying to put by-table semantics front and center. I find it quite difficult to construct interesting examples, and should we introduce the concept of by-table, by-row semantics at all or just refer to it in more general terms?

@hvub
Copy link
Contributor

hvub commented Aug 1, 2025

@rsill-neo4j I have updated the page a bit more to address my own comments on top of what @JoelBergstrand already did. @JoelBergstrand is out for vacation. I am taking over the PR, so that we can make whatever deadline for the next release is. I am done editing, so please have a look and feel free to fix any editorial sins I may have committed. 😄

Copy link
Contributor

@rsill-neo4j rsill-neo4j left a comment

Choose a reason for hiding this comment

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

editorial suggestions

.Passing multiple variables to another query via `NEXT`
// tag::sequential_queries_basic_example[]
Copy link
Contributor

Choose a reason for hiding this comment

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

these should probably stay (used for cypher cheat sheet includes)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah.. okay. I didn't know that.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have add tags again, but on a newly made selection of three queries.

@hvub
Copy link
Contributor

hvub commented Aug 6, 2025

@rsill-neo4j What is the state of this PR from your point of view? Do you need any more input to take it over the finish line?

@hvub hvub force-pushed the 2025.x-next-by-table-semantics branch from f04dcee to 63bdec3 Compare August 7, 2025 06:40
Copy link
Contributor

@rsill-neo4j rsill-neo4j left a comment

Choose a reason for hiding this comment

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

updated include tags

@rsill-neo4j
Copy link
Contributor

@rsill-neo4j What is the state of this PR from your point of view? Do you need any more input to take it over the finish line?

added a few suggestions for the tags -
restored two that were deleted, but where the queries weren't changed.
the PR moves one, deletes one, adds two, correct?

i'll create a PR for the cheat sheet to account for this.

@JoelBergstrand
Copy link
Contributor Author

@rsill-neo4j, @hvub, I've rereviewed the PR, looks great!


NEXT

MATCH (c:Customer)-[:BUYS]->(p)
RETURN collect(c.firstName) AS customers, p
RETURN c.firstName AS name, COLLECT(p.price * c.discount) AS purchases, "discounted price" AS type
Copy link
Contributor

Choose a reason for hiding this comment

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

while not technically wrong, i think the discount is calculated incorrectly on a conceptual level -
shouldn't it be (1 - c.discount) ? for example, hannah's laptop is at a discounted price of 37.5 (down from 250)

stumbled upon this just now while trying to understand the testing error

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 you are right.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should be fixed.

@rsill-neo4j rsill-neo4j self-requested a review August 19, 2025 07:57
Copy link
Contributor

@rsill-neo4j rsill-neo4j left a comment

Choose a reason for hiding this comment

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

4 suggestions to make it clear that changes were introduced with 2025.08, and an entry in the additions page as a direct commit

* `NEXT` can improve the usability of xref:queries/composed-queries/conditional-queries.adoc[conditional `WHEN`] and xref:queries/composed-queries/combined-queries.adoc[combined `UNION`] queries.
* `NEXT` can be used instead of xref:clauses/with.adoc[] clause to construct complex queries.
* `NEXT` can improve the usability of xref:queries/composed-queries/conditional-queries.adoc[].
* `NEXT` allows for passing the full table of intermediate results into the arms of xref:queries/composed-queries/combined-queries.adoc[].
Copy link
Contributor

@rsill-neo4j rsill-neo4j Aug 19, 2025

Choose a reason for hiding this comment

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

Suggested change
* `NEXT` allows for passing the full table of intermediate results into the arms of xref:queries/composed-queries/combined-queries.adoc[].
* `NEXT` allows for passing the full table of intermediate results to a xref:queries/composed-queries/combined-queries.adoc[`UNION`] clause.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe just: "...results to a xref:queries/composed-queries/combined-queries.adoc[UNION`] clause". (i.e. get rid of the poetic "into the arms" 😄 )

Copy link
Collaborator

Choose a reason for hiding this comment

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

If I understand it correctly, the below sections marked as new in 2025.08 are not new to this release (e.g. you could have NEXT interact with CALL in 2025.07), and I am not understanding from this update how it impacts users? If it is just an under-the-hood update, then I think it is fine to only make a small mention of it. E.g.
"As of Neo4j 2025.08,... Previously, ...."

If this makes a meaningful change to how NEXT queries work in 2025.06 and 2025.07, then we should have an example to the effect of "NEXT used to work like this: Now it works like that:..."

Copy link
Contributor

@rsill-neo4j rsill-neo4j Aug 19, 2025

Choose a reason for hiding this comment

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

double-checking the queries in the old version, at least this one (NEXT inside CALL) behaves differently (yielding 100% for all products):

MATCH (p:Product) WHERE p.name <> "Coffee"
CALL (p) {
    MATCH (p)<-[:BUYS]-(c:Customer)-[:BUYS]->(otherProduct)
    RETURN c, otherProduct
    NEXT
    RETURN count(DISTINCT c) AS customers, 0 AS customersAlsoBuyingCoffee
    UNION
    FILTER otherProduct.name = "Coffee"
    RETURN 0 as customers, count(DISTINCT c) AS customersAlsoBuyingCoffee
    NEXT
    RETURN max(customers) AS customers, max(customersAlsoBuyingCoffee) AS customersAlsoBuyingCoffee
}
RETURN p.name AS product,
       round(toFloat(customersAlsoBuyingCoffee) * 100 / customers, 1) AS percentageOfCustomersAlsoBuyingCoffee
  ORDER BY product

Copy link
Contributor

Choose a reason for hiding this comment

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

If there is aggregation in CALL the previous implementation was wrong, so they errored in the last release. Now they are implemented correctly. In that sense it is new.

Copy link
Contributor

Choose a reason for hiding this comment

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

The same for aggregation in a UNION.

Comment on lines 83 to 84
| The `NEXT` keyword used for linear composition of queries.
For more information, see xref:queries/composed-queries/sequential-queries.adoc[]
Copy link
Collaborator

Choose a reason for hiding this comment

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

This entry should be for allReduce

Copy link
Contributor

Choose a reason for hiding this comment

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

copy-paste error! should be fixed

* `NEXT` can improve the usability of xref:queries/composed-queries/conditional-queries.adoc[conditional `WHEN`] and xref:queries/composed-queries/combined-queries.adoc[combined `UNION`] queries.
* `NEXT` can be used instead of xref:clauses/with.adoc[] clause to construct complex queries.
* `NEXT` can improve the usability of xref:queries/composed-queries/conditional-queries.adoc[].
* `NEXT` allows for passing the full table of intermediate results into the arms of xref:queries/composed-queries/combined-queries.adoc[].
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe just: "...results to a xref:queries/composed-queries/combined-queries.adoc[UNION`] clause". (i.e. get rid of the poetic "into the arms" 😄 )

* `NEXT` can improve the usability of xref:queries/composed-queries/conditional-queries.adoc[conditional `WHEN`] and xref:queries/composed-queries/combined-queries.adoc[combined `UNION`] queries.
* `NEXT` can be used instead of xref:clauses/with.adoc[] clause to construct complex queries.
* `NEXT` can improve the usability of xref:queries/composed-queries/conditional-queries.adoc[].
* `NEXT` allows for passing the full table of intermediate results into the arms of xref:queries/composed-queries/combined-queries.adoc[].
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I understand it correctly, the below sections marked as new in 2025.08 are not new to this release (e.g. you could have NEXT interact with CALL in 2025.07), and I am not understanding from this update how it impacts users? If it is just an under-the-hood update, then I think it is fine to only make a small mention of it. E.g.
"As of Neo4j 2025.08,... Previously, ...."

If this makes a meaningful change to how NEXT queries work in 2025.06 and 2025.07, then we should have an example to the effect of "NEXT used to work like this: Now it works like that:..."

Co-authored-by: Jens Pryce-Åklundh <[email protected]>
@neo4j-docops-agent
Copy link
Collaborator

neo4j-docops-agent commented Aug 21, 2025

Thanks for the documentation updates.

The preview documentation has now been torn down - reopening this PR will republish it.

@rsill-neo4j rsill-neo4j merged commit 3213b93 into neo4j:dev Aug 22, 2025
5 checks passed
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.

5 participants