Skip to content

Fix grouped count aggregation on SQL Server#778

Open
apples-kksk wants to merge 19 commits into
sqlkata:masterfrom
apples-kksk:fix/sqlserver-groupby-removal-774
Open

Fix grouped count aggregation on SQL Server#778
apples-kksk wants to merge 19 commits into
sqlkata:masterfrom
apples-kksk:fix/sqlserver-groupby-removal-774

Conversation

@apples-kksk
Copy link
Copy Markdown

Requested

Issue #774 reports that SQL Server compilation removes GROUP BY from grouped count queries.

Implemented

  • Preserve grouped query shape when transforming single-column AsCount() aggregate queries.
  • Wrap grouped counts in an outer COUNT(*) query while keeping the inner GROUP BY.
  • Added a SQL Server regression test for GroupBy(...).AsCount().

Not covered

No changes to distinct aggregate behavior or unrelated compiler output.

Validated

  • dotnet test /home/molang/bounty-work/querybuilder/sqlkata.sln --filter CountWithGroupBy
  • dotnet build /home/molang/bounty-work/querybuilder/sqlkata.sln
  • git diff --check

Also ran full dotnet test /home/molang/bounty-work/querybuilder/sqlkata.sln; non-MySQL tests passed, while 11 MySqlExecutionTest cases failed because the local MySQL test service is not available in this environment.

ahmad-moussawi and others added 19 commits February 1, 2025 07:45
This workflow automates the build and test process for a .NET project on push and pull request events to the main branch.
Added SQL Server service container and updated installation steps for sqlcmd tools.
- Add Clone() method to Include class for deep copying
- Fix Query.Clone() to deep-copy Includes list and Variables dictionary
- Fix XQuery.Clone() with same deep-copy fixes
- Add unit tests for the clone bug (independent list, objects, dict, properties)

Fixes sqlkata#747

Agent-Logs-Url: https://github.com/sqlkata/querybuilder/sessions/d82ad628-73f5-4c2f-b56e-f4021ce1519f

Co-authored-by: ahmad-moussawi <2517523+ahmad-moussawi@users.noreply.github.com>
Fix Query.Clone() shallow copy of Includes and Variables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants