-
Notifications
You must be signed in to change notification settings - Fork 25.6k
ES|QL: add local optimizations for constant_keyword #127549
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
Merged
luigidellaquila
merged 14 commits into
elastic:main
from
luigidellaquila:esql/constant_keyword_optimizations
May 22, 2025
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
53f6aef
ES|QL: add local optimizations for constant_keyword
luigidellaquila 9f3beb1
Simplify
luigidellaquila 3ee8771
Merge branch 'main' into esql/constant_keyword_optimizations
luigidellaquila 80df1b6
Merge branch 'main' into esql/constant_keyword_optimizations
luigidellaquila 5c91551
Merge branch 'main' into esql/constant_keyword_optimizations
luigidellaquila 0df9c68
Update docs/changelog/127549.yaml
luigidellaquila 7ed3546
Fix cases with mix of constant_keyword and other types
luigidellaquila 54bdcce
Merge remote-tracking branch 'luigidellaquila/esql/constant_keyword_o…
luigidellaquila 23dc016
More tests
luigidellaquila be6605a
Merge branch 'main' into esql/constant_keyword_optimizations
luigidellaquila 76bd083
Merge branch 'main' into esql/constant_keyword_optimizations
luigidellaquila 3a52b87
Unify ReplaceMissingFieldWithNull and ReplaceConstantKeyword in a sin…
luigidellaquila 847065c
Merge branch 'main' into esql/constant_keyword_optimizations
luigidellaquila f6a6176
Implement review suggestions
luigidellaquila 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 127549 | ||
| summary: Add local optimizations for `constant_keyword` | ||
| area: ES|QL | ||
| type: enhancement | ||
| issues: [] |
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
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 |
|---|---|---|
|
|
@@ -310,6 +310,41 @@ public boolean canUseEqualityOnSyntheticSourceDelegate(String name, String value | |
| return true; | ||
| } | ||
|
|
||
| public String constantValue(String name) { | ||
| String val = null; | ||
| for (SearchExecutionContext ctx : contexts) { | ||
| MappedFieldType f = ctx.getFieldType(name); | ||
| if (f == null) { | ||
| return null; | ||
| } | ||
| if (f instanceof ConstantFieldType cf) { | ||
| var fetcher = cf.valueFetcher(ctx, null); | ||
| String thisVal = null; | ||
| try { | ||
| // since the value is a constant, the doc _should_ be irrelevant | ||
| List<Object> vals = fetcher.fetchValues(null, -1, null); | ||
| Object objVal = vals.size() == 1 ? vals.get(0) : null; | ||
| // we are considering only string values for now, since this can return "strange" things, | ||
| // see IndexModeFieldType | ||
| thisVal = objVal instanceof String ? (String) objVal : null; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe we tend to use |
||
| } catch (IOException iox) {} | ||
|
|
||
| if (thisVal == null) { | ||
| // Value not yet set | ||
| return null; | ||
| } | ||
| if (val == null) { | ||
| val = thisVal; | ||
| } else if (thisVal.equals(val) == false) { | ||
| return null; | ||
| } | ||
| } else { | ||
| return null; | ||
| } | ||
| } | ||
| return val; | ||
| } | ||
|
|
||
| private interface DocCountTester { | ||
| Boolean test(LeafReader leafReader) throws IOException; | ||
| } | ||
|
|
||
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
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.
Uh oh!
There was an error while loading. Please reload this page.