-
Notifications
You must be signed in to change notification settings - Fork 690
Fix window aggregate functions not implementing semantics #2411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Continue |
|
@copilot Continue... |
…TITION BY Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
I've implemented window aggregate functions with PARTITION BY support. The implementation now allows COUNT(), MAX(), MIN(), SUM(), and AVG() to work correctly with OVER (PARTITION BY ...) clauses. Changes made (commit e1e87f4):
Key features:
|
mathiasrw
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a lot of code for such a simple issue.
Please review and see how we can make the code more elegant.
Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
Refactored for elegance (commit f2d12d7). The code is now ~49% more concise: Key improvements:
Result: Reduced from 116 added lines to 59 added lines while maintaining full functionality and test coverage. |
Co-authored-by: mathiasrw <1063454+mathiasrw@users.noreply.github.com>
re_aggrWithExpressionregex outside hot code pathOriginal 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.