Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AND should have higher precedence than OR in predicate expression #771

Merged
merged 1 commit into from
Oct 11, 2024

Conversation

LantaoJin
Copy link
Member

@LantaoJin LantaoJin commented Oct 11, 2024

Description

In SQL, AND has higher precedence than OR.
Example:

SELECT *
FROM employees
WHERE department = 'HR'
   OR job_title = 'Manager'
   AND salary > 50000;

In this query, the AND between job_title = 'Manager' and salary > 50000 is evaluated first, because AND has higher precedence than OR. It equals to

WHERE department = 'HR'
   OR (job_title = 'Manager' AND salary > 50000);

But in PPL, this query will be evaluated with wrong order:

source=employees
| where department = 'HR' OR job_title = 'Manager' AND salary > 50000

was evaluated to

source=employees
| where (department = 'HR' OR job_title = 'Manager') AND salary > 50000

Issues Resolved

Resolve #770

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.

@LantaoJin LantaoJin added correctness Does not produce the expected outcome even though it doesn’t crash Lang:PPL Pipe Processing Language support 0.6 labels Oct 11, 2024
@LantaoJin LantaoJin marked this pull request as ready for review October 11, 2024 14:51
@YANG-DB YANG-DB merged commit cb813c1 into opensearch-project:main Oct 11, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.6 correctness Does not produce the expected outcome even though it doesn’t crash Lang:PPL Pipe Processing Language support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Predicates expression containing multiple AND and OR operators evaluated with wrong order
3 participants