Repository navigation
fix(query): expose filename/lineno as synthetic metadata keys - #1511
Conversation
beanquery injects filename/lineno into every posting/entry meta dict; rledger keeps source location in spans. Synthesize the two keys at the BQL boundary via one shared, scope-aware view (meta_lookup / augmented_meta), routed through META/ POSTING_META/ANY_META (posting scope), ENTRY_META (entry scope), and the meta column on both the default and #postings paths. getitem rides on the column value. User keys win. Found via BQL dogfooding. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
📊 Benchmark Results
vs main branch (2026-06-22)
What do these numbers mean?
|
There was a problem hiding this comment.
Pull request overview
This PR updates rustledger-query’s BQL executor to expose beanquery-compatible filename/lineno as synthetic metadata keys (in addition to the existing dedicated columns), so SELECT meta, meta('filename') / meta('lineno'), and getitem(meta, ...) can see source location even when the user didn’t define any metadata.
Changes:
- Materialize an augmented
metadictionary that includes syntheticfilename/linenokeys derived from resolved source locations (user keys still take precedence). - Route
META/POSTING_META/ENTRY_META/ANY_METAthrough a shared lookup path that can synthesize the source-location keys. - Add an executor test covering per-posting synthetic metadata and
getitem(meta, ...)behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/rustledger-query/src/executor/mod.rs | Augments the #postings table’s meta column and adds tests for synthetic source-location metadata. |
| crates/rustledger-query/src/executor/functions/util.rs | Adds shared helpers to synthesize and look up filename/lineno metadata keys by scope/location. |
| crates/rustledger-query/src/executor/evaluation.rs | Ensures the default-row meta column is augmented using the resolved posting location. |
Comments suppressed due to low confidence (1)
crates/rustledger-query/src/executor/mod.rs:2763
- In the #postings table path, META/ENTRY_META/ANY_META functions read from the hidden
_posting_meta/_entry_metacolumns (seeeval_meta_on_table_row), but those columns are still built from the raw metadata maps. This meansmeta('filename')/meta('lineno')will still return NULL when queryingFROM #postings, even though themetacolumn itself is now augmented (split-brain betweenmeta()andgetitem(meta, ...)). To keep all metadata accessors consistent, augment the hidden meta columns with the same syntheticfilename/linenokeys (scoped to posting vs entry location).
// Hidden metadata columns
Self::metadata_to_value(&txn.meta),
Self::metadata_to_value(&posting.meta),
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // The full meta column is augmented; getitem over it (and via #postings) | ||
| // sees the synthetic keys. | ||
| let r = executor | ||
| .execute(&parse("SELECT getitem(meta, 'lineno') FROM #postings").unwrap()) | ||
| .unwrap(); | ||
| assert_eq!(r.rows[0][0], Value::Number(dec!(2))); | ||
| assert_eq!(r.rows[1][0], Value::Number(dec!(3))); |
|
| 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
* feat(core): add MetaValue::Int(i64) variant (lineno -> Integer) Add a first-class integer MetaValue. PR 1/2: variant + all match/wire arms + cache version bump + synthetic BQL lineno uses Int; parser change is PR 2. Resolves the Number-vs-Integer inconsistency from #1511 (#5b): meta(lineno) / getitem(meta,lineno) are now true integers matching the lineno column. Co-Authored-By: Claude Opus 4.8 <[email protected]> * docs(loader): point CostNumber version-bump note at v12 Copilot on #1513: CACHE_VERSION is now 11, so the changelog hint should reference the next bump (v12). Co-Authored-By: Claude Opus 4.8 <[email protected]> --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
What
The
metacolumn rendered{}for postings with no user metadata and omitted beanquery'sfilename/linenokeys;meta('filename')/meta('lineno')andgetitem(meta, …)couldn't see them either. beanquery's parser injectsfilename/linenointo every posting's/entry's metadata, soSELECT metashows{'filename': …, 'lineno': N}.Found in round-4 BQL dogfounding (#5b). Builds on the per-posting source-location resolution from #1510.
Design (why it's a shared view, not a 2-site patch)
rledger deliberately keeps source location in spans (
file_id+ offset), not in the meta map (beancount's per-entry filename-string model is exactly the memory cost rledger avoids). Sofilename/lineno-in-meta is a compatibility view synthesized at the BQL boundary, from a single resolver — not injected at load time, and not patched ad-hoc at eachValue::Metadatasite (which would leavemetathe column augmented butmeta()/entry_meta()reading raw maps — a split-brain).One shared helper set, scope-aware:
source_location_meta_key(loc, key)→ the syntheticfilename/linenofor a location.meta_lookup(raw, loc, key)— single-key access; user keys win (raw map consulted first).augmented_meta(raw, loc)— materializes the fullmetacolumn (user keys win).Routed through every accessor with the correct scope:
META/POSTING_META/ANY_META→ posting location (the posting's own line).ENTRY_META→ the entry/directive location (the transaction's line).metacolumn (default path and#postings) →augmented_meta.getitem(meta, …)rides on the (now augmented) column value — no separate change.All derive from #1510's single location resolver, so values agree with the
filename/linenocolumns.Notes / deliberate choices
linenovia the meta surface is aNumber(there is no integerMetaValue); the dedicatedlinenocolumn staysInteger.Number(Decimal)renders4and compares numerically — beanquery-compatible.filename/linenokeys take precedence (raw map first).Tests
test_meta_includes_source_location:meta('filename')/meta('lineno')per-posting;entry_meta('lineno')= entry line (scope); user key wins;getitem(meta,'lineno')augmented over#postings. Values verified against bean-query'sSELECT meta. Fullrustledger-querysuite passes; clippy + fmt clean.🤖 Generated with Claude Code