Skip to content

feat(query): make meta selectable on #transactions - #2181

Merged
robcohen merged 4 commits into
mainfrom
fix/bql-transactions-meta
Aug 29, 2026
Merged

robcohen merged 4 commits into
mainfrom
fix/bql-transactions-meta

Conversation

@robcohen

@robcohen robcohen commented Aug 29, 2026 •

Copy link
Copy Markdown
Member

What

The last of #2154's eleven columns. bean-query answers
SELECT meta FROM #transactions; we returned nothing.

$ bean-query -f csv f.bean "SELECT meta FROM #transactions"
{'mtxn': 'tv'}

$ rledger query -f csv f.bean "SELECT meta FROM #transactions"   # before
                                                                  # (empty)

Wildcard-hidden, because bean-query keeps SELECT * FROM #transactions at
seven columns — the same split #2161 established for the other five per-table
meta columns. No existing output changes, so no snapshot drift anywhere.

User keys only: bean-query's per-table meta excludes filename/lineno,
which only #entries carries (#2162), so this must not route through
augmented_meta.

#2154 is now complete, and what remains is a different kind of problem

A census of all 55 columns bean-query exposes across its ten system tables
finds three unselectable here — with a negative control confirming the census
detects a genuinely absent column:

#notes.tags, #notes.links Note drops them at parse time (#2160)
#balances.discrepancy the checker computes it and does not store it on the directive (#2180)

Neither is a schema-registration gap, which is what #2154 was about. #2180 is
filed as part of this PR, and the comment in build_balances_table that
pointed at #2154 for discrepancy now points there instead, so the reference
survives #2154 closing.

The test needed a real SourceMap to mean anything

It asserts three things: meta resolves by name, SELECT * stays at seven
columns, and the map carries no source keys.

That third assertion was decorative at first. With a plain
Executor::new there is no source location, so augmented_meta returns its
input unchanged — I mutated the column to route through it and the test still
passed. The fixture now builds a source-mapped executor, and that mutation
fails.

All three ways to get this wrong are covered, checked one at a time:

Cost of building it unconditionally

The column is built for every row, like the other five per-table meta
columns. Measured rather than assumed, against a binary built from main,
--no-cache, interleaved:

ledger query main this PR
no transaction metadata count(date) FROM #transactions 170–180 ms 175–178 ms (noise)
no transaction metadata SELECT * FROM #transactions 228–230 ms 225–227 ms (noise)
5 keys on every txn count(date) FROM #transactions 371–375 ms 400–406 ms (+8%)

So the worst case is ~30 ms on a deliberately extreme shape, for a query that
never selects meta. Far from the 40% that justified the projection gating in
#2169, so that machinery is not worth the review surface here. The number is
recorded at the code so a future reader deciding otherwise has it.

Verification

  • SELECT * parity across all ten tables unchanged: 6 match, 4 differ, exactly
    as before this PR.
  • Booked-value gate clean (known 34, found 34, new 0).
  • clippy at CI's 1.97, fmt, typos, rustdoc clean; 416 tests pass.

Closes #2154

The last of #2154's eleven columns. bean-query answers
`SELECT meta FROM #transactions`; we returned nothing. Its `SELECT *`
stays at seven columns, so this is wildcard-hidden -- the same split
#2161 established for the other five per-table `meta` columns, and it
means no existing output changes.

User keys only. bean-query's per-table `meta` excludes `filename` and
`lineno`; only `#entries` carries them (#2162), so this must not route
through `augmented_meta`.

A census of all 55 columns bean-query exposes across its ten system
tables now finds three unselectable here, and all three need model
changes rather than schema entries:

  #notes.tags, #notes.links   Note drops them at parse time (#2160)
  #balances.discrepancy       the balance checker computes it and does
                              not store it on the directive (#2180)

#2180 is filed as part of this, and the comment in `build_balances_table`
that pointed at #2154 for `discrepancy` now points there instead, so the
reference survives #2154 closing.

The test asserts both halves -- selectable by name, absent from the
wildcard -- and that the map carries no source keys. That last assertion
needed a source-mapped executor to mean anything: with a plain
`Executor::new` the location is None, `augmented_meta` returns its input
unchanged, and routing this column through it passed the test. It fails
now.

Closes #2154
@robcohen
robcohen requested a review from a team as a code owner August 29, 2026 12:15
Copilot AI lite review requested due to automatic review settings August 29, 2026 12:15

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.

🟢 Approval recommended

The change is narrowly scoped, preserves wildcard output shape via with_hidden, and includes a focused integration test that prevents the main regression modes.

Pull request overview

Adds the missing meta column to the #transactions system table in rustledger-query, making SELECT meta FROM #transactions behave like bean-query while keeping SELECT * FROM #transactions at the same 7-column shape (via per-table hidden columns).

Changes:

  • Register meta on #transactions and mark it hidden from wildcard expansion (SELECT *).
  • Ensure #transactions.meta returns user metadata only (does not route through augmented_meta, so no filename/lineno injection).
  • Add an integration test that pins both behaviors: meta is selectable, and wildcard stays at seven columns.
File summaries
File Description
crates/rustledger-query/src/executor/system_tables.rs Adds meta to #transactions table schema, hides it from SELECT *, and documents discrepancy issue reference update (#2180).
crates/rustledger-query/tests/bql_integration_test.rs Adds a source-mapped regression test ensuring #transactions.meta is selectable, hidden from wildcard, and excludes filename/lineno.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Aug 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

🔴 Slower than base on: fifo

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 47.6ms ± 5.7ms 598.4ms ± 6.9ms 12.6x 55.1 MB / 50.1 MB
investment 67.5ms ± 4.3ms 2232.0ms ± 12.8ms 33.1x 59.0 MB / 57.9 MB
fifo 66.9ms ± 4.6ms 12986.7ms ± 122.4ms 194.0x 59.2 MB / 57.9 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 46.6ms ± 5.2ms 47.6ms ± 5.7ms +2.2% ✅ within noise 55.1 MB → 55.1 MB (-0.1%)
investment 67.9ms ± 5.1ms 67.5ms ± 4.3ms -0.6% ✅ within noise 59.1 MB → 59.0 MB (-0.1%)
fifo 63.4ms ± 3.1ms 66.9ms ± 4.6ms +5.6% 🟡 slower 61.0 MB → 59.2 MB (-3.0%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 3.4ms, investment 3.0ms, fifo 2.5ms), and is at least 5%.
10,000 transactions per shape · 20 runs, 3 warmup · hyperfine

What do these numbers mean?
  • simple — Two-posting transfers, one currency. The historical workload — keep as the floor, not as the benchmark.
  • investment — Cost specs, per-unit prices and lot reductions. Exercises booking and inventory, which simple leaves at 0.3%.
  • fifo — Bare {} reductions against a FIFO account — how FIFO sells are normally written. The other four shapes reach the ordered-selection path twice in 2k transactions between them, so it was effectively unprofiled until it turned out to be quadratic (plan_ordered scans every lot per reduction: FIFO ledgers are quadratic (8.8s at 20k transactions) #2083).
  • vs base: the PR and the base-branch commit it is built on, built and measured in the same job
  • RSS: peak resident set size, a single sample — reported without a verdict because there is no spread to test it against
  • A shape with no beancount column is one bean-check reports errors on; it is timed for rledger only

@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 170 masked)
Full AST Match 100%
Total Files 811
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
    The headline is the EFFECTIVE rate, after pairs where beanquery
    itself is wrong are masked. raw is the same run with nothing
    masked. A widening gap means the registry grew, not that rledger
    changed.
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

Self-review catch on #2181. The test was switched to `new_with_sources`
so the "no source keys" assertion could actually fail -- with a plain
`Executor::new` the location is None and `augmented_meta` is a no-op.
That fixed one gap and opened another: the plain path is what wasm and
the FFI use, and it was then covered by nothing.

Both are asserted now. All four ways to get the column wrong -- dropping
it, making it wildcard-visible, routing it through `augmented_meta`,
nulling the value -- fail the test, checked one at a time.
…data

Third review pass on #2181 found no defect; this locks in what it
checked.

The same transaction is visible through `#transactions.meta`,
`#entries.meta` and `#postings._entry_meta`. `#entries` adds
`filename`/`lineno` and the other two do not -- that split is
bean-query's and is already asserted -- but the user's own keys are one
fact and must not differ by which table you ask.

Nothing tested that. A per-table census cannot see it either: every
column involved is present in every table, so the disagreement is in the
values. That is exactly how #entries and #documents came to report
different tags for one directive (#2161).

Confirmed the assertion fails when `#entries.meta` is made to drop the
user's keys.
@robcohen
robcohen merged commit 614dc32 into main Aug 29, 2026
59 of 60 checks passed
@robcohen
robcohen deleted the fix/bql-transactions-meta branch August 29, 2026 16:00
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.

meta is missing from seven BQL tables, plus discrepancy/tolerance on #balances and links/tags on #notes

2 participants