Skip to content

Fixes a bug with expressions when functions are combined with and/or operations#6669

Merged
dlvenable merged 1 commit into
opensearch-project:mainfrom
dlvenable:expressions-fix
Mar 23, 2026
Merged

Fixes a bug with expressions when functions are combined with and/or operations#6669
dlvenable merged 1 commit into
opensearch-project:mainfrom
dlvenable:expressions-fix

Conversation

@dlvenable

Copy link
Copy Markdown
Member

Description

The function composition change (#6628) converted function from a lexer rule to a parser rule, which meant function arguments became full parser sub-expressions (including conditionalExpression). The ParseTreeEvaluatorListener uses LPAREN/RPAREN tokens on the operatorSymbolStack as barriers to prevent operators from being evaluated inside nested scopes - this is how parenthesesExpression works correctly. However, the function composition code explicitly skipped LPAREN/RPAREN tokens inside functions, removing this barrier. When a multi-argument function appeared as the right operand of and/or, the AND operator sitting on the stack would fire prematurely when the walker exited the inner conditionalExpression of a function argument, consuming the function's arguments as boolean operands, silently pushing false, and leaving the function with only one argument instead of two.

The fix simply stops skipping LPAREN/RPAREN inside functions, letting them flow through to the normal handling where they act as operator stack barriers.

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.

…operations.

The function composition change (opensearch-project#6628) converted function from a lexer rule to a parser rule, which meant function arguments became full parser sub-expressions (including conditionalExpression
). The ParseTreeEvaluatorListener uses LPAREN/RPAREN tokens on the operatorSymbolStack as barriers to prevent operators from being evaluated inside nested scopes - this is how parenthesesExpression
works correctly. However, the function composition code explicitly skipped LPAREN/RPAREN tokens inside functions, removing this barrier. When a multi-argument function appeared as the right operand of and/or, the AND operator sitting on the stack would fire prematurely when the walker exited the inner conditionalExpression of a function argument, consuming the function's arguments as boolean operands, silently pushing false, and leaving the function with only one argument instead of two.

The fix simply stops skipping LPAREN/RPAREN inside functions, letting them flow through to the normal handling where they act as operator stack barriers.

Signed-off-by: David Venable <dlv@amazon.com>
@dlvenable dlvenable merged commit d47fb03 into opensearch-project:main Mar 23, 2026
70 of 72 checks passed
@dlvenable dlvenable deleted the expressions-fix branch March 24, 2026 13:41
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