Repository navigation
fix: implement implicit GROUP BY for aggregate queries (issue #575) - #590
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Implements Python beancount-compatible implicit GROUP BY behavior for aggregate queries that mix aggregate functions with non-aggregated columns (fixing issue #575).
Changes:
- Added implicit grouping logic in
execute_select()for aggregate queries when no explicitGROUP BYis provided. - Introduced
extract_implicit_group_by_exprs()helper to derive non-aggregate grouping expressions fromSELECTtargets. - Added integration/regression tests covering implicit grouping, pure aggregates, and explicit
GROUP BYprecedence.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/rustledger-query/src/executor/execution.rs | Computes an “effective” group-by for aggregate queries (explicit if present, otherwise implicit). |
| crates/rustledger-query/src/executor/aggregation.rs | Adds helper to extract non-aggregate expressions from SELECT targets for implicit grouping. |
| crates/rustledger-query/tests/bql_integration_test.rs | Adds regression tests for issue #575 and related grouping behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
robcohen
force-pushed
the
fix/issue-575-implicit-group-by
branch
from
March 29, 2026 16:14
6d45d94 to
fceb899
Compare
When aggregate functions are mixed with non-aggregated columns and no explicit GROUP BY is provided, Python beancount implicitly groups by the non-aggregated columns. This fix implements the same behavior. For example, `SELECT sum(number), currency, account ORDER BY account` now correctly returns one row per (currency, account) combination instead of a single aggregated row. Changes: - Added `extract_implicit_group_by_exprs()` to extract non-aggregate column expressions from SELECT targets - Modified `execute_select()` to use implicit GROUP BY when needed - Added regression tests for issue #575 Fixes #575 Co-Authored-By: Claude Opus 4.5 <[email protected]>
robcohen
force-pushed
the
fix/issue-575-implicit-group-by
branch
from
March 29, 2026 16:22
fceb899 to
5d42064
Compare
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs main branch (2026-03-29)
What do these numbers mean?
|
robcohen
enabled auto-merge
March 29, 2026 16:26
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
robcohen
added this pull request to the merge queue
Mar 29, 2026
This was referenced Mar 30, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
extract_implicit_group_by_exprs()helper to extract non-aggregate expressionsexecute_select()to use implicit grouping when no explicit GROUP BY is providedProblem
Query
SELECT sum(number), currency, account ORDER BY accountreturned 1 row instead of 3.Python beancount output (expected):
Rustledger output (before fix):
Root Cause
When aggregate functions are mixed with non-aggregated columns and no explicit GROUP BY is provided, Python beancount implicitly groups by the non-aggregated columns. Rustledger was treating all postings as a single group.
Fix
In
execute_select(), when an aggregate query has no explicit GROUP BY:group_postings()for proper groupingTest plan
cargo test -p rustledger-query- all 189 tests passcargo clippy -p rustledger-query -- -D warnings- no warningstest_issue_575_implicit_group_by- main regression testtest_pure_aggregate_no_implicit_group_by- verifies pure aggregates still worktest_explicit_group_by_overrides_implicit- verifies explicit GROUP BY takes precedenceFixes #575
🤖 Generated with Claude Code