Skip to content

fix(query): render boolean columns as TRUE/FALSE, like bean-query - #2182

Merged
robcohen merged 2 commits into
mainfrom
fix/bql-boolean-casing
Aug 29, 2026
Merged

robcohen merged 2 commits into
mainfrom
fix/bql-boolean-casing

Conversation

@robcohen

Copy link
Copy Markdown
Member

What

SELECT number > 0 returned true where bean-query returns TRUE, in both
CSV and the default text output. Every boolean-valued expression was affected —
comparisons, IS NULL, IN.

The failure shape is the one this whole series keeps hitting: a script written
against bean-query that tests a field for TRUE silently matches nothing.
No error, no missing column, just a comparison that never fires.

Not the one-line change it looked like

bean-query has two boolean spellings, and format_value's Object arm
recurses:

position bean-query
a boolean column TRUE / FALSE
a boolean inside a metadata map True / False (Python repr)

Uppercasing the shared Value::Boolean arm would have changed both, moving
the nested case further from bean-query than it already is. I measured that
before writing anything, which is the only reason it isn't in this diff.

format_value now applies the column rule and delegates everything else to
format_value_nested, which the set and object arms call — so the top-level
spelling cannot leak into them.

JSON

Untouched by construction: it goes through serde_json::Value::Bool, where
true is the literal and TRUE would make the document invalid. There is a
test asserting it stays a real bool, because "make it consistent" is exactly
the change someone would later make to that arm.

Verification

  • Top-level matches bean-query in both CSV and text, across comparisons,
    IS NULL and IN.
  • Nested confirmed to stay lowercase — the point being that the new rule did
    not leak, not that our map format matches bean-query's (it does not; ours
    omits the quoting).
  • Nothing covered any of this: 454 tests passed before the change and
    after it. Each of the three rules is confirmed to fail when reverted,
    including the nested one, checked separately.
  • Booked-value gate clean (known 34, found 34, new 0); corpus_parity
    divergences still exactly 20, matching main.
  • clippy at CI's 1.97, fmt, typos, rustdoc clean; 456 tests pass.

Closes #2179

`SELECT number > 0` returned `true` where bean-query returns `TRUE`, in
both CSV and the default text output. Any boolean-valued expression was
affected -- comparisons, IS NULL, IN -- and a script written against
bean-query that tests a field for `TRUE` silently matched nothing.

Not the one-line change it looked like. bean-query has TWO boolean
spellings, and `format_value`'s `Object` arm recurses:

    a boolean COLUMN          TRUE / FALSE
    a boolean INSIDE a map    True / False   (Python repr)

Uppercasing the shared arm would have changed both, moving the nested
case further from bean-query than it already is. `format_value` now
applies the column rule and delegates everything else to
`format_value_nested`, which the set and object arms call so the
top-level spelling cannot leak into them.

JSON is untouched by construction -- it goes through
`serde_json::Value::Bool`, where `true` is the literal and `TRUE` would
be invalid -- and there is now a test saying so, because that is the
mistake a later "make it consistent" change would make.

Nothing covered any of this: all 454 tests passed before the change and
after it. Each of the three rules is confirmed to fail when reverted,
including the nested one, checked separately.

Closes #2179
@robcohen
robcohen requested a review from a team as a code owner August 29, 2026 15:53
Copilot AI lite review requested due to automatic review settings August 29, 2026 15:53

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.

🟡 Changes recommended

The new tests don’t currently assert the boolean spelling in the default text output even though write_text also uses format_value, leaving the claimed behavior partially unpinned.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Adjusts rustledger’s BQL query rendering to match bean-query’s boolean casing expectations for top-level result columns, preventing silent mismatches for consumers that compare against TRUE/FALSE (issue #2179).

Changes:

  • Render Value::Boolean as TRUE / FALSE for top-level result columns.
  • Introduce format_value_nested() so booleans inside sets/objects keep their prior lowercase rendering and the top-level rule doesn’t leak.
  • Add regression tests covering CSV top-level vs nested boolean rendering and JSON bool preservation.
File summaries
File Description
crates/rustledger/src/cmd/query/output.rs Splits top-level vs nested value formatting to match bean-query’s boolean casing for result columns; adds targeted tests.
Review details
  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@codecov

codecov Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.95918% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/rustledger/src/cmd/query/output.rs 97.95% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

🔴 Slower than base on: simple

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 50.7ms ± 5.7ms 812.5ms ± 4.2ms 16.0x 55.1 MB / 50.1 MB
investment 69.6ms ± 3.0ms 3052.8ms ± 20.1ms 43.9x 59.1 MB / 58.0 MB
fifo 65.7ms ± 2.5ms 15568.0ms ± 131.0ms 236.8x 61.0 MB / 57.9 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 46.7ms ± 3.7ms 50.7ms ± 5.7ms +8.5% 🟡 slower 55.1 MB → 55.1 MB (+0.1%)
investment 68.0ms ± 2.1ms 69.6ms ± 3.0ms +2.3% ✅ within noise 59.1 MB → 59.1 MB (+0.0%)
fifo 67.5ms ± 3.9ms 65.7ms ± 2.5ms -2.6% ✅ within noise 61.1 MB → 61.0 MB (-0.1%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 3.0ms, investment 1.7ms, fifo 2.1ms), and is at least 5%.
10,000 transactions per shape · 20 runs, 3 warmup · hyperfine

What do these numbers mean?
  • simple — Two-posting transfers, one currency. The historical workload — keep as the floor, not as the benchmark.
  • investment — Cost specs, per-unit prices and lot reductions. Exercises booking and inventory, which simple leaves at 0.3%.
  • fifo — Bare {} reductions against a FIFO account — how FIFO sells are normally written. The other four shapes reach the ordered-selection path twice in 2k transactions between them, so it was effectively unprofiled until it turned out to be quadratic (plan_ordered scans every lot per reduction: FIFO ledgers are quadratic (8.8s at 20k transactions) #2083).
  • vs base: the PR and the base-branch commit it is built on, built and measured in the same job
  • RSS: peak resident set size, a single sample — reported without a verdict because there is no spread to test it against
  • A shape with no beancount column is one bean-check reports errors on; it is timed for rledger only

Review catch on #2182 from Copilot. The tests covered CSV and JSON but
not the default text output, which shares format_value -- so a later
change could keep CSV compatible and silently regress the format most
users actually see.

Confirmed the new assertion fails on a text-only regression, with the
CSV assertion still passing.
@github-actions

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 170 masked)
Full AST Match 100%
Total Files 811
What's tested
  • Check: Exit codes and error counts match bean-check
  • BQL: Query results match bean-query
    The headline is the EFFECTIVE rate, after pairs where beanquery
    itself is wrong are masked. raw is the same run with nothing
    masked. A widening gap means the registry grew, not that rledger
    changed.
  • Files: ~800 test files downloaded from 10+ beancount repositories

Full results available in workflow artifacts

@robcohen
robcohen merged commit e19668a into main Aug 29, 2026
55 checks passed
@robcohen
robcohen deleted the fix/bql-boolean-casing branch August 29, 2026 16:36
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.

BQL: booleans render as true/false; bean-query renders TRUE/FALSE

2 participants