Repository navigation
fix(query): resolve lineno/filename/location per posting, not per directive - #1510
Merged
Merged
Conversation
…ective The lineno/filename/location columns reported the enclosing transaction line for every posting; beanquery reports each posting own line. Keep the SourceMap in the Executor and resolve these columns from the posting span (default and #postings paths), falling back to the directive location for synthesized postings. Updates the #1506 CLI test, which pinned the old txn-line behavior. Found via BQL dogfooding. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs main branch (2026-06-22)
What do these numbers mean?
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes BQL source-location reporting so filename / lineno / location resolve per posting (matching bean-query), rather than always using the enclosing directive’s location. This impacts both the default (implicit postings) query path and the FROM #postings table path.
Changes:
- Keep
SourceMapinExecutorand add span-based location resolution with fallback behavior for synthesized/no-source-map cases. - Update default column evaluation (
evaluation.rs) to resolve posting-level source locations. - Update
#postingstable building to compute per-posting filename/lineno/location, and extend tests to validate per-posting behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| crates/rustledger/tests/integration_test.rs | Adjusts CLI integration assertion to reflect per-posting line numbers and uses unique tempfile handling. |
| crates/rustledger-query/src/executor/mod.rs | Stores SourceMap, adds span/posting location resolution helpers, applies per-posting source location to #postings, and adds unit tests. |
| crates/rustledger-query/src/executor/evaluation.rs | Switches filename/lineno/location column evaluation to use per-posting resolved source locations with fallback. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+2624
to
+2632
| let (filename, lineno, location) = | ||
| match self.span_source_location(posting.file_id, posting.span.start) { | ||
| Some(loc) => ( | ||
| Value::String(loc.filename.clone()), | ||
| Value::Integer(loc.lineno as i64), | ||
| Value::String(format!("{}:{}", loc.filename, loc.lineno)), | ||
| ), | ||
| None => (filename.clone(), lineno.clone(), location.clone()), | ||
| }; |
Comment on lines
+384
to
+396
| // Source location columns — resolved from the posting's own span | ||
| // (falling back to the enclosing directive's location). | ||
| "filename" => Ok(self | ||
| .resolved_source_location(ctx) | ||
| .map_or(Value::Null, |loc| Value::String(loc.filename))), | ||
| "lineno" => Ok(self | ||
| .resolved_source_location(ctx) | ||
| .map_or(Value::Null, |loc| Value::Integer(loc.lineno as i64))), | ||
| "location" => Ok(self | ||
| .resolved_source_location(ctx) | ||
| .map_or(Value::Null, |loc| { | ||
| Value::String(format!("{}:{}", loc.filename, loc.lineno)) | ||
| })), |
Comment on lines
+4089
to
+4093
| Spanned { | ||
| value: Posting::new("Expenses:Food", Amount::new(dec!(-100), "USD")), | ||
| span: Span { start: 43, end: 67 }, | ||
| file_id, | ||
| }, |
Comment on lines
+4097
to
+4101
| let spanned = vec![Spanned { | ||
| value: Directive::Transaction(txn), | ||
| span: Span { start: 0, end: 67 }, | ||
| file_id, | ||
| }]; |
Comment on lines
166
to
169
| pub fn new_with_sources( | ||
| spanned_directives: &'a [Spanned<Directive>], | ||
| source_map: &SourceMap, | ||
| source_map: &'a SourceMap, | ||
| ) -> Self { |
Comment on lines
779
to
783
| // filename resolves to the real path (was empty/NULL before the fix). | ||
| assert!( | ||
| stdout.contains("query-filename-lineno-test.beancount"), | ||
| stdout.contains(".beancount"), | ||
| "expected the source filename in output, got:\n{stdout}" | ||
| ); |
Contributor
|
| Metric | Result |
|---|---|
| Check Compatibility | 100% |
| BQL Compatibility | 85% |
| Full AST Match | 100% |
| Total Files | 792 |
What's tested
- Check: Exit codes and error counts match
bean-check - BQL: Query results match
bean-query - Files: ~800 test files downloaded from 10+ beancount repositories
Full results available in workflow artifacts
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.
What
The
lineno/filename/locationcolumns reported the enclosing transaction's line for every posting, instead of each posting's own line. bean-query reports the posting's line:Found in round-4 BQL dogfounding. Affected both the default SELECT path and the explicit
FROM #postingspath.Root cause
source_locationsis keyed per-directive, and the Executor kept only those precomputed locations — not theSourceMap— so per-posting lines couldn't be resolved. Both row paths looked up the directive's location.How
SourceMapin the Executor (new_with_sources).span_source_location(file_id, span_start)resolves a location from a span; synthesized spans (pad/booking-generated) →None.evaluation.rs):filename/lineno/locationresolve viaresolved_source_location(ctx)— the posting's own span, falling back to the directive's location.#postingspath: per-posting location computed in the builder loop, falling back to the txn-level location.Synthesized postings (no real span) and source-map-less executors fall back to the prior behavior, so nothing regresses.
Tests
test_per_posting_source_location: postings on lines 2 & 3 reportlineno2 & 3 on both the default and#postingspaths. Existing source-location tests (synthesized postings → directive line) unchanged. Oracle-verified against bean-query. Fullrustledger-querysuite passes; clippy + fmt clean.🤖 Generated with Claude Code