Repository navigation
Conversation
… has it UNWIND [1, 1, 2] AS x WITH x, count(x) AS c RETURN c, count(x) returned 1|1 twice instead of 2|1 and 1|1; sum(x) and count(DISTINCT x) did the same, and so did count(x) + x after WITH x, count(x) + x AS c. An aggregate is named after its function and arguments, so the RETURN's count(x) had the name of the expression carried in c, or of a part of it, and took that column. An aggregate in a projection list whose name an expression in scope already has, at any depth, now gets a fresh name, reused for each occurrence in the list. In WHERE and ORDER BY an aggregate keeps its structural name, so WITH x, count(x) AS c WHERE count(x) > 1 still filters on c, and so does an aggregate inside a lambda body, which the projection does not compute. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This work was produced with the help of language models.
Fixes #1246.
UNWIND [1, 1, 2] AS x WITH x, count(x) AS c RETURN c, count(x)returned1|1twice instead of2|1and1|1;sum(x),count(DISTINCT x)andcount(x) + xafterWITH x, count(x) + x AS cwent wrong the same way. An aggregate is named after its function and arguments, so theRETURN'scount(x)had the name of the expression carried inc, or of a part of it, and read that column instead of being computed.Fix. An aggregate in a projection list whose structural name an expression in scope already has, at any depth, now gets a fresh name, as
count(*)always did; the same aggregate repeated in one list shares it, so it is computed once. InWHEREandORDER BYan aggregate keeps its structural name, soWITH x, count(x) AS c WHERE count(x) > 1still filters oncandORDER BY count(x)still sorts by it, and so does an aggregate inside a lambda body, which the projection does not compute.Tests.
agg/multi_query_part.testgetsRepeatedAggregateAfterWithGroupKey: the four queries above, a list withcount(x)twice, and theWHERE,ORDER BYandall(i IN [1] WHERE i < count(x))cases that must keep readingc. Onmainthe first five statements return wrong rows and the last three pass; all eight pass here. Full suite: no failures.