Repository navigation
fix(query): a table name can end a subquery or a statement - #2437
Conversation
After a table name the FROM parser required WHERE, GROUP, ORDER, HAVING, LIMIT, PIVOT or the end of input, so `FROM (SELECT account FROM #postings)` and `SELECT account FROM #postings;` failed the lookahead and backtracked to a syntax error at the outer `(` or the `#`. A `)` or `;` now ends the clause there too. The #2432 tests drop their `WHERE true` workaround. Closes #2435 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
📊 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 |
Letting a table name end a subquery or statement changed what `FROM payee;` and a subquery's `FROM payee)` meant: the parser had read those as filter expressions, only because it could not parse a table there, and now read them as a missing table. beanquery reads a bare name that no table has as the FROM filter in every spelling (`SELECT count(*) FROM payee` counts postings with a payee), where rledger's plain `FROM payee` already reported a missing table. The parser cannot tell a table from a column, so the executor decides: a name no table has is run as the FROM filter, and reported as a missing table only if it is no column either. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
Deep reviewFixed in 1e09c66: the fix changed what a bare FROM name meansWhen the table branch rejected a name, the parser fell back to the FROM-filter branch. So What beanquery does, checked with the oracle on
beanquery reads a bare name that no table has as the FROM filter, in every spelling. Main was inconsistent: without Fix. The parser can't tell a table from a column, so the executor decides. In Tests.
Disabling the fallback fails a test. Also improvedThe error for a stray Verification (1e09c66)
Second pass (c6a9799): a typo was silent on a ledger without transactions1e09c66 mapped the FROM filter's unknown-column error back to a missing table. That error only fires once a transaction is evaluated. On a ledger with none, a typo returned an empty result:
Fix. Swept against beanquery,
Verification (c6a9799).
|
…any ledger The previous commit ran a bare FROM name that no table has as the FROM filter, and mapped the filter's unknown-column error back to a missing table. That error only fires once a transaction is evaluated, so on a ledger with none a typo (`FROM nosuchthing`) returned an empty result where main and beanquery's compiler report it. Whether the name is a column is now decided before anything runs, by evaluating it as a FROM filter on a one-posting sample transaction, so the check cannot drift from what the filter resolves. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr
What
A table name can now end a subquery or a statement.
SELECT account FROM (SELECT account FROM #postings)(SELECT count(*) FROM (SELECT * FROM #accounts)SELECT x FROM (SELECT x FROM MyTable)SELECT account FROM #postings;#SELECT account FROM #postings)Why
After a table name, the
table_frombranch inparser.rsrequired a lookahead ofWHERE,GROUP,ORDER,HAVING,LIMIT,PIVOTorend(). A)closing a subquery or a;ending the statement failed that lookahead. The parser then backtracked out of the table branch and reported a syntax error at the outer(or at the#.)and;are now in the lookahead. The subquery and statement parsers already consume them.A bare FROM name that is no table is the FROM filter
Fixing the lookahead changed a second behavior, so this PR fixes that too. When the table branch rejected a name, the parser fell back to the FROM filter, so
FROM payee;and a subquery'sFROM payee)had been filters by accident. beanquery reads a bare name that no table has as the FROM filter in every spelling:SELECT count(*) FROM payeegives 2846 onexample.beancount. PlainFROM payeeon main reportedtable 'payee' does not exist. Nowexecute_select_from_tableruns such a name as the FROM filter, and reports a missing table only if the name is no column either. Whether it is a column is decided up front (is_from_filter_column, which evaluates it on a sample transaction), so a typo is reported even on a ledger with no transactions.#names and existing tables are unchanged.Tests
a_table_name_ends_a_subquery_or_statement(parser unit test) covers:);;, with and without whitespace;)staying an error.subquery_posting_values.rs) drop their eightWHERE trueworkarounds. That runs the plain form end to end through the executor.from_name_is_table_or_filter.rs: a bare column name is the filter in four spellings; a name that is neither a table nor a column is a missing table; a table of that name wins; another unknown column keeps its own error; a missing table is reported on a ledger without transactions.Checks
cargo clippy --workspace --all-features --all-targets -D warnings: clean.cargo mutants --in-diff: 7 caught, 3 unviable, 0 missed. The two lookahead entries themselves yield no mutants; the self-check covers them.Closes #2435
🤖 Generated with Claude Code
https://claude.ai/code/session_012nNGPA44Dt32NyxWem26xr