[WIP] Fix window aggregate functions not implementing semantics #2411
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.
Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.
Original prompt
This section details on the original issue you should resolve
<issue_title>Window Aggregate Functions (COUNT/MAX/MIN) Not Working with PARTITION BY</issue_title>
<issue_description>## Summary
Window aggregate functions like
COUNT(),MAX(), andMIN()withOVER (PARTITION BY ...)clauses are parsed successfully but do not implement proper window function semantics. Instead of returning one row per input row with the windowed aggregate value, they collapse the result set to a single row with the overall aggregate.Current Behavior
Expected Behavior
Technical Details
Working Reference
ROW_NUMBER() OVER (PARTITION BY ...)works correctly (implemented insrc/424select.jslines 514-529)OVERclause structure (src/47over.js)Problem Location
The issue appears to be in how aggregate functions interact with the OVER clause:
src/alasqlparser.jison- correctly parses OVER clausesrc/424select.js- needs window function execution logicsrc/55functions.js- aggregate functions don't check for OVER clauseRoot Cause
When an aggregate function (COUNT/MAX/MIN/SUM/AVG) has an OVER clause, it should:
Currently, the aggregate behavior treats it as a regular GROUP BY aggregate, collapsing rows.
Affected Functions
COUNT(*) OVER (PARTITION BY ...)MAX(column) OVER (PARTITION BY ...)MIN(column) OVER (PARTITION BY ...)SUM(column) OVER (PARTITION BY ...)(likely)AVG(column) OVER (PARTITION BY ...)(likely)Test Case
Implementation Approach
References
ROW_NUMBER()insrc/424select.jsPriority
High - This is a core SQL feature that users expect to work when the syntax is accepted.
Related Issues
ROW_NUMBER() OVER (PARTITION BY ...)working correctly (can serve as template)</issue_description>Comments on the Issue (you are @copilot in this section)
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.