Repository navigation
fix(query,ffi): one-arg value() is type-stable; column datatypes from first non-NULL row - #1703
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs main branch (2026-07-02)
What do these numbers mean?
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses query result type/shape mismatches that caused FFI consumers to crash (issue #1701), by making VALUE()’s 1-arg behavior type-stable over inventories and improving FFI column datatype inference so it isn’t dictated by a single (possibly NULL) first row.
Changes:
- Updated
VALUE()evaluation so the one-argument form overInventoryalways returnsInventory(type-stable across rows), while the explicit-currency form remainsAmount. - Updated the FFI component’s column datatype inference to pick the first non-NULL value per column rather than using only row 1.
- Added integration tests pinning both
VALUE(sum(position))(Inventory) andVALUE(sum(position), "USD")(Amount) contracts.
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 regression tests for VALUE() return-type stability across groups. |
| crates/rustledger-query/src/executor/mod.rs | Adjusts VALUE() market-value conversion to keep 1-arg inventory results inventory-typed. |
| crates/rustledger-ffi-component/src/convert.rs | Changes datatype inference to use the first non-NULL value per column instead of first row only. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
… first non-NULL row Two stacked defects behind #1701 (Amount-declared column carrying Inventory-shaped payloads in rustfava's Holdings route): 1. convert_to_market_value inferred the target currency PER ROW for the one-argument form (cost currency, else executor default), returning Amount when a target existed and the Inventory as-is when none did — a column type that depends on the row's data. The one-arg form over an Inventory now ALWAYS returns an Inventory (beanquery parity: value(inventory) is inventory-typed), converting per position; a position with no available price keeps its raw units, which also fixes the silent-drop inconsistency with the Position/Amount arms. The two-argument form keeps its Amount contract (explicit target is constant across the query, so it was never unstable); its pre-existing beanquery divergences are now documented at the site. 2. The component inferred each column's declared datatype from the FIRST row only — baking whichever shape row one carried into the contract the host trusts, and declaring "null" whenever row one happened to be NULL. It now infers from each column's first non-NULL value. Regression tests pin both value() contracts (one-arg Inventory for every row across costed and costless groups; two-arg Amount). Closes #1701 Co-Authored-By: Claude Opus 4.8 <[email protected]>
robcohen
force-pushed
the
fix/value-type-stability
branch
from
July 3, 2026 02:48
bb4b798 to
9accaad
Compare
Merged
robcohen
added a commit
that referenced
this pull request
Jul 3, 2026
Minor (breaking) release carrying the route-smoke fix wave (#1699/#1700/ #1701, found by rustfava's new route-smoke suite): - BREAKING parser/booking: compound cost {a # b} now carries both components and weighs N*a + b per beancount (#1700, via #1704). Ledgers that balanced under the old {a # b} == {{b}} misreading were genuinely unbalanced and now error; lot cost bases for compound specs are now correct. Binary caches invalidate automatically (CACHE_VERSION 13). - BREAKING plugin-types: CostNumberData gained the Compound variant — exhaustive matches in plugin code need a new arm (deliberate: silent mishandling of compound costs is the failure mode the exhaustive enum prevents). - FFI: WIT rustledger:ledger 3.2.0 -> 3.3.0 (additive compound case); runtime API_VERSION 3.3. Embedders regenerate bindings (rustfava#234); post-booking egress is unaffected. - query: only() propagates NULL (fava Holdings by_currency 500, #1699 via #1702); one-arg value() is inventory-typed for every row and the component declares column datatypes from the first non-NULL value (#1701, via #1703). Workspace 0.19.1 -> 0.20.0; packages/mcp-server bumped to match. Co-authored-by: Claude Opus 4.8 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the second route-smoke finding — two stacked defects (per the #1701 analysis):
1.
value()was type-unstable across rowsThe one-arg form inferred the target currency per row: Amount when a cost currency existed, the Inventory as-is when none did. Now: one-arg over Inventory → always Inventory (beanquery parity —
value(inventory)is inventory-typed), converting per position with unpriced positions kept at raw units — which also fixes the silent-drop inconsistency vs the Position/Amount arms. The two-arg form keeps its Amount contract (explicit target is constant per query, never unstable — and existing tests pinnumber(value(sum(position), \"USD\"))); its pre-existing beanquery divergences are documented at the site rather than silently changed.2. First-row datatype inference in the component
convert.rsdeclared each column's type from row 1 — baking in whichever shape that row had (and "null" when row 1 was NULL). Now: first non-NULL value per column, so no single row dictates a contract other rows contradict.Regression tests pin both contracts across costed + costless groups (the exact pre-fix instability pair).
Closes #1701
🤖 Generated with Claude Code