fix(parse): recognize a window function using a named window - #342
Merged
Conversation
Query<DB, 'select sum(salary) over w from users window w as (order by id)'>
// was { 'over w': number }[]
`over w` refers to a window declared in a WINDOW clause - the other half of
the syntax, where what follows OVER is a name rather than an inline
definition. FindOverKeyword and SplitWindowExpression both wanted a paren
directly after `over`, so the entry was not read as a window expression at
all and fell through to the first-space bare-alias split, which made
`over w` the alias of `sum(salary)`. The value came out right by coincidence;
the key was nonsense.
The [never] guard added alongside it is load-bearing: FindOverKeyword
resolves to never for an entry with no OVER, and `never extends { expr:
infer E extends string; rest: infer R extends string }` passes with both
infers falling back to `string`, which the new named-window branch would
have accepted as a window name - every column in the suite came back a
window function until the guard went in.
Fixes #301
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
tiagolauer
force-pushed
the
fix/301-named-window
branch
from
August 2, 2026 13:04
bb99099 to
9e5d23c
Compare
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 #301.
The bug
Expected
{ sum: number }[]. The value type comes out right by coincidence; the key is nonsense.The fix
FindOverKeyword/SplitWindowExpressionrequired a(directly afterover, so the named-window form was not recognized as a window expression and the entry fell through to the first-space bare-alias split — makingover wthe alias ofsum(salary).What follows
OVERmay now be a name instead of an inline definition, in which case it is consumed as the window reference and whatever comes after it is treated as the alias, exactly as the parenthesized form already does.The
[never]guard that came with it is the interesting part.FindOverKeywordresolves toneverfor an entry with noOVERat all, andnever extends { expr: infer E extends string; rest: infer R extends string }passes with both infers falling back to their constraints — so with the paren no longer required,Restcame through asstringand every column in the suite was read as a window function (308 errors across 42 files on the first run). Same[never]patternExtraSourcesAfterKeywordandParseWithClausealready carry.Verification
tests/window.test-d.ts, three new cases, all red on master:over wunaliased (keyedsum), with anas totalalias, and alongside a regular columnThe four existing assertions (inline
over (...), emptyover (), aliased, alongside a column) stay pinned.tsc --noEmitclean, 192 runtime tests pass, budget 192,572 (+86).