mrproliu opened a new pull request, #1223:
URL: https://github.com/apache/skywalking-banyandb/pull/1223

   ### Fix: a resource whose name contains `*` can be created but never queried
   
   - [x] Add a unit test to verify that the fix works.
   - [x] Explain briefly why the bug exists and how to fix it.
   
   #### Symptom
   
   A measure created as `endpoint_avg-cluster-excludes-*` accepts writes, but 
any
   read against it fails at parse time:
   
   ```
   INVALID_ARGUMENT: failed to parse query: syntax error: 1:55:
   unexpected token "*" (expected GrammarInClause GrammarStageClause?)
   ```
   
   This name is not contrived — it is what SkyWalking's TopN *exclude* rules are
   called (`bydb-topn.yml`), so every server-side TopN query against such a rule
   fails.
   
   #### Why the bug exists
   
   The write and read paths disagree on what a legal name is.
   
   Schema creation does not validate the character set of a resource name: the 
only
   name check in `api/validate/validate.go` is `validateTagName`, which rejects 
a
   single reserved character (`#`) in **tag** names. Nothing constrains measure,
   stream, trace, property or group names.
   
   The read path, however, embeds the name in text that must be lexed and 
parsed,
   and `Ident` accepted only:
   
   ```
   [a-zA-Z_][a-zA-Z0-9_-]*
   ```
   
   So BanyanDB happily creates a resource it cannot subsequently reference — a
   self-consistency gap rather than a downstream naming problem. It surfaced 
only
   recently because the typed query API carried the name as a proto string field
   that was never parsed; BydbQL turned that name from data into code.
   
   #### The fix
   
   Accept `*` as a **continuation** character, never as the first one:
   
   ```diff
   -{Name: "Ident", Pattern: `[a-zA-Z_][a-zA-Z0-9_-]*`},
   +{Name: "Ident", Pattern: `[a-zA-Z_][a-zA-Z0-9_*-]*`},
   ```
   
   #### Why `SELECT *` is unaffected
   
   Two independent reasons:
   
   1. A bare `*` does not start with `[a-zA-Z_]`, so `Ident` cannot match it 
and it
      still lexes as an operator.
   2. The grammar consumes `'*'` in exactly one place — `GrammarProjection.All`
      (`grammar.go:76`) — where it is always whitespace-separated from the
      preceding token. No valid BydbQL places an identifier directly adjacent 
to a
      `*` operator, so there is no new ambiguity.
   
   
   #### Also in this PR
   
   The BydbQL grammar reference documented `identifier ::= 
[a-zA-Z_][a-zA-Z0-9_]*`
   in five places — omitting the hyphen, which the lexer has always accepted. 
All
   five are corrected, and a new *Identifier Character Set* section states the 
rule
   and the reasoning.
   
   #### Out of scope
   
   An identifier that begins with a reserved word followed by a non-word 
character
   is rejected by the keyword rule (`IN group-a` fails on `group`). This 
predates
   this change and is unrelated to `*`; it is now documented as a caveat rather
   than fixed here.
   
   - [ ] If this pull request closes/resolves/fixes an existing issue, replace 
the issue number. Fixes apache/skywalking#<issue number>.
   - [x] Update the [`CHANGES` 
log](https://github.com/apache/skywalking-banyandb/blob/main/CHANGES.md).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to