-
Notifications
You must be signed in to change notification settings - Fork 690
Fix ORDER BY clause handling in multiple UNIONs #2188
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
- Modified alasqlparser.jison to create SelectWithoutOrderOrLimit rule - Updated UnionClause to reference SelectWithoutOrderOrLimit - Fixed 40select.js to not override top-level orderfn from union clauses - Added orderColumns to query object for union handling - Added logic in 38query.js to populate order keys before sorting for union queries - Enabled test7.js tests Co-authored-by: mathiasrw <[email protected]>
Co-authored-by: mathiasrw <[email protected]>
|
Run yarn test-format-all |
- Added 7 new test cases (G-M) covering plain UNION, INTERSECT, EXCEPT, and edge cases - Fixed code formatting in src/38query.js and src/424select.js using prettier - All 13 test cases in test7.js now pass Co-authored-by: mathiasrw <[email protected]>
|
@copilot Please run |
Ran `yarn jison` to regenerate src/alasqlparser.js from the grammar file. All tests continue to pass. Co-authored-by: mathiasrw <[email protected]>
|
@copilot Did you see the comments? |
Added test case N covering UNION ALL across 4 actual tables with ORDER BY. This test demonstrates the fix works with real table data, not just literal values. Co-authored-by: mathiasrw <[email protected]>
|
@copilot Please run |
Ran `yarn jison` to regenerate src/alasqlparser.js from the grammar file. Parser state numbers updated. All tests continue to pass. Co-authored-by: mathiasrw <[email protected]>
Fixes the ORDER BY clause handling when used with three or more UNION operations. Previously, the ORDER BY was incorrectly applied to intermediate SELECT statements rather than the final result set.
Changes Made
Grammar Changes (alasqlparser.jison)
UnionClauseandOrderClause/LimitClausein theSelectrule to align with SQL-99 syntaxSelectWithoutOrderOrLimitrule to prevent ORDER BY from being nested in union clausesUnionClauseto referenceSelectWithoutOrderOrLimitinstead ofSelectyarn jisonto ensure consistency with grammar changesExecution Logic Updates
orderfnand not override it with union clause order; addedorderColumnsto query object for proper union handlingcompileSelect2andcompileSelectGroup2to skip adding order keys duringselectfnexecution when union operations are presentTest Coverage (test7.js)
Code Quality
src/38query.js,src/424select.js, andtest/test7.jsusing PrettierTesting
yarn test-format-allyarn jisonExample
Before (Incorrect):
After (Correct):
Real-World Example (4 Tables):
Fixes #7
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.