Repository navigation
fix(query): give #entries.meta its source keys, and empty meta a map - #2167
Conversation
Two divergences from bean-query, both in how metadata reaches a query. `#entries.meta` dropped `filename` and `lineno`. bean-query carries them alongside the user's keys there. `#postings` already did this via `augmented_meta`; `#entries` had the same source location in scope and did not use it. The augmentation belongs on `#entries` specifically. bean-query's per-table `meta` columns -- #notes, #balances, #events, #documents, #commodities -- exclude `filename`/`lineno`, which is verified here, so moving this into the shared conversion would break the five tables #2161 brought into agreement. A regression check confirms those five still match bean-query without the source keys while #entries has them. Second, an absent metadata block produced `Null` where bean-query produces `{}`. Those are distinguishable in bean-query -- it renders Null as an empty CSV field -- so `meta IS NULL` answered true where bean-query answers false. Not replicated: bean-query also injects `__tolerances__` into `#entries.meta`, its internal per-currency inference cache. That is an implementation detail rather than ledger content, and exposing it would put beancount's internals in user query results. Neither fix was covered: reverting either passed the whole suite before these tests. Both are confirmed to fail against their unfixed code.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Pull request overview
This PR fixes two BQL compatibility gaps with bean-query around how directive metadata is surfaced from system tables in rustledger-query.
Changes:
- Ensure
#entries.metaincludes syntheticfilename/linenokeys (without affecting per-tablemetacolumns like#notes.meta). - Change empty metadata conversion from
Nullto an empty object/map ({}) someta IS NULLmatches bean-query semantics. - Add integration tests covering both behaviors.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/rustledger-query/tests/bql_integration_test.rs | Adds regression tests for empty-metadata-as-{} and #entries.meta carrying filename/lineno. |
| crates/rustledger-query/src/executor/system_tables.rs | Augments #entries.meta using augmented_meta(...) so it carries source keys. |
| crates/rustledger-query/src/executor/mod.rs | Makes metadata_to_value return an empty object for empty metadata instead of Null. |
Suppressed comments (1)
crates/rustledger-query/tests/bql_integration_test.rs:6763
- This test asserts key presence by searching the Debug string, which is brittle (format changes can break it) and can also pass with empty placeholder values because the
SourceMaphas no file registered. Consider registering a file in theSourceMapand asserting directly on the returnedValue::Objectcontents (and specific values forfilename/lineno).
let source_map = SourceMap::new();
let mut executor = Executor::new_with_sources(&spanned, &source_map);
let result = executor
.execute(&parse("SELECT meta FROM #entries").expect("should parse"))
.expect("query should execute");
let rendered = format!("{:?}", result.rows[0][0]);
assert!(
rendered.contains("lineno"),
"#entries.meta should carry lineno, got {rendered}"
);
assert!(
rendered.contains("filename"),
"#entries.meta should carry filename, got {rendered}"
);
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
📊 Benchmark Results
vs base, measured in this run
A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: What do these numbers mean?
|
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Review catch on #2167. The empty-metadata test asserted only that the value was not Null. That would still pass if per-table `meta` picked up the synthetic `filename` / `lineno` keys -- the exact regression this change's scoping exists to prevent. It now asserts the value IS an empty map, and the #entries test inspects the map rather than a Debug string. Adds the missing test for the split itself: the same directive, through the same executor, must carry the source keys in `#entries.meta` and must not carry them in `#notes.meta`. Both directions confirmed by mutation. The first attempt at the per-table direction passed `None` as the location, which `augmented_meta` early-returns on, so it changed nothing and proved nothing; injecting the keys inside the shared `metadata_to_value` is the realistic regression shape and does fire the assertion.
What
Two ways metadata reached a query differently from bean-query.
1.
#entries.metadroppedfilenameandlinenobean-query carries them alongside the user's keys:
#postingsalready did this through the existingaugmented_metahelper.#entrieshad the sameSourceLocationin scope — it builds thefilenameand
linenocolumns from it — and simply did not use it formeta.2. Absent metadata produced
Null, not{}These are distinct values in bean-query, which renders Null as an empty CSV
field — so
meta IS NULLansweredtruefor us andfalsethere.The scoping is the load-bearing part
The augmentation goes on
#entriesonly. bean-query's per-tablemetacolumns —
#notes,#balances,#events,#documents,#commodities—exclude
filename/lineno. Moving this into the sharedmetadata_to_valuewould have broken the five tables #2161 just brought into agreement.
Verified explicitly, with a negative control so the check cannot pass
vacuously:
filename/linenoinmeta?#entriesBehaviour change worth stating
meta IS NULLnow answersfalsefor a directive with no metadata, where itanswered
truebefore. That is the point of the fix on the bean-query-facingcolumns, but it applies uniformly, including to our own hidden helper columns
_entry_meta/_posting_meta, which now report{}rather than Null for anun-annotated transaction or posting. Those have no bean-query equivalent, so
there is nothing to match there; the uniform semantic is simply the correct
one. Verified on a file with four posting rows, two annotated and two not.
Nothing outside the query crate keys off metadata being Null — the
MetaValue::Nonehandling in the FFI and core is about an individual metadatavalue, not the map.
Scope of the match
The keys are right; their order is not, and cannot be here. bean-query
emits
filename, linenofirst then declaration order; we emit alphabetical,because
metadata_to_valuecollects into aBTreeMap. That is load-bearing:Metadatais anFxHashMap, so theBTreeMapis the only thing makingSELECT metadeterministic. Declaration order is lost at parse time, so thequery layer cannot recover it. Recorded in #2168.
A user key named
filenameorlinenocorrectly wins over the injected one,matching bean-query —
augmented_metaonly fills keys that are absent.Verified.
Not replicated
bean-query also injects
__tolerances__into#entries.meta— its internalper-currency inference cache. That is an implementation detail rather than
ledger content, and mirroring it would put beancount's internals into user
query results. Same reasoning that closed #2166.
Verification
before these tests existed. Each new test is confirmed to fail against its
own unfixed code, checked separately rather than together.
re-checked on merged
mainso the fix(query): expose meta on five system tables without breaking SELECT * #2161 and fix(query): keep source order in five system tables, as bean-query does #2165 interaction is included.known 34, found 34, new 0).Closes #2162