-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
SQL: Enable adding missing equals to bool fields as filters #66252
Conversation
This will enable QL's AnalyzerRules.AddMissingEqualsToBoolField to SQL's analyzer as well.
Pinging @elastic/es-ql (Team:QL) |
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
@@ -39,7 +40,7 @@ protected LogicalPlan rule(Filter filter) { | |||
} | |||
|
|||
private Expression replaceRawBoolFieldWithEquals(Expression e) { | |||
if (e instanceof FieldAttribute) { | |||
if (e instanceof FieldAttribute && e.dataType() == BOOLEAN) { |
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.
The rule could check whether the Filter
is resolved before applying the equality.
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.
Ah, right. Thanks, fixed.
Make sure a fields's type is available before checking it's value.
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.
So the outcome for SQL: Before all these queries below failed with exception during the query translation, while after this PR the first one will succeed.
SELECT * FROM test WHERE bool
SELECT * FROM test WHERE int
SELECT * FROM test WHERE str
That's correct. |
Check on filter's resolution part of the rule() method, before any other change is applied.
@elasticmachine update branch |
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.
Left a comment.
x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/planner/QueryTranslatorTests.java
Show resolved
Hide resolved
Add one SQL test with nested "free-floating" bool that got assigned a true literal.
…icsearch into enh/add_missing_eq_to_bool
@elasticmachine update branch |
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, thx!
This PR adds QL's
AnalyzerRules.AddMissingEqualsToBoolField
to SQL's analyser as well.Closes #65579.