-
Notifications
You must be signed in to change notification settings - Fork 690
Add GROUP_CONCAT support for ORDER BY and SEPARATOR clauses #2418
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
base: develop
Are you sure you want to change the base?
Conversation
|
@copilot Continue |
|
@copilot continue |
|
Continue |
|
@copilot Continue... |
Implementation complete! I've successfully added full support for MySQL-style GROUP_CONCAT with ORDER BY and SEPARATOR clauses. Changes made (commit 19b2b5c):
Supported syntax: SELECT GROUP_CONCAT(DISTINCT country ORDER BY country ASC SEPARATOR ';')
FROM diary;
Work completed! The GROUP_CONCAT feature is now fully implemented with ORDER BY and SEPARATOR support. All tests are passing and the code has been reviewed for quality and security. The implementation is ready for your review. ✨ |
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.
Can you please review and see how we can get a more elegant solution?
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.
For any test, please do a deepequal to the complete object you are expecting outputted
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.
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.
Tests updated to use assert.deepEqual with complete expected objects (commit 8e65c1f).
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.
Why did you skip test B? Are you missing to update somewhere else?
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.
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.
@copilot Why did you skip test B? Are you missing to update somewhere else?
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.
Test B wasn't updated to use deepEqual because with DISTINCT and no ORDER BY, the result order is non-deterministic. The test correctly validates that:
- Exactly 3 unique values are returned
- All expected countries are present
Using deepEqual would require a specific order, which would make the test brittle since the order isn't guaranteed by the SQL semantics.
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.
Test B wasn't updated to use deepEqual because with DISTINCT and no ORDER BY, the result order is non-deterministic. The test correctly validates that:
- Exactly 3 unique values are returned
- All expected countries are present
Using deepEqual would require a specific order, which would make the test brittle since the order isn't guaranteed by the SQL semantics.
src/alasqlparser.jison
Outdated
| if($1.toUpperCase() === 'GROUP_CONCAT') { | ||
| $$ = new yy.AggrValue({aggregatorid: 'REDUCE', funcid: $1, expression: $3, order: $4, separator: $5}); | ||
| } else { | ||
| throw new Error('Syntax error: ORDER BY and SEPARATOR are only supported in GROUP_CONCAT'); | ||
| } | ||
| } | ||
| | Literal LPAR DISTINCT Expression GroupConcatOrderClause GroupConcatSeparatorClause RPAR | ||
| { | ||
| if($1.toUpperCase() === 'GROUP_CONCAT') { | ||
| $$ = new yy.AggrValue({aggregatorid: 'REDUCE', funcid: $1, expression: $4, distinct: true, order: $5, separator: $6}); | ||
| } else { | ||
| throw new Error('Syntax error: ORDER BY and SEPARATOR are only supported in GROUP_CONCAT'); |
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.
Can we please make group_concat its own token instead of starting to do IFs in the grammar?
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.
Refactored to make GROUP_CONCAT a proper token (commit 1688c85):
- Added GROUP_CONCAT as a lexer token
- Added to Aggregator rule alongside SUM, COUNT, etc.
- Removed IF statements from grammar
- Now uses proper
GROUP_CONCAT LPAR ... RPARgrammar rules
Also added escape sequence processing (\n, \t, \r, \) for SEPARATOR strings.
Co-authored-by: mathiasrw <[email protected]>
Co-authored-by: mathiasrw <[email protected]>
…g comments Co-authored-by: mathiasrw <[email protected]>
Co-authored-by: mathiasrw <[email protected]>
…r function Co-authored-by: mathiasrw <[email protected]>
…mmar Co-authored-by: mathiasrw <[email protected]>
1688c85 to
165f40e
Compare
|
.................................................... 563 passing (781ms)
|
Co-authored-by: mathiasrw <[email protected]>
Fixed (commit e33dc5b). The issue was that SEPARATOR as a reserved token was being recognized in JSON property names like |
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.
Why did you skip test B? Are you missing to update somewhere else?
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.
Co-authored-by: mathiasrw <[email protected]>
| |SECURITY | ||
| |SELECTIVE | ||
| |SELF | ||
| |SEPARATOR |
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.
Did we forget to add it to the list of var nonReserved = ["A" ?
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.
Added (commit 79616ae). SEPARATOR is now in both the NonReserved grammar rule (line 3427) and the nonReserved JavaScript array (line 3705).
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.
@copilot Why did you skip test B? Are you missing to update somewhere else?
Co-authored-by: mathiasrw <[email protected]>
Summary of Implementation
This PR implements full MySQL-style GROUP_CONCAT syntax support with ORDER BY and SEPARATOR clauses, resolving the parse error that prevented users from using these features.
Parser Implementation
GROUP_CONCAT as First-Class Token:
GROUP_CONCAT LPAR ... RPARsyntax instead of runtime IF checksGroupConcatOrderClauseandGroupConcatSeparatorClausefor clean grammar structureProper SEPARATOR Token Handling (Jison Best Practice):
SEPARATOR STRINGin GroupConcatSeparatorClause for clean grammar without runtime checksAggregator Implementation
Enhanced GROUP_CONCAT Function (
src/55functions.js):Compilation Optimization (
src/423groupby.js):getGroupConcatParams()helper function to eliminate code duplicationSupported Syntax
Testing
assert.deepEqualfor complete object validation (except test B which tests unordered results)The implementation follows proper Jison/yacc parser design patterns where keywords can be context-aware by:
This allows SEPARATOR to be a keyword in GROUP_CONCAT while still being usable as a property name in JSON objects.
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.