Skip to content

[ES|QL] COMPLETION command logical plan optimizer #126763

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

Conversation

afoucret
Copy link
Contributor

The COMPLETION command is expected to be costly because it is doing an inference for each row of the dataset.

This PR tries to limit the number of rows to process by applying the same logical plan than others GeneratingPlan (Eval, Enrich, RegexExtract, ...):

  • push down and combine filters that come after the COMPLETION command when possible
  • push down and combine sort and limit that come after the COMPLETION command when possible
  • keep only the required field (push down projections)

Work for the completion command is tracked in: #124405

PS: the command is available only for snapshot build.

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Apr 14, 2025
@afoucret afoucret mentioned this pull request Apr 14, 2025
10 tasks
Copy link
Member

@carlosdelest carlosdelest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - have a question about some code being tested

@@ -238,6 +245,53 @@ public void testSelectivelyPushDownFilterPastFunctionAgg() {
assertEquals(expected, new PushDownAndCombineFilters().apply(fb));
}

// from ... | where a > 1 | COMPLETION "some prompt" WITH reranker AS completion | where b < 2 and match(completion, some text)
// => ... | where a > 1 AND b < 2| COMPLETION "some prompt" WITH reranker AS completion | match(completion, some text)
public void testPushDownFilterPastCompletion() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have missed this - is the PushDownAndCombineLimits change being tested?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some test for PushDownAndCombineLimits (it is wild but none were created for other commands)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The LogicalPlanOptimizerTests have testCombineLimits and testMultipleCombineLimits, but indeed, I don't immediately see tests for the case where there are compatible plans between the two limits. Thanks a lot for the added tests.

@afoucret afoucret requested review from a team as code owners April 16, 2025 09:17
@afoucret afoucret force-pushed the esql-completion-logical-plan-optimizer branch from ee35f39 to 4eab7d5 Compare April 16, 2025 09:18
@afoucret afoucret enabled auto-merge (squash) April 16, 2025 09:44
@afoucret afoucret merged commit e13173c into elastic:main Apr 16, 2025
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL >non-issue Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants