Skip to content

fix(query): resolve filename/lineno columns in the CLI - #1506

Merged
robcohen merged 1 commit into
mainfrom
fix/bql-cli-source-locations
Jun 22, 2026
Merged

robcohen merged 1 commit into
mainfrom
fix/bql-cli-source-locations

Conversation

@robcohen

Copy link
Copy Markdown
Member

What

BQL SELECT filename, lineno (and location, getitem(meta,'lineno')) returned NULL from rledger 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.rs stripped the Spanned wrappers (ledger.directives.into_iter().map(|s| s.value)) before booking and called Executor::new (no source map), so the location columns had nothing to resolve.

How

  • New span-preserving merge_with_padding_spanned in rustledger-booking: same merge behavior as merge_with_padding, but keeps each directive's Spanned wrapper; pad-synthesized transactions (no source) are marked with Spanned::synthesized (Span::ZERO + SYNTHESIZED_FILE_ID) → they resolve to no location, exactly like other synthesized directives.
  • CLI query: keep ledger.directives (spanned) + ledger.source_map, merge via the spanned variant, and thread both through execute_query → Executor::new_with_sources. Updated run_interactive, handle_dot_command, and count_statistics accordingly (all 6 execute_query call sites).

Tests

test_query_filename_lineno_columns_resolve (CLI e2e): SELECT filename, lineno returns the real path + line 3 for the transaction (was empty). rustledger-booking and rustledger-query suites pass unchanged; clippy + fmt clean.

🤖 Generated with Claude Code

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]>
@robcohen
robcohen requested a review from a team as a code owner June 22, 2026 00:59
Copilot AI review requested due to automatic review settings June 22, 2026 00:59
@github-actions

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 33ms ± 0.8ms 23.7 MB
beancount 880ms ± 5.8ms 50.5 MB
Comparison 26.7x faster 2.1x less

vs main branch (2026-06-21)

Metric main this PR Change
Time 37.7ms 33ms -12.5% 🟢
10K transactions · 5 runs, 2 warmup · hyperfine
What do these numbers mean?
  • Time: Wall-clock time to parse and validate the ledger (± std dev)
  • Memory: Peak resident set size (RSS)
  • vs main: Compared to latest nightly benchmark on main branch

@robcohen
robcohen merged commit 058f3cf into main Jun 22, 2026
48 checks passed
@robcohen
robcohen deleted the fix/bql-cli-source-locations branch June 22, 2026 01:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_spanned in rustledger-booking to merge pad-synth transactions without dropping directive spans.
  • Update the CLI query command (batch + interactive) to pass Spanned<Directive> and SourceMap through to Executor::new_with_sources.
  • Add a CLI e2e regression test ensuring SELECT filename, lineno returns 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!(
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Compatibility Test Results

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

codecov Bot commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 46.80851% with 25 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger/src/cmd/query/interactive.rs 0.00% 18 Missing ⚠️
crates/rustledger/src/cmd/query/mod.rs 30.00% 7 Missing ⚠️

📢 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]>
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]>
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.

2 participants