Repository navigation
fix(query): resolve filename/lineno columns in the CLI - #1506
Merged
Merged
Conversation
The query engine supports source locations via new_with_sources, but the CLI stripped spans before booking and used Executor::new, so filename/lineno were NULL. Add span-preserving merge_with_padding_spanned and thread the source map through execute_query / the REPL. Found via BQL dogfooding. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Contributor
📊 Benchmark Results
vs main branch (2026-06-21)
What do these numbers mean?
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes rledger query so BQL location-related columns (filename, lineno, location, and meta-derived lookups) resolve to real source positions by preserving Spanned<Directive> data through padding merge and constructing the query Executor with the ledger SourceMap.
Changes:
- Add
merge_with_padding_spannedinrustledger-bookingto merge pad-synth transactions without dropping directive spans. - Update the CLI query command (batch + interactive) to pass
Spanned<Directive>andSourceMapthrough toExecutor::new_with_sources. - Add a CLI e2e regression test ensuring
SELECT filename, linenoreturns a real path and expected line number.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/rustledger/tests/integration_test.rs | Adds an end-to-end regression test for filename/lineno resolution in rledger query. |
| crates/rustledger/src/cmd/query/output.rs | Switches query execution to Executor::new_with_sources and threads SourceMap into execution. |
| crates/rustledger/src/cmd/query/mod.rs | Preserves spanned directives, merges via merge_with_padding_spanned, and passes SourceMap into batch/interactive execution. |
| crates/rustledger/src/cmd/query/interactive.rs | Threads SourceMap through REPL execution and dot-commands to keep location columns resolvable. |
| crates/rustledger-booking/src/pad.rs | Introduces merge_with_padding_spanned (span-preserving padding merge) and marks synth pad transactions as synthesized. |
| crates/rustledger-booking/src/lib.rs | Re-exports merge_with_padding_spanned. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+355
to
+357
| /// [`Spanned::synthesized`] ([`Span::ZERO`](rustledger_core::Span) + | ||
| /// [`SYNTHESIZED_FILE_ID`](rustledger_core::SYNTHESIZED_FILE_ID)) — exactly how | ||
| /// other synthesized directives (plugin output, etc.) are marked. |
Comment on lines
+364
to
+366
| pub fn merge_with_padding_spanned(directives: &[Spanned<Directive>]) -> Vec<Spanned<Directive>> { | ||
| let plain: Vec<Directive> = directives.iter().map(|s| s.value.clone()).collect(); | ||
| debug_assert!( |
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
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
robcohen
added a commit
that referenced
this pull request
Jun 22, 2026
…#1508) * fix(query): PRINT falls back to spanned_directives (was empty in CLI) execute_print iterated self.directives, which is empty when the executor is built via new_with_sources (the CLI path since #1506) — so PRINT returned 0 rows. Add the same spanned_directives fallback the system-table builders use. Co-Authored-By: Claude Opus 4.8 <[email protected]> * test(query): use a unique tempfile in the PRINT integration test Addresses Copilot on #1508 — avoids cross-run collisions on a fixed temp path; NamedTempFile auto-removes (drops the explicit cleanup). Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Jun 22, 2026
…ective (#1510) 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]>
robcohen
added a commit
that referenced
this pull request
Jun 22, 2026
execute_journal iterated self.directives directly, but new_with_sources (CLI/LSP) leaves that empty and stores directives in spanned_directives — so JOURNAL returned zero rows in the CLI, regressing BQL JOURNAL compat 90/90 -> 12/90 from #1506. SELECT/PRINT/BALANCES already had inline fallbacks; JOURNAL was missed. Add a resolved_directives() accessor and route JOURNAL + SELECT + PRINT through it so it cannot recur. Adds a source-mapped JOURNAL regression test. Co-Authored-By: Claude Opus 4.8 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Jun 22, 2026
execute_journal iterated self.directives directly, but new_with_sources (CLI/LSP) leaves that empty and stores directives in spanned_directives — so JOURNAL returned zero rows in the CLI, regressing BQL JOURNAL compat 90/90 -> 12/90 from #1506. SELECT/PRINT/BALANCES already had inline fallbacks; JOURNAL was missed. Add a resolved_directives() accessor and route JOURNAL + SELECT + PRINT through it so it cannot recur. Adds a source-mapped JOURNAL regression test. Co-Authored-By: Claude Opus 4.8 <[email protected]>
robcohen
added a commit
that referenced
this pull request
Jun 22, 2026
#1531) * fix(query): JOURNAL must read spanned_directives (BQL compat 77%->93%) execute_journal iterated self.directives directly, but new_with_sources (CLI/LSP) leaves that empty and stores directives in spanned_directives — so JOURNAL returned zero rows in the CLI, regressing BQL JOURNAL compat 90/90 -> 12/90 from #1506. SELECT/PRINT/BALANCES already had inline fallbacks; JOURNAL was missed. Add a resolved_directives() accessor and route JOURNAL + SELECT + PRINT through it so it cannot recur. Adds a source-mapped JOURNAL regression test. Co-Authored-By: Claude Opus 4.8 <[email protected]> * perf(query): resolved_directives returns an iterator, not a Vec Copilot on #1531: avoid the per-call Vec<&Directive> allocation. The two directive sources are mutually exclusive, so chaining them yields the populated one with zero allocation; all three callers only iterate. Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
This was referenced Jun 23, 2026
robcohen
added a commit
that referenced
this pull request
Jun 23, 2026
* ci(compat): block on BQL query regressions The Compatibility job recorded results but never failed, so #1506 dropped BQL JOURNAL 90->12 and merged unblocked. Add --baseline to compat-bql-test.py: exit non-zero if any (file, query) pair that matched on the baseline now fails (a true->false flip; robust to corpus/coverage changes). compat.yml fetches mains BQL results as the baseline and passes --baseline. Baseline-commit is already PR-gated and runs after, so a regression is never blessed into the baseline. Co-Authored-By: Claude Opus 4.8 <[email protected]> * ci(compat): tolerate corrupt baseline lines in the BQL gate Copilot on #1533: a truncated/corrupt baseline JSONL line crashed json.loads with a traceback. Skip unparsable lines; a wholly-unparsable baseline yields an empty passing-set (no gate that run) rather than a spurious block. Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
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
BQL
SELECT filename, lineno(andlocation,getitem(meta,'lineno')) returned NULL fromrledger query; bean-query returns the real source path + line number. Found by BQL dogfounding (round 3).Root cause
The query engine supports source locations via
Executor::new_with_sources(spanned_directives, source_map), but the CLI never used it:cmd/query/mod.rsstripped theSpannedwrappers (ledger.directives.into_iter().map(|s| s.value)) before booking and calledExecutor::new(no source map), so the location columns had nothing to resolve.How
merge_with_padding_spannedinrustledger-booking: same merge behavior asmerge_with_padding, but keeps each directive'sSpannedwrapper; pad-synthesized transactions (no source) are marked withSpanned::synthesized(Span::ZERO+SYNTHESIZED_FILE_ID) → they resolve to no location, exactly like other synthesized directives.query: keepledger.directives(spanned) +ledger.source_map, merge via the spanned variant, and thread both throughexecute_query→Executor::new_with_sources. Updatedrun_interactive,handle_dot_command, andcount_statisticsaccordingly (all 6execute_querycall sites).Tests
test_query_filename_lineno_columns_resolve(CLI e2e):SELECT filename, linenoreturns the real path + line 3 for the transaction (was empty).rustledger-bookingandrustledger-querysuites pass unchanged; clippy + fmt clean.🤖 Generated with Claude Code