Skip to content

fix(query): only() propagates NULL in its first argument - #1702

Merged
robcohen merged 1 commit into
mainfrom
fix/only-null-propagation
Jul 3, 2026
Merged

robcohen merged 1 commit into
mainfrom
fix/only-null-propagation

Conversation

@robcohen

@robcohen robcohen commented Jul 3, 2026

Copy link
Copy Markdown
Member

Fixes the first of the three route-smoke findings: only(NULL, inv) now returns NULL (beanquery parity) instead of type error: ONLY: first argument must be a currency string.

Root cause (from the #1699 analysis): the first-arg match sent everything non-String — including Value::Null from first(cost_currency) on costless groups — to the error branch. The second-arg match already propagated; the asymmetry was the bug. User impact fixed: fava's Holdings → by currency page 500'd on ordinary ledgers.

Regression test drives the exact Holdings expression shape (only(first(cost_currency), cost(sum(position))) over a costless group → NULL row, not an error).

The broader NULL-propagation sweep across typed scalar functions (also suggested in #1699) is left as a follow-up — this PR is the minimal user-facing fix.

Closes #1699

🤖 Generated with Claude Code

first(cost_currency) is NULL for groups without costs; beanquery propagates
NULL through only(), rustledger raised a type error — which 500'd fava's
Holdings by_currency page for any ledger with a costless commodity group
(the standard example ledger included).

The second-argument match already propagated NULL; the asymmetry was the
bug. Regression test drives the exact Holdings expression shape.

Closes #1699

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Copilot AI review requested due to automatic review settings July 3, 2026 00:14
@robcohen
robcohen requested a review from a team as a code owner July 3, 2026 00:14
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

Pull request overview

Fixes BQL only() to propagate NULL when its first argument evaluates to NULL, matching beanquery behavior and preventing Holdings-by-currency queries (e.g., fava) from failing on costless groups.

Changes:

  • Update ONLY function evaluation to return NULL when the first argument is Value::Null (instead of raising a type error).
  • Add an integration regression test that reproduces the Holdings-style expression shape where first(cost_currency) is NULL.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
crates/rustledger-query/src/executor/mod.rs Fix ONLY first-argument handling to propagate NULL for beanquery parity.
crates/rustledger-query/tests/bql_integration_test.rs Add regression test ensuring only(NULL, inventory) returns NULL (no type error).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Tool Time Memory
rustledger 36.3ms ± 3.1ms 23.6 MB
beancount 770.6ms ± 9.4ms 50.7 MB
Comparison 21.2x faster 2.1x less

vs main branch (2026-07-02)

Metric main this PR Change
Time 39.8ms 36.3ms -8.8% 🟢
10K transactions · 5 runs, 2 warmup · hyperfine
What do these numbers mean?
  • Time: Wall-clock time to parse and validate the ledger (± std dev)
  • Memory: Peak resident set size (RSS)
  • vs main: Compared to latest nightly benchmark on main branch

@github-actions

github-actions Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100%
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

@robcohen
robcohen merged commit 4db2b6e into main Jul 3, 2026
49 checks passed
@robcohen
robcohen deleted the fix/only-null-propagation branch July 3, 2026 00:48
@robcohen robcohen mentioned this pull request Jul 3, 2026
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]>
robcohen added a commit that referenced this pull request Jul 3, 2026
Closes #1699 (the remaining half — only() was fixed in #1702). Scalar
functions applied to NULL raised a type error instead of propagating,
so expressions like abs(sum(number(value(position)))) — which rustfava's
Holdings report runs on every render — failed compilation whenever the
inner aggregate yielded NULL for a group.

NULL now propagates through: YEAR, MONTH, DAY, QUARTER, UPPER, LOWER,
TRIM, ABS, LENGTH, NEG, ACCOUNT_SORTKEY, PARENT, LEAF, ROOT, ROUND, and
the second argument of FILTER_CURRENCY and POSSIGN. EMPTY keeps its
deliberate NULL -> true semantic (a missing inventory is empty). STR/
INT/DECIMAL/BOOL casts, NUMBER, CURRENCY, UNITS, COST, CONVERT, SAFEDIV
and COALESCE already handled NULL.

New integration test locks the whole scalar surface, including the
rustfava Holdings shape and second-argument propagation.
robcohen added a commit that referenced this pull request Jul 4, 2026
…1711)

* fix(query): typed scalar functions propagate NULL (beanquery parity)

Closes #1699 (the remaining half — only() was fixed in #1702). Scalar
functions applied to NULL raised a type error instead of propagating,
so expressions like abs(sum(number(value(position)))) — which rustfava's
Holdings report runs on every render — failed compilation whenever the
inner aggregate yielded NULL for a group.

NULL now propagates through: YEAR, MONTH, DAY, QUARTER, UPPER, LOWER,
TRIM, ABS, LENGTH, NEG, ACCOUNT_SORTKEY, PARENT, LEAF, ROOT, ROUND, and
the second argument of FILTER_CURRENCY and POSSIGN. EMPTY keeps its
deliberate NULL -> true semantic (a missing inventory is empty). STR/
INT/DECIMAL/BOOL casts, NUMBER, CURRENCY, UNITS, COST, CONVERT, SAFEDIV
and COALESCE already handled NULL.

New integration test locks the whole scalar surface, including the
rustfava Holdings shape and second-argument propagation.

* fix(booking): merge_with_padding is idempotent on already-merged input

Closes #1712. query-entries runs merge_with_padding on host-provided
entries; embedders (rustfava) pass load-full output, which is already
merged. Debug builds aborted on the guard (wasm trap poisoning the
component instance — how the downstream job failed on this PR); release
builds re-applied pads against an inventory already containing the
synths. Input with synth pad transactions is now returned unchanged;
the should-panic guard test became an idempotence test.

* fix(query): arithmetic operators propagate NULL

The next layer behind the scalar fix (found by the downstream job's
second pass): the Holdings expression tail is safediv(...) * 100, and
with abs(NULL) fixed the query reached 'NULL * 100' and failed with
'arithmetic requires numeric values'. NULL operands now yield NULL
(SQL/beanquery semantics), locked by tests.

* docs(test): backtick abs() in doc comment (clippy doc-markdown)

* test(query): NULL-literal cases, round() coverage, doc fix (review)

- Date/numeric NULL propagation now asserted via the NULL literal
  directly (clearer intent, decoupled from column behavior); the string
  block keeps payee to exercise the real column pipeline.
- round(NULL) was in the propagation list but untested — added.
- empty(NULL) asserted via the literal.
- Doc: payee is a transaction-level field the posting rows inherit.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 <[email protected]>
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.

query: only() type-errors on NULL first argument (beanquery propagates NULL) — Holdings by_currency 500s

2 participants