-
Notifications
You must be signed in to change notification settings - Fork 181
[BugFix] Fix the bug when boolean comparison condition is simplifed to field #5071
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
base: main
Are you sure you want to change the base?
[BugFix] Fix the bug when boolean comparison condition is simplifed to field #5071
Conversation
Signed-off-by: Songkan Tang <songkant@amazon.com>
📝 WalkthroughSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings. WalkthroughThis PR adds support for pushing down boolean field equality comparisons as term queries within filter predicates, enabling query optimization when filters combine boolean field conditions with other operators like query_string. Changes
Sequence DiagramsequenceDiagram
participant Client
participant PredicateAnalyzer
participant NamedFieldExpression
participant SimpleQueryExpression
participant DSLGenerator
Client->>PredicateAnalyzer: analyzeExpression(filter with boolean field)
PredicateAnalyzer->>NamedFieldExpression: isBooleanType() check
NamedFieldExpression-->>PredicateAnalyzer: true (boolean field detected)
PredicateAnalyzer->>SimpleQueryExpression: isTrue() / isFalse()
SimpleQueryExpression->>DSLGenerator: create TermQuery(field, true/false)
DSLGenerator-->>SimpleQueryExpression: TermQuery object
SimpleQueryExpression-->>PredicateAnalyzer: QueryExpression with term
PredicateAnalyzer->>DSLGenerator: combine with other filters (AND/OR)
DSLGenerator-->>PredicateAnalyzer: BoolQuery with must clauses
PredicateAnalyzer-->>Client: optimized DSL with pushed-down boolean term
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
Signed-off-by: Songkan Tang <songkant@amazon.com>
| Content-Type: 'application/json' | ||
| ppl: | ||
| body: | ||
| query: source=test-boolean | where is_internal=true | fields name |
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.
Using failed query source=test url=http | where is_internal=true
in #5054
| // Handle NOT(IS_TRUE(boolean_field)) - convert to term query with false value | ||
| // This covers cases where IS_TRUE was explicitly applied | ||
| if (expr instanceof SimpleQueryExpression simpleExpr && simpleExpr.isBooleanFieldIsTrue()) { | ||
| return QueryExpression.create(simpleExpr.rel).isFalse(); | ||
| } |
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.
- (NOT boolean_field = true) will return fields include ture, null and missing fields
- but boolean_field=false only return fields has false value.
| // generate a term query with value true. | ||
| // When called on an already-evaluated predicate (builder already set), | ||
| // return as-is. | ||
| if (builder == null) { |
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.
Is it possible to override isTrue and not API for NamedFieldExpression instead of changing SimpleQueryExpression?
Description
Fix the bug discovered in #5054. See root cause description in #5054 (comment)
Related Issues
Resolves #5054
Check List
--signoffor-s.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.