generated from amazon-archives/__template_Custom
-
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
Open
songkant-aws
wants to merge
14
commits into
opensearch-project:main
Choose a base branch
from
songkant-aws:boolean-comparison-expression-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+487
−37
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2bea19d
Fix the bug when boolean comparison condition is simplifed to field
songkant-aws ab77f1e
Update tests and cover more cases
songkant-aws 875b350
Correct the logic of not boolean comparison
songkant-aws bbf328c
Add missing IS_FALSE RexNode translation
songkant-aws 9def64e
Remove unnecessary boolean expression conversion
songkant-aws 835dc3e
Fix spotless check
songkant-aws 6beaf9a
Merge branch 'main' into boolean-comparison-expression-fix
songkant-aws c7170e9
Refactor PredicateAnalyzer logic a bit
songkant-aws d75eb51
Add more strict not expression match for field
songkant-aws ea36c6b
Fix spotless check and flaky test
songkant-aws 6497cf3
Cover more cases for IS_FALSE, IS_NOT_TRUE, IS_NOT_FALSE
songkant-aws 20ac08c
Complement the truth tests for expressions
songkant-aws 108a465
Fix logic
songkant-aws 8a7d3df
Fix spotless check
songkant-aws File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...t/src/test/resources/expectedOutput/calcite/explain_filter_query_string_with_boolean.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| calcite: | ||
| logical: | | ||
| LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT]) | ||
| LogicalProject(firstname=[$1]) | ||
| LogicalFilter(condition=[$12]) | ||
| LogicalFilter(condition=[query_string(MAP('query', 'firstname:Amber':VARCHAR))]) | ||
| CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_bank]]) | ||
| physical: | | ||
| CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_bank]], PushDownContext=[[PROJECT->[firstname, male], FILTER->AND(query_string(MAP('query', 'firstname:Amber':VARCHAR)), $1), PROJECT->[firstname], LIMIT->10000], OpenSearchRequestBuilder(sourceBuilder={"from":0,"size":10000,"timeout":"1m","query":{"bool":{"must":[{"query_string":{"query":"firstname:Amber","fields":[],"type":"best_fields","default_operator":"or","max_determinized_states":10000,"enable_position_increments":true,"fuzziness":"AUTO","fuzzy_prefix_length":0,"fuzzy_max_expansions":50,"phrase_slop":0,"escape":false,"auto_generate_synonyms_phrase_query":true,"fuzzy_transpositions":true,"boost":1.0}},{"term":{"male":{"value":true,"boost":1.0}}}],"adjust_pure_negative":true,"boost":1.0}},"_source":{"includes":["firstname"],"excludes":[]}}, requestedTotalSize=10000, pageSize=null, startFrom=0)]) |
9 changes: 9 additions & 0 deletions
9
...test/resources/expectedOutput/calcite/explain_filter_query_string_with_boolean_false.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| calcite: | ||
| logical: | | ||
| LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT]) | ||
| LogicalProject(firstname=[$1]) | ||
| LogicalFilter(condition=[NOT($12)]) | ||
| LogicalFilter(condition=[query_string(MAP('query', 'firstname:Amber':VARCHAR))]) | ||
| CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_bank]]) | ||
| physical: | | ||
| CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_bank]], PushDownContext=[[PROJECT->[firstname, male], FILTER->AND(query_string(MAP('query', 'firstname:Amber':VARCHAR)), NOT($1)), PROJECT->[firstname], LIMIT->10000], OpenSearchRequestBuilder(sourceBuilder={"from":0,"size":10000,"timeout":"1m","query":{"bool":{"must":[{"query_string":{"query":"firstname:Amber","fields":[],"type":"best_fields","default_operator":"or","max_determinized_states":10000,"enable_position_increments":true,"fuzziness":"AUTO","fuzzy_prefix_length":0,"fuzzy_max_expansions":50,"phrase_slop":0,"escape":false,"auto_generate_synonyms_phrase_query":true,"fuzzy_transpositions":true,"boost":1.0}},{"term":{"male":{"value":false,"boost":1.0}}}],"adjust_pure_negative":true,"boost":1.0}},"_source":{"includes":["firstname"],"excludes":[]}}, requestedTotalSize=10000, pageSize=null, startFrom=0)]) |
9 changes: 9 additions & 0 deletions
9
...t/resources/expectedOutput/calcite/explain_filter_query_string_with_boolean_not_true.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| calcite: | ||
| logical: | | ||
| LogicalSystemLimit(fetch=[10000], type=[QUERY_SIZE_LIMIT]) | ||
| LogicalProject(firstname=[$1]) | ||
| LogicalFilter(condition=[IS NOT TRUE($12)]) | ||
| LogicalFilter(condition=[query_string(MAP('query', 'firstname:Amber':VARCHAR))]) | ||
| CalciteLogicalIndexScan(table=[[OpenSearch, opensearch-sql_test_index_bank]]) | ||
| physical: | | ||
| CalciteEnumerableIndexScan(table=[[OpenSearch, opensearch-sql_test_index_bank]], PushDownContext=[[PROJECT->[firstname, male], FILTER->AND(query_string(MAP('query', 'firstname:Amber':VARCHAR)), IS NOT TRUE($1)), PROJECT->[firstname], LIMIT->10000], OpenSearchRequestBuilder(sourceBuilder={"from":0,"size":10000,"timeout":"1m","query":{"bool":{"must":[{"query_string":{"query":"firstname:Amber","fields":[],"type":"best_fields","default_operator":"or","max_determinized_states":10000,"enable_position_increments":true,"fuzziness":"AUTO","fuzzy_prefix_length":0,"fuzzy_max_expansions":50,"phrase_slop":0,"escape":false,"auto_generate_synonyms_phrase_query":true,"fuzzy_transpositions":true,"boost":1.0}},{"bool":{"must_not":[{"term":{"male":{"value":true,"boost":1.0}}}],"adjust_pure_negative":true,"boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}},"_source":{"includes":["firstname"],"excludes":[]}}, requestedTotalSize=10000, pageSize=null, startFrom=0)]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
integ-test/src/yamlRestTest/resources/rest-api-spec/test/issues/5054.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| setup: | ||
| - do: | ||
| query.settings: | ||
| body: | ||
| transient: | ||
| plugins.calcite.enabled: true | ||
|
|
||
| --- | ||
| teardown: | ||
| - do: | ||
| query.settings: | ||
| body: | ||
| transient: | ||
| plugins.calcite.enabled: false | ||
|
|
||
| --- | ||
| "Fix boolean field comparison pushdown": | ||
| - skip: | ||
| features: | ||
| - headers | ||
| - allowed_warnings | ||
| - do: | ||
| indices.create: | ||
| index: test | ||
| body: | ||
| mappings: | ||
| properties: | ||
| "@timestamp": | ||
| type: date | ||
| url: | ||
| type: text | ||
| is_internal: | ||
| type: boolean | ||
|
|
||
|
|
||
| - do: | ||
| bulk: | ||
| index: test | ||
| refresh: true | ||
| body: | ||
| - '{"index": {}}' | ||
| - '{ "@timestamp":"2025-08-19T04:51:24Z", "url": "http" }' | ||
| - '{"index": {}}' | ||
| - '{ "@timestamp":"2025-08-19T04:51:24Z", "url": "http", "is_internal": true }' | ||
| - '{"index": {}}' | ||
| - '{ "@timestamp":"2025-08-19T04:51:24Z", "url": "http", "is_internal": false }' | ||
|
|
||
| # Test is_internal=true: should return only documents where is_internal is explicitly true | ||
| - do: | ||
| allowed_warnings: | ||
| - 'Loading the fielddata on the _id field is deprecated and will be removed in future versions. If you require sorting or aggregating on this field you should also include the id in the body of your documents, and map this field as a keyword field that has [doc_values] enabled' | ||
| headers: | ||
| Content-Type: 'application/json' | ||
| ppl: | ||
| body: | ||
| query: source=test url=http | where is_internal=true | ||
|
|
||
| - match: { total: 1 } | ||
| - length: { datarows: 1 } | ||
|
|
||
| # Test is_internal=false: should return only documents where is_internal is explicitly false | ||
| # NOT documents where is_internal is null or missing | ||
| - do: | ||
| allowed_warnings: | ||
| - 'Loading the fielddata on the _id field is deprecated and will be removed in future versions. If you require sorting or aggregating on this field you should also include the id in the body of your documents, and map this field as a keyword field that has [doc_values] enabled' | ||
| headers: | ||
| Content-Type: 'application/json' | ||
| ppl: | ||
| body: | ||
| query: source=test url=http | where is_internal=false | ||
|
|
||
| - match: { total: 1 } | ||
| - length: { datarows: 1 } | ||
|
|
||
| # Test NOT(is_internal=false): should return documents where is_internal is true OR null/missing | ||
| # This is the negation of "is_internal=false", so it should return 2 documents | ||
| - do: | ||
| allowed_warnings: | ||
| - 'Loading the fielddata on the _id field is deprecated and will be removed in future versions. If you require sorting or aggregating on this field you should also include the id in the body of your documents, and map this field as a keyword field that has [doc_values] enabled' | ||
| headers: | ||
| Content-Type: 'application/json' | ||
| ppl: | ||
| body: | ||
| query: source=test url=http | where not is_internal=false | ||
|
|
||
| - match: { total: 2 } | ||
| - length: { datarows: 2 } | ||
|
|
||
| # Test NOT(is_internal=true): should return documents where is_internal is false OR null/missing | ||
| # This is the negation of "is_internal=true", so it should return 2 documents | ||
| - do: | ||
| allowed_warnings: | ||
| - 'Loading the fielddata on the _id field is deprecated and will be removed in future versions. If you require sorting or aggregating on this field you should also include the id in the body of your documents, and map this field as a keyword field that has [doc_values] enabled' | ||
| headers: | ||
| Content-Type: 'application/json' | ||
| ppl: | ||
| body: | ||
| query: source=test url=http | where not is_internal=true | ||
|
|
||
| - match: { total: 2 } | ||
| - length: { datarows: 2 } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Ensure index isolation by cleaning up
testbefore/after use.Right now the test can fail or leak state if an index named
testalready exists or is reused. Add a cleanup step (or use a unique index name) to keep this test independent.🧹 Suggested cleanup (align with existing YAML REST test patterns)
setup: - do: query.settings: body: transient: plugins.calcite.enabled: true + - do: + indices.delete: + index: test + ignore: 404 --- teardown: - do: query.settings: body: transient: plugins.calcite.enabled: false + - do: + indices.delete: + index: test + ignore: 404As per coding guidelines: Tests must not rely on execution order; ensure test independence.
Also applies to: 23-34
🤖 Prompt for AI Agents