Translate string.Join/Concat with ordering on SQLite#38344
Conversation
SQLite 3.44.0 added support for ORDER BY inside aggregate functions (group_concat(value, separator ORDER BY ...)). Translate string.Join and string.Concat over an ordered source instead of falling back to client evaluation. - Add SqliteAggregateFunctionExpression carrying the orderings - Render the ORDER BY inside the function in SqliteQuerySqlGenerator - Handle the new expression in SqliteSqlNullabilityProcessor - Enable the Join_with_ordering test Fixes dotnet#32201
|
@Aykuttonpc please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement ( “Agreement” ) is agreed to by the party signing below ( “You” ), 1. Definitions. “Code” means the computer software code, whether in human-readable or machine-executable form, “Project” means any of the projects owned or managed by .NET Foundation and offered under a license “Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any “Submission” means the Code and any other copyrightable material Submitted by You, including any 2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any 3. Originality of Work. You represent that each of Your Submissions is entirely Your 4. Your Employer. References to “employer” in this Agreement include Your employer or anyone else 5. Licenses. a. Copyright License. You grant .NET Foundation, and those who receive the Submission directly b. Patent License. You grant .NET Foundation, and those who receive the Submission directly or c. Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement. 6. Representations and Warranties. You represent that You are legally entitled to grant the above 7. Notice to .NET Foundation. You agree to notify .NET Foundation in writing of any facts or 8. Information about Submissions. You agree that contributions to Projects and information about 9. Governing Law/Jurisdiction. This Agreement is governed by the laws of the State of Washington, and 10. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and .NET Foundation dedicates this Contribution License Agreement to the public domain according to the Creative Commons CC0 1. |
There was a problem hiding this comment.
Pull request overview
This PR enables translation of string.Join/string.Concat over an ordered grouping in the SQLite provider by emitting SQLite’s group_concat(... ORDER BY ...) syntax (SQLite >= 3.44.0), avoiding client evaluation for these queries.
Changes:
- Introduces
SqliteAggregateFunctionExpressionto represent aggregate function invocations that carryORDER BYinformation. - Updates SQLite string-aggregate translation to allow ordered inputs and updates SQL generation to render
ORDER BYinside the aggregate function parentheses. - Enables the
Join_with_orderingSQLite functional test to assert server translation.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/EFCore.Sqlite.FunctionalTests/Query/Translations/StringTranslationsSqliteTest.cs | Updates expected SQL for ordered string aggregation using group_concat(... ORDER BY ...). |
| src/EFCore.Sqlite.Core/Query/Internal/Translators/SqliteStringAggregateMethodTranslator.cs | Emits the new aggregate expression when orderings are present instead of refusing translation. |
| src/EFCore.Sqlite.Core/Query/Internal/SqliteSqlNullabilityProcessor.cs | Adds nullability-processing support for the new custom SQL expression node. |
| src/EFCore.Sqlite.Core/Query/Internal/SqliteQuerySqlGenerator.cs | Adds SQL generation for aggregate ORDER BY inside function parentheses. |
| src/EFCore.Sqlite.Core/Query/Internal/SqlExpressions/SqliteAggregateFunctionExpression.cs | New SQL expression type carrying aggregate function name, arguments, and orderings. |
- Refuse translation when the SQLite version is below 3.44 (ServerVersion check), falling back to client evaluation as before - Refuse ORDER BY combined with DISTINCT, which SQLite restricts to ordering by the distinct value itself - Skip Join_with_ordering on SQLite versions below 3.44
|
Good catches all three addressed in b89fb2b: version-gated to 3.44 (falls back to client eval below that), DISTINCT + ORDER BY now refused, and the test is gated the same way. |
Translates
string.Join/string.Concatover an ordered grouping to SQLite'sgroup_concatwith anORDER BYclause, supported since SQLite 3.44.0. Previously such queries fell back to client evaluation.Changes
SqliteAggregateFunctionExpression(carries the orderings), mirroringSqlServerAggregateFunctionExpressionSqliteStringAggregateMethodTranslator: stop refusing translation when an ordering is present; emit the new expression (plaingroup_concatwhen there's no ordering — SQL unchanged)SqliteQuerySqlGenerator: rendergroup_concat(value, separator ORDER BY ...). Note SQLite places the ordering inside the parentheses, unlike SQL Server'sWITHIN GROUPSqliteSqlNullabilityProcessor: handle the new expressionJoin_with_orderinginStringTranslationsSqliteTestNotes
group_concat(string aggregation);ORDER BYis meaningless forMin/Max.group_concat(DISTINCT x ORDER BY y)is restricted in SQLite (DISTINCT + ORDER BY only when ordering by the distinct column); no base test covers this combination.Fixes #32201