Repository navigation
fix(query): accept * only as the target list and as a call's only argument - #2878
Merged
Merged
Conversation
…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]>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
📊 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?
|
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
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.
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'sSELECT *, accountextension (a*beside other targets) keeps working.targetreads a bare*before trying an expression, unless an operator, a sign,.or[follows it.function_argsreads a*alone before).*reaches the*atom inprimary_expr, which refuses it at the*with'*' is not a value: it stands only for the whole target list, or alone in a call such as count(*). This replaces the sign-only check from fix(query): report BQL syntax errors where they are, read dot-edge decimals and stacked signs, and use bean-query's postings wildcard #2865, which caught a bare signed*but not-(*)or-*.x.SELECT -*, `x`,SELECT -* FROM), that refusal is now the reported error, notunexpected token '*'.+(++6,+-6,+-*) is refused at that sign witha '+' sign takes a bare value, not another sign after it, notfound '+' expected identifier, or '*'. Signs after a+are read as a run, not recursively, so they add no nesting.+check now runs before the atom. It used to beatom.and_is(..), whose rewind dropped the*atom's error, soSELECT +*would have parsed.Why
#2871.
*was part of the parser'sprimaryexpression, so it could appear wherever an operand could.SELECT 1 + *gave blank rows,count(1 + *)gave 0, andSELECT 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:
SELECT 1 + *,SELECT 2 * *,SELECT * * 2*SELECT count(1 + *),SELECT count(*, 1)*SELECT date WHERE 1 + **SELECT (*),SELECT *.x,SELECT -(*),SELECT -*.x*SELECT date GROUP BY *,SELECT date ORDER BY **SELECT *,SELECT * FROM (SELECT *),SELECT * WHERE ...SELECT count(*),SELECT count( * )SELECT sum(*)SELECT -1 * 2,SELECT 2*3SELECT *, account,SELECT account, *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_operandchecks each refused form and its error position, including the error after a later failure.test_parse_keeps_the_wildcard_where_bean_query_takes_itchecks the accepted forms, and runsSELECT *, account,count( * ),-1 * 2and2*3.test_parse_names_a_sign_after_unary_pluschecks the sign-after-plus refusal.The existing
test_parse_refuses_a_sign_before_the_wildcardkeeps every position and now expects the new message.Checks run locally:
cargo test -p rustledger-query --all-featurescargo clippy --all-features --all-targets -- -D warningsRUSTDOCFLAGS=-Dwarnings cargo doc --workspace --no-depscargo fmt --checkCloses #2871
🤖 Generated with Claude Code