-
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
QL: Verify filter's condition type #66268
Conversation
This adds a check in the verifier to check if filter's condition is of a boolean type and fail the request otherwise.
Make sure a fields's type is available before checking it's value.
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.
Some minor adjustments required. Looks good otherwise.
@@ -626,6 +628,15 @@ private static boolean checkGroupMatch(Expression e, Node<?> source, List<Expres | |||
return false; | |||
} | |||
|
|||
private static void checkBooleanFiltering(LogicalPlan p, Set<Failure> localFailures) { |
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.
Filtering only works on bool hence why I recommend renaming it to checkFilterConditionType
private static void checkBooleanFiltering(LogicalPlan p, Set<Failure> localFailures) { | ||
if (p instanceof Filter) { | ||
Expression condition = ((Filter) p).condition(); | ||
if (condition.resolved() && condition.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.
No need to check if the condition is resolved, this has already been checked before - these checks get applied only if the plan is fully 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.
Right, this follows after checking against unresolved nodes (and even a comment about it!). Thanks, fixed.
if (p instanceof Filter) { | ||
Expression condition = ((Filter) p).condition(); | ||
if (condition.resolved() && condition.dataType() != BOOLEAN) { | ||
localFailures.add(fail(condition, "Cannot filter by non-boolean expression of type [{}]", condition.dataType())); |
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.
Maybe Condition expression needs to be boolean, found [{}]
. Remove the notion of filter which is not something the user declares.
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.
Changed.
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, one comment regarding testing.
@@ -326,6 +326,23 @@ Pettey | |||
Heyers | |||
; | |||
|
|||
iifConditionWhere | |||
SELECT last_name FROM test_emp WHERE IIF(LENGTH(last_name) < 7, true, false) LIMIT 10; |
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.
👍 for this test case.
What about covering the simplest case (WHERE boolField
) specifically too? The reason: the test case above gets translated into a script query, while the WHERE boolField
into a terms query, and while there are plenty of test cases that test the script
query, I don't think we have any that tests querying a bool
field directly. Note: This would require adding a new field to the test dataset with bool
type though.
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.
Yeh, I think it might make sense to add data for a new test index, with more types (like floats like bools) or extend one of the current ones. But not sure if part of this small PR. I'll open an issue to track it.
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.
Green checkmark, since my previous comment should not be a blocker.
- remove superfluous resolution check. - rename a method.
Move checkFilterConditionType() into it's own QL class, VerifierChecks.
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
As @costin pointed out, this check should be extended to EQL as well, so the last commit does that. The CI should fail until #66252 is merged in though, since with #65325 in place, an |
@elasticmachine update branch |
Remove now obsolete test.
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 2.
* Verify filter's condition type This adds a check in the verifier to check if filter's condition is of a boolean type and fail the request otherwise. (cherry picked from commit 3aec1a3)
* Verify filter's condition type This adds a check in the verifier to check if filter's condition is of a boolean type and fail the request otherwise. (cherry picked from commit 3aec1a3)
This adds a check in the verifier to check if filter's condition is of a
boolean type and fail the request otherwise.
Closes #66254.