-
Notifications
You must be signed in to change notification settings - Fork 25.6k
ESQL - KNN function uses LIMIT for setting top k #129353
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
Closed
carlosdelest
wants to merge
20
commits into
elastic:main
from
carlosdelest:non-issue/esql-knn-function-limit
Closed
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
887615c
Add limit to Knn query, set it in PushDownAndCombineLimits
carlosdelest 56d4317
First test - default limit
carlosdelest 625da5b
Add tests
carlosdelest ac0d231
Add tests
carlosdelest a6562f8
Include push down limits past sorting
carlosdelest 967a415
KNN can't be used in stats functions
carlosdelest 0e049ae
Separate push down limits to knn into its own rule class
carlosdelest f6cb5d9
Perform premapping after optimization so FTFs can be optimized before…
carlosdelest 1fe1a89
Fix tests
carlosdelest 3f16640
Merge remote-tracking branch 'origin/main' into non-issue/esql-knn-fu…
carlosdelest 67280fc
Spotless
carlosdelest 44c87cb
[CI] Auto commit changes from spotless
81f84a2
Guard knn tests with capability
carlosdelest 89d8907
LIMITs should not pass through STATS
carlosdelest 9167cab
K must be set either explicitly or implicitly
carlosdelest c5467d2
Merge remote-tracking branch 'carlosdelest/non-issue/esql-knn-functio…
carlosdelest 54e6407
Add javadoc
carlosdelest 6931643
Fix tests
carlosdelest b810ca6
[CI] Auto commit changes from spotless
6b10677
Merge branch 'main' into non-issue/esql-knn-function-limit
carlosdelest 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -181,7 +181,7 @@ public QueryBuilder queryBuilder() { | |
|
|
||
| @Override | ||
| public BiConsumer<LogicalPlan, Failures> postAnalysisPlanVerification() { | ||
| return FullTextFunction::checkFullTextQueryFunctions; | ||
| return this::checkFullTextQueryFunctions; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -190,7 +190,7 @@ public BiConsumer<LogicalPlan, Failures> postAnalysisPlanVerification() { | |
| * @param plan root plan to check | ||
| * @param failures failures found | ||
| */ | ||
| private static void checkFullTextQueryFunctions(LogicalPlan plan, Failures failures) { | ||
| private void checkFullTextQueryFunctions(LogicalPlan plan, Failures failures) { | ||
|
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. Changed visibility of these methods to allow overriding in KNN |
||
| if (plan instanceof Filter f) { | ||
| Expression condition = f.condition(); | ||
|
|
||
|
|
@@ -219,23 +219,25 @@ private static void checkFullTextQueryFunctions(LogicalPlan plan, Failures failu | |
| checkFullTextFunctionsInAggs(agg, failures); | ||
| } else { | ||
| plan.forEachExpression(FullTextFunction.class, ftf -> { | ||
| failures.add(fail(ftf, "[{}] {} is only supported in WHERE and STATS commands", ftf.functionName(), ftf.functionType())); | ||
| failures.add(fail(ftf, notSupportedErroMessage(), ftf.functionName(), ftf.functionType())); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| private static void checkFullTextFunctionsInAggs(Aggregate agg, Failures failures) { | ||
| protected void checkFullTextFunctionsInAggs(Aggregate agg, Failures failures) { | ||
| agg.groupings().forEach(exp -> { | ||
| exp.forEachDown(e -> { | ||
| if (e instanceof FullTextFunction ftf) { | ||
| failures.add( | ||
| fail(ftf, "[{}] {} is only supported in WHERE and STATS commands", ftf.functionName(), ftf.functionType()) | ||
| ); | ||
| failures.add(fail(ftf, notSupportedErroMessage(), ftf.functionName(), ftf.functionType())); | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| protected String notSupportedErroMessage() { | ||
| return "[{}] {} is only supported in WHERE and STATS commands"; | ||
| } | ||
|
|
||
| /** | ||
| * Checks all commands that exist before a specific type satisfy conditions. | ||
| * | ||
|
|
||
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.
I changed these tests to: