-
Notifications
You must be signed in to change notification settings - Fork 25k
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
[ES|QL] Add CombineBinaryComparisons rule #110548
[ES|QL] Add CombineBinaryComparisons rule #110548
Conversation
Pinging @elastic/es-analytical-engine (Team:Analytics) |
Hi @fang-xing-esql, I've created a changelog YAML for you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't believe this change is enough.
This rule you are adding (from SQL) had tests in OptimizerRulesTests
. We must add as many as possible back in ESQL.
...sql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/CombineBinaryComparisons.java
Outdated
Show resolved
Hide resolved
Thinking about this some more, I think we didn't add this rule because of multi-values fields. EQL doesn't use this rule and EQL is multi-values aware. SQL, on the other hand, is single-value enforcer and uses it. Please, look into the multi-values issue and see if this rule makes sense in this scenario. |
I'll look into multi-valued fields and migrating more tests, there must be a reason that this rule was not added for ES|QL in the first place. |
Thanks for reviewing @astefan ! More tests(from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be ok with multi-value fields, indeed. Thank you for checking.
I've left two more comments related to a better testing coverage.
...gin/esql/src/test/java/org/elasticsearch/xpack/esql/optimizer/LogicalPlanOptimizerTests.java
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks
Please, wait also for @bpintea's approval before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why discard the Range
formation? We're not having language support for smth. like BETWEEN
, but I think Range
s could very well be used internally.
Right now an ESQL query like from employees | where salary > 30000 and salary < 50000
is translated into a DSL bool
query with two distinctive range queries:
query[{"bool":{"must":[{"esql_single_value":{"field":"salary","next":{"range"
:{"salary":{"gt":30000,"boost":1.0}}},"source":"salary > 30000@5:38"}},{"esql_single_value":{"field":"salary","next":{"range":{"salary":{"lt":50000,"boost":1.0}}},"source":"salary < 50000@5:57"}}],"boost":1.
0}}
We can optimise the filter output already and potentially enable other Range-based optimisation rules.
...sql/src/main/java/org/elasticsearch/xpack/esql/optimizer/rules/CombineBinaryComparisons.java
Outdated
Show resolved
Hide resolved
That's a good point! Although BETWEEN is not supported in ES|QL yet, Range can be useful for pushing down predicates in physical plan, I'll look more into it. |
Thank you for reviewing @bpintea! As suggested, I created a separate PR #111255 to add both |
Hi @fang-xing-esql, I've updated the changelog YAML for you. |
Resolves #108525
This rule exists in sql, but not esql. After adding this rule the OR predicate in the test can be transformed into a boolean term. The sql rule is modified as ES|QL doesn't support range yet.