-
Notifications
You must be signed in to change notification settings - Fork 25.6k
ESQL: text == and text != pushdown
#127355
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
Merged
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
78247a6
ESQL: Reenable `text ==` pushdown
nik9000 34048e0
Merge branch 'main' into half_pushable
nik9000 22a7c1d
Update docs/changelog/127355.yaml
nik9000 4be4318
Merge branch 'main' into half_pushable
nik9000 3442f7b
Fix test
nik9000 eeefc98
Merge remote-tracking branch 'nik9000/half_pushable' into half_pushable
nik9000 ec77a9f
Merge branch 'main' into half_pushable
nik9000 8d93564
Test and javadoc
nik9000 bb9b13a
WIP
nik9000 83f02f8
[CI] Auto commit changes from spotless
2807083
Merge branch 'main' into half_pushable
nik9000 400c00f
Spotless:
nik9000 2aea3f9
Merge remote-tracking branch 'nik9000/half_pushable' into half_pushable
nik9000 d6146fb
Fixup
nik9000 db35b76
More
nik9000 156651d
Merge branch 'main' into half_pushable
nik9000 093f89f
Merge branch 'main' into half_pushable
nik9000 cef677b
Merge branch 'main' into half_pushable
nik9000 82b4e68
Merge branch 'main' into half_pushable
nik9000 641f7c8
Fix test
nik9000 9b0f018
Merge branch 'main' into half_pushable
nik9000 3b7384e
semantic_text and match_only_text
nik9000 d9575d6
Merge remote-tracking branch 'nik9000/half_pushable' into half_pushable
nik9000 bd8d437
Merge branch 'main' into half_pushable
nik9000 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: 127355 | ||
| summary: '`text ==` and `text !=` pushdown' | ||
| 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 |
|---|---|---|
|
|
@@ -7,20 +7,34 @@ | |
|
|
||
| package org.elasticsearch.xpack.esql.capabilities; | ||
|
|
||
| import org.elasticsearch.compute.lucene.LuceneTopNSourceOperator; | ||
| import org.elasticsearch.compute.operator.FilterOperator; | ||
| import org.elasticsearch.xpack.esql.core.expression.Expression; | ||
| import org.elasticsearch.xpack.esql.core.querydsl.query.Query; | ||
| import org.elasticsearch.xpack.esql.optimizer.rules.physical.local.LucenePushdownPredicates; | ||
| import org.elasticsearch.xpack.esql.planner.TranslatorHandler; | ||
|
|
||
| /** | ||
| * Expressions implementing this interface can get called on data nodes to provide an Elasticsearch/Lucene query. | ||
| * Expressions implementing this interface are asked provide an | ||
| * Elasticsearch/Lucene query on the as part of the data node optimizations. | ||
| */ | ||
| public interface TranslationAware { | ||
| /** | ||
| * Indicates whether the expression can be translated or not. | ||
| * Usually checks whether the expression arguments are actual fields that exist in Lucene. | ||
| * Can this instance be translated or not? Usually checks whether the | ||
| * expression arguments are actual fields that exist in Lucene. See {@link Translatable} | ||
| * for precisely what can be signaled from this method. | ||
| */ | ||
| boolean translatable(LucenePushdownPredicates pushdownPredicates); | ||
| Translatable translatable(LucenePushdownPredicates pushdownPredicates); | ||
|
|
||
| /** | ||
| * Is an {@link Expression} translatable? | ||
| */ | ||
| static TranslationAware.Translatable translatable(Expression exp, LucenePushdownPredicates lucenePushdownPredicates) { | ||
| if (exp instanceof TranslationAware aware) { | ||
| return aware.translatable(lucenePushdownPredicates); | ||
| } | ||
| return TranslationAware.Translatable.NO; | ||
| } | ||
|
|
||
| /** | ||
| * Translates the implementing expression into a Query. | ||
|
|
@@ -42,4 +56,112 @@ interface SingleValueTranslationAware extends TranslationAware { | |
| */ | ||
| Expression singleValueField(); | ||
| } | ||
|
|
||
| /** | ||
| * How is this expression translatable? | ||
| */ | ||
| enum Translatable { | ||
| /** | ||
| * Not translatable at all. Calling {@link TranslationAware#asQuery} is an error. | ||
| * The expression will stay in the query plan and be filtered via a {@link FilterOperator}. | ||
| * Imagine {@code kwd == "a"} when {@code kwd} is configured without a search index. | ||
| */ | ||
| NO(FinishedTranslatable.NO), | ||
| /** | ||
| * Entirely translatable into a lucene query. Calling {@link TranslationAware#asQuery} | ||
| * will produce a query that matches all documents matching this expression and | ||
| * <strong>only</strong> documents matching this expression. Imagine {@code kwd == "a"} | ||
| * when {@code kwd} has a search index and doc values - which is the | ||
| * default configuration. This will entirely remove the clause from the | ||
| * {@code WHERE}, removing the entire {@link FilterOperator} if it's empty. Sometimes | ||
| * this allows us to push the entire top-n operation to lucene with | ||
| * a {@link LuceneTopNSourceOperator}. | ||
| */ | ||
| YES(FinishedTranslatable.YES), | ||
| /** | ||
| * Translation requires a recheck. Calling {@link TranslationAware#asQuery} will | ||
|
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. ❤️ |
||
| * produce a query that matches all documents matching this expression but might | ||
| * match more documents that do not match the expression. This will cause us to | ||
| * push a query to lucene <strong>and</strong> keep the query in the query plan, | ||
| * rechecking it via a {@link FilterOperator}. This can never push the entire | ||
| * top-n to Lucene, but it's still quite a lot better than the full scan from | ||
| * {@link #NO}. | ||
| * <p> | ||
| * Imagine {@code kwd == "a"} where {@code kwd} has a search index but doesn't | ||
| * have doc values. In that case we can find candidate matches in lucene but | ||
| * can't tell if those docs are single-valued. If they are multivalued they'll | ||
| * still match the query but won't match the expression. Thus, the double-checking. | ||
| * <strong>Technically</strong> we could just check for single-valued-ness in | ||
| * this case, but it's simpler to | ||
| * </p> | ||
| */ | ||
| RECHECK(FinishedTranslatable.RECHECK), | ||
| /** | ||
| * The same as {@link #YES}, but if this expression is negated it turns into {@link #RECHECK}. | ||
| * This comes up when pushing {@code NOT(text == "a")} to {@code text.keyword} which can | ||
| * have ignored fields. | ||
| */ | ||
| YES_BUT_RECHECK_NEGATED(FinishedTranslatable.YES); | ||
|
|
||
| private final FinishedTranslatable finish; | ||
|
|
||
| Translatable(FinishedTranslatable finish) { | ||
| this.finish = finish; | ||
| } | ||
|
|
||
| /** | ||
| * Translate into a {@link FinishedTranslatable} which never | ||
| * includes {@link #YES_BUT_RECHECK_NEGATED}. | ||
| */ | ||
| public FinishedTranslatable finish() { | ||
| return finish; | ||
| } | ||
|
|
||
| public Translatable negate() { | ||
| if (this == YES_BUT_RECHECK_NEGATED) { | ||
| return RECHECK; | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Merge two {@link TranslationAware#translatable} results. | ||
| */ | ||
| public Translatable merge(Translatable rhs) { | ||
| return switch (this) { | ||
| case NO -> NO; | ||
| case YES -> switch (rhs) { | ||
| case NO -> NO; | ||
| case YES -> YES; | ||
| case RECHECK -> RECHECK; | ||
| case YES_BUT_RECHECK_NEGATED -> YES_BUT_RECHECK_NEGATED; | ||
| }; | ||
| case RECHECK -> switch (rhs) { | ||
| case NO -> NO; | ||
| case YES, RECHECK, YES_BUT_RECHECK_NEGATED -> RECHECK; | ||
| }; | ||
| case YES_BUT_RECHECK_NEGATED -> switch (rhs) { | ||
| case NO -> NO; | ||
| case YES, YES_BUT_RECHECK_NEGATED -> YES_BUT_RECHECK_NEGATED; | ||
| case RECHECK -> RECHECK; | ||
| }; | ||
| }; | ||
| } | ||
|
|
||
| } | ||
|
|
||
| enum FinishedTranslatable { | ||
| /** | ||
| * See {@link Translatable#YES}. | ||
| */ | ||
| YES, | ||
| /** | ||
| * See {@link Translatable#NO}. | ||
| */ | ||
| NO, | ||
| /** | ||
| * See {@link Translatable#RECHECK}. | ||
| */ | ||
| RECHECK; | ||
| } | ||
| } | ||
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
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
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
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
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.
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.
on theis probably a leftover