Skip to content

fix(query): accept * only as the target list and as a call's only argument - #2878

Merged
robcohen merged 1 commit into
mainfrom
fix/bql-star-operand
Nov 6, 2026
Merged

robcohen merged 1 commit into
mainfrom
fix/bql-star-operand

Conversation

@robcohen

@robcohen robcohen commented Nov 6, 2026

Copy link
Copy Markdown
Member

What changed

* is accepted only where bean-query 0.2.0's grammar accepts it: as the whole target list (select: ... targets:(','.{target}+ | asterisk)) and as a call's only argument (function: fname '(' asterisk ')'). rledger's SELECT *, account extension (a * beside other targets) keeps working.

Why

#2871. * was part of the parser's primary expression, so it could appear wherever an operand could. SELECT 1 + * gave blank rows, count(1 + *) gave 0, and SELECT date WHERE 1 + * gave no rows and no error, so a typo silently gave an empty result.

Checked against bean-query 0.2.0 (rustledger-compat image), rledger before and after:

Query bean-query rledger before rledger after
SELECT 1 + *, SELECT 2 * *, SELECT * * 2 syntax error parses error at the *
SELECT count(1 + *), SELECT count(*, 1) syntax error parses error at the *
SELECT date WHERE 1 + * syntax error no rows error at the *
SELECT (*), SELECT *.x, SELECT -(*), SELECT -*.x syntax error parses error at the *
SELECT date GROUP BY *, SELECT date ORDER BY * syntax error parses error at the *
SELECT *, SELECT * FROM (SELECT *), SELECT * WHERE ... ok ok ok
SELECT count(*), SELECT count( * ) ok ok ok
SELECT sum(*) parses, then refused when compiled parses parses, as before
SELECT -1 * 2, SELECT 2*3 ok ok ok
SELECT *, account, SELECT account, * syntax error ok (extension) ok (extension)

How to test

cargo test -p rustledger-query --all-features --test bql_literals_and_wildcard_test. There are three new tests:

  • test_parse_refuses_the_wildcard_as_an_operand checks each refused form and its error position, including the error after a later failure.
  • test_parse_keeps_the_wildcard_where_bean_query_takes_it checks the accepted forms, and runs SELECT *, account, count( * ), -1 * 2 and 2*3.
  • test_parse_names_a_sign_after_unary_plus checks the sign-after-plus refusal.

The existing test_parse_refuses_a_sign_before_the_wildcard keeps every position and now expects the new message.

Checks run locally:

  • cargo test -p rustledger-query --all-features
  • cargo clippy --all-features --all-targets -- -D warnings
  • RUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-deps
  • cargo fmt --check

Closes #2871

🤖 Generated with Claude Code

…ument

BQL read `*` as an ordinary operand, so `SELECT 1 + *` gave blank rows,
`count(1 + *)` gave 0 and `SELECT date WHERE 1 + *` gave no rows and no
error, where bean-query 0.2.0 refuses each as a syntax error. Its grammar
takes `*` only as the whole target list (`select: ... targets:(target+ |
asterisk)`) and as a call's only argument (`function: fname '('
asterisk ')'`).

- `target` reads a bare `*` before an expression, unless an operator,
  `.` or `[` follows it. rledger's `SELECT *, account` extension keeps
  working.
- `function_args` reads a `*` alone before `)`.
- Any other `*` reaches the `*` atom in `primary_expr`, which refuses it
  by name at the `*` ("'*' is not a value: ..."): `1 + *`, `2 * *`,
  `count(1 + *)`, `count(*, 1)`, `WHERE 1 + *`, `(*)`, `*.x`, `-(*)`,
  `-*.x`, `GROUP BY *`, `ORDER BY *`. This replaces the sign-only check
  from #2865, which caught only a bare signed `*`.
- That refusal is reported as written when the query also fails further
  in (``SELECT -*, `x` ``, `SELECT -* FROM`), instead of "unexpected token
  '*'".
- A sign after a unary `+` (`++6`, `+-6`, `+-*`) is refused at that sign
  by name, instead of "found '+' expected identifier, or '*'". The plus
  check now runs before the atom rather than as `atom.and_is(..)`, whose
  rewind dropped the `*` atom's error, so `SELECT +*` parsed.

`-1 * 2`, `2*3`, `count(*)`, `count( * )`, `sum(*)` (parsed, then
checked like any call, as in bean-query) and `SELECT * FROM (SELECT *)`
are unchanged.

Closes #2871

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robcohen
robcohen requested a review from a team as a code owner November 6, 2026 17:11
@codecov

codecov Bot commented Nov 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

📊 Benchmark Results

Shape rustledger beancount Speedup RSS (rledger / beancount)
simple 55.9ms ± 4.2ms 676.4ms ± 7.0ms 12.1x 42.8 MB / 51.1 MB
investment 82.8ms ± 0.9ms 2484.9ms ± 12.7ms 30.0x 56.6 MB / 59.2 MB
fifo 80.2ms ± 0.7ms 13916.6ms ± 151.8ms 173.6x 54.7 MB / 58.7 MB

vs base, measured in this run

Shape base this PR Change RSS base → PR
simple 54.4ms ± 0.4ms 55.9ms ± 4.2ms +2.7% ✅ within noise 42.5 MB → 42.8 MB (+0.7%)
investment 83.2ms ± 1.0ms 82.8ms ± 0.9ms -0.6% ✅ within noise 56.7 MB → 56.6 MB (-0.2%)
fifo 80.1ms ± 2.3ms 80.2ms ± 0.7ms +0.1% ✅ within noise 55.0 MB → 54.7 MB (-0.6%)

A difference counts only when it clears the combined spread of the two measurements, per shape (2σ: simple 1.9ms, investment 0.6ms, fifo 1.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

@github-actions

github-actions Bot commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

✅ Compatibility Test Results

Metric Result
Check Compatibility 100%
BQL Compatibility 100% (raw 93%, 179 masked)
Full AST Match 100%
Total Files 826
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

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 accepts * as an operand of a binary operator (1 + *, WHERE 1 + *)

1 participant