Repository navigation
docs(query): record the two metadata divergences as decisions - #2172
Conversation
#2168 investigated. Both are deliberate; neither was written down where a reader would look, so both read as gaps. Metadata key order is alphabetical, not bean-query's `filename`/`lineno` first then declaration order. We can reproduce neither half: `Metadata` is an `FxHashMap`, so declaration order is lost at parse time, and `Value::Object` is a `BTreeMap`, so the query layer cannot impose an order even if it had one. Matching would mean an order-preserving map in rustledger-core -- a new dependency, rkyv support for the cache format, and a shifted `meta.hash` that rustfava pins -- to change the order keys print in. The sort is also the only thing making `SELECT meta` deterministic over a hash map, the same shape as the `#prices` ordering in #2163. bean-query lets a directive's `lineno:` metadata override its `lineno` COLUMN, because it stores the location in the dict users write to. We read the `SourceLocation` directly, so ours is immune by construction. A column named `lineno` should say where the directive is, not what someone typed. The `meta` map is the other way round -- the user's value wins, matching bean-query -- and the new test asserts both halves so neither can drift toward the other. Confirmed the test fails when the column is made to prefer metadata.
There was a problem hiding this comment.
Pull request overview
Records two deliberate BQL metadata divergences vs bean-query (alphabetical meta key order and non-shadowable lineno column) directly in the query executor code, and adds an integration test intended to pin the lineno behavior to prevent silent drift.
Changes:
- Documented why
SELECT metaemits metadata keys in deterministic alphabetical order (and why bean-query order cannot be reproduced without broader structural changes). - Documented that the
linenocolumn is sourced fromSourceLocation(not user metadata), whilemeta["lineno"]still allows the user’s value to win (bean-query-compatible). - Added an integration test to assert the non-shadowing behavior and the
metabehavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| crates/rustledger-query/tests/bql_integration_test.rs | Adds a regression test intended to pin lineno column vs meta["lineno"] shadowing behavior. |
| crates/rustledger-query/src/executor/mod.rs | Adds rationale/comments explaining deterministic alphabetical metadata key ordering for meta. |
| crates/rustledger-query/src/executor/functions/util.rs | Expands documentation for source_lineno_value to record the deliberate lineno behavior divergence. |
💡 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 |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Review catch on #2172. The test built an `Executor` from a span with `file_id: 0` against an empty `SourceMap`, so the lookup missed and the `lineno` column resolved to 0. The assertions were "an integer" and "not 999", both of which 0 satisfies -- so the test passed even with source locations entirely broken, which is the regression it exists to catch. Now it registers a real file, puts the note on line 3, and asserts `Integer(3)`. Confirmed to fail both ways: when the column is made to prefer metadata, and when the source location is dropped. The old version passed that second mutation. The metadata value is `MetaValue::Int`, not `String`. A real parse of `lineno: 999` yields a number -- `-f json` renders it unquoted -- so the fixture now matches what the parser actually produces.
Self-review catch on #2172. The comment listed "a shifted meta.hash that rustfava pins" among the costs of making `Metadata` order-preserving. That is not true. `rustledger-ffi-wasi::hash::metadata` sorts the keys itself before hashing -- precisely because `Metadata` is an `FxHashMap` and iterating it would make the digest nondeterministic -- so the hash is already independent of iteration order. I asserted it without checking, in a session spent flagging exactly that habit. The recommendation is unchanged and the two real costs are now stated precisely: `indexmap` is not a dependency today, and `Metadata` is part of the rkyv-archived cache payload with rkyv on by default, so the layout change needs a CACHE_VERSION bump.
What
#2168 raised two metadata divergences from bean-query. Both are deliberate,
but neither was written down where a reader would look, so both read as gaps.
This records them at the code and pins the one that can silently drift.
1. Metadata key order stays alphabetical
bean-query emits
filename/linenofirst, then the user's keys indeclaration order. We emit alphabetical:
We can reproduce neither half.
MetadataisFxHashMap<String, MetaValue>, so declaration order is lost at parse time; andValue::Objectis a
BTreeMap, so the query layer cannot impose an order even if it had one.Matching means an order-preserving map in
rustledger-core: a new dependency(
indexmapis not one today) and a changed rkyv layout, sinceMetadataispart of the archived cache payload and rkyv is a default feature — so a
CACHE_VERSIONbump as well. All to change the order keys print in.Correction to an earlier draft of this PR: I claimed this would also shift
meta.hash, which rustfava pins. That is wrong —rustledger-ffi-wasi::hashsorts the metadata keys itself before hashing, precisely because
Metadataisa hash map, so the digest is already independent of iteration order. The
recommendation is unchanged, but that reason was not real and I had asserted
it without checking.
The sort is also the only thing making
SELECT metadeterministic over a hashmap. Same shape as the
#pricesordering in #2163: removing it to chasebean-query would trade a stable order for an unstable one.
2.
linenometadata does not shadow thelinenocolumnbean-query stores the source location in the same dict users write to, so:
We read the
SourceLocationdirectly, so ours is immune by constructionrather than by a guard. A column named
linenoshould report where thedirective is, not what someone typed.
The
metamap is the other way round: the user's value wins there, whichdoes match bean-query, because
augmented_metaonly fills absent keys.Test
user_metadata_cannot_shadow_the_lineno_columnasserts both halves, soneither can drift toward the other — someone "fixing" this toward bean-query
would have to delete an assertion that says why not.
Confirmed to fail when the column is made to prefer metadata, which is
bean-query's behaviour.
Verification
413 tests, clippy at CI's 1.97, fmt, typos, rustdoc all clean.
Closes #2168