Skip to content

Fixes the typeof operator along with data types in expressions.#6673

Merged
dlvenable merged 3 commits into
opensearch-project:mainfrom
dlvenable:expression-function-fix
Mar 25, 2026
Merged

Fixes the typeof operator along with data types in expressions.#6673
dlvenable merged 3 commits into
opensearch-project:mainfrom
dlvenable:expression-function-fix

Conversation

@dlvenable

@dlvenable dlvenable commented Mar 25, 2026

Copy link
Copy Markdown
Member

Description

The function composition change (#6628) converted function from a single lexer rule (Function) that matched the entire name(args) pattern into a parser rule that referenced a new standalone lexer rule FunctionName. This FunctionName rule was defined as JsonPointerCharacters, which matches [A-Za-z0-9_.@]+.

This caused the typeof operator to stop working. This is because ANTLR was resolving our data type keywords (e.g. integer, map) as FunctionName. ANTLR did this because FunctionName came first in the grammar and is very broad. ANTLR resolves conflicts by choosing the rules defined first the grammar. So ANTLR was trying to resolve the data types as functions.

The fix is to move the FunctionName below the DataTypes. Additionally, since FunctionName is so broad, I renamed it to Identifier. This means it can be a catch all for non-keywords that may be expanded in the expression language. This name should be clearer and allow it to be re-used so we don't hit this issue again with other identifiers.

Also there were no tests for the typeof operator. I have added some of these tests, first to verify the failure and fix, and second to ensure future changes do not break them.

This PR also adds additional test cases to ensure that existing features are working as expected. It corrects incorrect assertions related to tokens from #2692 that was attempting to verify that invalid floating point values are not parsed. It also adds new tests on the grammar for functions.

Issues Resolved

N/A

Check List

  • New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

The typeof operator was not working because FunctionName came before it and it has a very broad matching rule. This means that ANTLR was resolving these as functions instead of their own tokens.

Also there were no tests for the typeof operator. I have added some of these tests, first to verify the failure and fix, and second to ensure future changes do not break them.

Signed-off-by: David Venable <dlv@amazon.com>
…ions and functionality.

Signed-off-by: David Venable <dlv@amazon.com>
@dlvenable

Copy link
Copy Markdown
Member Author

Looking at the example Java grammar for ANTLR, they clearly call out that the the identifer must show up after all keywords.

https://github.com/antlr/grammars-v4/blob/8c7185f34a6958da71c6faa2e07abe9710f3e236/java/java20/Java20Lexer.g4#L273-L275

…r future identifiers.

Signed-off-by: David Venable <dlv@amazon.com>
@dlvenable dlvenable merged commit da35804 into opensearch-project:main Mar 25, 2026
72 checks passed
@dlvenable dlvenable deleted the expression-function-fix branch March 25, 2026 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants