You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Expressions in PPL require whitespace around * characters #720
What is the bug?
If a multiplication expression is written without whitespace around the operator, the lexer mistakenly tokenizes it as ID_LITERAL.
This leads to unexpected behavior (and IMHO wrong parsing) wherever multiplication is allowed.
How can one reproduce the bug?
Execute the PPL query search source=opensearch_dashboards_sample_data_logs | stats avg(bytes*1024)
The query fails with org.opensearch.sql.exception.SemanticCheckException: can't resolve Symbol(namespace=FIELD_NAME, name=bytes*1024) in type env
Change the query to search source=opensearch_dashboards_sample_data_logs | stats avg(bytes * 1024) (note the surrounding whitespace)
Run it again, the query succeeds
What is the expected behavior?
An expression should parse successfully with or without optional whitespace present, the queries above should behave identically.
If certain identifiers can contain wildcards those should be a different token, as they are not allowed everywhere where a plain ID is allowed at.
As far as I can tell from the code, the intention was to allow wildcards and other non-numeric and non-alpha characters for index names. If that's the case the grammar should reflect the two different uses and not treat them as the same token type.
Unfortunately with the way things are now it becomes essentially impossible to disambiguate in the lexer.
Looks similar, but it is a different ANTLR grammar.
I haven't checked it yet, but I doubt that SQL identifiers would contain * so I venture a guess that the underlying reason will be slightly different.
SQL identifiers can contain * (among other things that aren't operators) which will probably break a lot of SQL clients' assumptions generating code.
Unless it can be lexically determined where wildcard identifiers are allowed, this will be really tricky to fix while staying compatible.
Is the intention to only allow wildcards in index names?
@kroepke Yeah, I think so. Because OpenSearch allows * used in index expression to express search over multiple indexes which match the pattern. Probably we need separate the index name identifier and field name identifier in ANTLR grammar.
@kroepke Yeah, I think so. Because OpenSearch allows * used in index expression to express search over multiple indexes which match the pattern. Probably we need separate the index name identifier and field name identifier in ANTLR grammar.
Actually, the * can be used in field identifier too, ref #3830 (comment). Even source=t | eval a = * * * | stats max(a) should be a valid PPL (field * multiply field *). I will update documentation to call out the multiply operator must work with blanks. Close this as won't fix.
Activity
kroepke commentedon Aug 2, 2022
Failing test in
org.opensearch.sql.ppl.antlr.PPLSyntaxParserTestYury-Fridlyand commentedon Aug 3, 2022
I guess it duplicates or similar to #265
kroepke commentedon Aug 3, 2022
Looks similar, but it is a different ANTLR grammar.
I haven't checked it yet, but I doubt that SQL identifiers would contain
*so I venture a guess that the underlying reason will be slightly different.kroepke commentedon Aug 4, 2022
Crazily, I was wrong, it is a different grammar file, but the issue is identical:
0a878ab#diff-de4dc8d33192023fd968c0c467b9c242904a600e388bbc49f87e90d511ce5c41R322
SQL identifiers can contain
*(among other things that aren't operators) which will probably break a lot of SQL clients' assumptions generating code.Unless it can be lexically determined where wildcard identifiers are allowed, this will be really tricky to fix while staying compatible.
Is the intention to only allow wildcards in index names?
dai-chen commentedon Aug 5, 2022
@kroepke Yeah, I think so. Because OpenSearch allows
*used in index expression to express search over multiple indexes which match the pattern. Probably we need separate the index name identifier and field name identifier in ANTLR grammar.LantaoJin commentedon Jul 21, 2025
Actually, the
*can be used in field identifier too, ref #3830 (comment). Evensource=t | eval a = * * * | stats max(a)should be a valid PPL (field*multiply field*). I will update documentation to call out the multiply operator must work with blanks. Close this as won't fix.