Skip to content

[BUG] Expressions in PPL require whitespace around * characters #720

Closed as not planned

Description

@kroepke

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?

  1. Execute the PPL query search source=opensearch_dashboards_sample_data_logs | stats avg(bytes*1024)
  2. The query fails with org.opensearch.sql.exception.SemanticCheckException: can't resolve Symbol(namespace=FIELD_NAME, name=bytes*1024) in type env
  3. Change the query to search source=opensearch_dashboards_sample_data_logs | stats avg(bytes * 1024) (note the surrounding whitespace)
  4. 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.

What is your host/environment?

  • Version 1.3, 2.1
  • Plugins SQL since 1.13.2.0 up until current

Do you have any additional context?
The change was introduced in 7dc8699#diff-fbfc17858912dc1b9fbe756efdc25267d6eb4f0f6e4b9d4fc1500d072f526892 and tests were deliberately changed to include whitespace to work around the lexer issue.
I believe this is wrong behavior, which is very difficult to understand for users.

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.

Activity

  1. added
    bug
    on Aug 2, 2022
  2. kroepke commented on Aug 2, 2022

    @kroepke
    Author

    Failing test in org.opensearch.sql.ppl.antlr.PPLSyntaxParserTest

      @Test
      public void testLiteralSwallowsExpression() {
        ParseTree tree = new PPLSyntaxParser().parse("source=foo | stats avg(bytes*1024)");
        assertNotEquals(null, tree);
        new OpenSearchPPLParserBaseVisitor<Void>(){
          @Override
          public Void visitPrimaryExpression(OpenSearchPPLParser.PrimaryExpressionContext ctx) {
            if (ctx.start.equals(ctx.stop)) {
              if (ctx.start.getText().equals("bytes*1024")) {
                fail("Expression not tokenized");
              }
            }
            return super.visitPrimaryExpression(ctx);
          }
        }.visit(tree);
      }
  3. Yury-Fridlyand commented on Aug 3, 2022

    @Yury-Fridlyand
    Collaborator

    I guess it duplicates or similar to #265

  4. kroepke commented on Aug 3, 2022

    @kroepke
    Author

    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.

  5. kroepke commented on Aug 4, 2022

    @kroepke
    Author

    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?

  6. dai-chen commented on Aug 5, 2022

    @dai-chen
    Collaborator

    @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.

  7. added
    good first issue
    PPL
    and removed on Aug 5, 2022
  8. added
    v2.5.0
    on Dec 12, 2022
  9. removed
    v2.5.0
    on Jan 6, 2023
  10. self-assigned this
    on Jun 27, 2025
  11. LantaoJin commented on Jul 21, 2025

    @LantaoJin
    Member

    @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.

  12. moved this from Not Started to Done in PPL Trackeron Jul 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

PPLbuggood first issue

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions