fix: whitespace- and order-tolerant verbatim aggregate detection - #1207
Draft
domoritz wants to merge 3 commits into
Draft
fix: whitespace- and order-tolerant verbatim aggregate detection#1207domoritz wants to merge 3 commits into
domoritz wants to merge 3 commits into
Conversation
Fixes #1204. SQL allows whitespace between a function name and its argument list, so `sum (amount)` in a verbatim fragment was classified as non-aggregate and vgplot emitted no GROUP BY for the mark's other channels. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DEmcoxyFx2BRM5BbmJGFsa
Fixes #1205. The strip searched for the literal text `(select `, so a subquery broken across lines kept its aggregate calls in view and the whole expression was misclassified as an aggregate. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DEmcoxyFx2BRM5BbmJGFsa
Fixes #1206. The strip truncated at the first `(select`, so an aggregate written after a subquery was never seen and classification depended on operand order: `(select max(a) from t) + sum(b)` was treated as row-level while the swapped spelling was not. Each subquery's balanced-paren extent is now excised and the remaining text scanned. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DEmcoxyFx2BRM5BbmJGFsa
21 tasks
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.
Fixes #1204, #1205, #1206. Part of the audit tracked in #1170.
Three fixes to the verbatim-SQL classifier in
visit/visitors.ts, the scan that decides whether asqltemplate contains an aggregate (and so whether a mark emitsGROUP BY). One commit per issue; they ship together because the second alone would regress a multi-line subquery written before an aggregate, which only the third repairs.fix: tolerate whitespace between a function name and its paren— the call token pattern becomes\w+\s*\(and the name is trimmed before the aggregate-name test, somax (num1)andMAX\n(num1)classify as DuckDB parses them. No non-aggregate input changes class (checked againstcount_total * (x + 1),x in (1, 2),'count (' || x, a bare column namedsum, quoted"count (x)",avg (x) over (…)).fix: match scalar subquery starts regardless of whitespace—indexOf('(select ')becomes asubqueryRegExp(/\(\s*select\b/) at module level next towindowRegExp, so(\n SELECT …is stripped;(selection_id)is not.fix: strip every scalar subquery, not the expression tail— astripSubquerieshelper excises each(select …)group by matching parentheses and rescans the remainder, so(select max(y) from t) + sum(x)classifies as an aggregate like its swapped spelling does.The classifier stays quote-unaware by decision (#1170 defers that). Consequence for 3: a
)inside a string literal inside a subquery can end the excision early; that needs an unbalanced)in a literal followed by an aggregate call in the same subquery. Where it bites, the result is a binder error if the expression also reads a row-level column, and otherwise a regrouping of a constant subquery with identical plotted values; preaggregation is unaffected. Pinned in a test and noted in the one source comment.🤖 Generated with Claude Code
https://claude.ai/code/session_01DEmcoxyFx2BRM5BbmJGFsa