-
Notifications
You must be signed in to change notification settings - Fork 25.2k
ESQL: introduce a pre-mapping logical plan processing step #121260
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 all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
b09553a
Add a pre-mapping logical plan processing step
bpintea cbddbc6
Update docs/changelog/120368.yaml
baec4ee
[CI] Auto commit changes from spotless
elasticsearchmachine b17f6e6
Minor listerns refactoring
bpintea 8b5d4a8
Merge branch 'main' into enh/mapping_pre_processor
bpintea 8fbd0fc
Fix wrong auto-merge
bpintea 62a5862
Have the FTFMapperPreprocessor update the plan in-place
bpintea 6040f3a
rename if'aces back
bpintea 865efe5
Merge branch 'main' into enh/mapping_pre_processor
bpintea aebbccf
[CI] Auto commit changes from spotless
elasticsearchmachine 39954c6
Drop the pre-mapping executor
bpintea 77518cd
Merge branch 'main' into enh/mapping_pre_processor2
bpintea e08fd4d
drop wrong changelog
bpintea 155acc7
Reintroduce a light premapping layer
bpintea 1df65e6
Merge branch 'main' into enh/mapping_pre_processor2
bpintea affc2e4
Merge branch 'main' into enh/mapping_pre_processor2
bpintea 04ef37d
Merge branch 'main' into enh/mapping_pre_processor2
bpintea d9a6807
Update some FTF verifications. Address review comments
bpintea fde7ea7
Merge branch 'main' into enh/mapping_pre_processor2
bpintea adada00
Update docs/changelog/121260.yaml
da8849c
Tests fixes
bpintea da56299
[ES|QL] Add aggregate metric double feature flag to its capability (#…
limotova 9993e4a
Mute org.elasticsearch.smoketest.DocsClientYamlTestSuiteIT test {yaml…
elasticsearchmachine 49071e0
ReindexDataStreamIndex bug in assertion caused by reference equality …
parkertimmins 7804f28
Mute org.elasticsearch.xpack.security.profile.ProfileIntegTests testH…
elasticsearchmachine 26a16c7
Mute org.elasticsearch.xpack.security.profile.ProfileIntegTests testA…
elasticsearchmachine 4d8fd09
Update ESRestTestCase's ROLLUP_REQUESTS_OPTIONS (#121335)
martijnvg d3ac9d8
Mute org.elasticsearch.smoketest.SmokeTestMultiNodeClientYamlTestSuit…
elasticsearchmachine 2919025
Fix propagation of dynamic mapping parameter when applying copy_to (#…
lkts 2008096
Integrate watsonx for re-ranking task (#117176)
saikatsarkar056 daddb62
revert rebasing update
bpintea 1fac8fb
Merge branch 'main' into enh/mapping_pre_processor2
bpintea 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: 121260 | ||
summary: Introduce a pre-mapping logical plan processing step | ||
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
30 changes: 0 additions & 30 deletions
30
.../qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/MockQueryBuilderResolver.java
This file was deleted.
Oops, something went wrong.
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
95 changes: 95 additions & 0 deletions
95
.../java/org/elasticsearch/xpack/esql/expression/function/fulltext/QueryBuilderResolver.java
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,95 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.esql.expression.function.fulltext; | ||
|
||
import org.elasticsearch.action.ActionListener; | ||
import org.elasticsearch.action.ResolvedIndices; | ||
import org.elasticsearch.index.query.QueryBuilder; | ||
import org.elasticsearch.index.query.QueryRewriteContext; | ||
import org.elasticsearch.index.query.Rewriteable; | ||
import org.elasticsearch.xpack.esql.core.util.Holder; | ||
import org.elasticsearch.xpack.esql.plan.logical.EsRelation; | ||
import org.elasticsearch.xpack.esql.plan.logical.LogicalPlan; | ||
import org.elasticsearch.xpack.esql.planner.TranslatorHandler; | ||
import org.elasticsearch.xpack.esql.plugin.TransportActionServices; | ||
import org.elasticsearch.xpack.esql.session.IndexResolver; | ||
|
||
import java.io.IOException; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
/** | ||
* Some {@link FullTextFunction} implementations such as {@link org.elasticsearch.xpack.esql.expression.function.fulltext.Match} | ||
* will be translated to a {@link QueryBuilder} that require a rewrite phase on the coordinator. | ||
* {@link QueryBuilderResolver#resolveQueryBuilders(LogicalPlan, TransportActionServices, ActionListener)} will rewrite the plan by | ||
* replacing {@link FullTextFunction} expression with new ones that hold rewritten {@link QueryBuilder}s. | ||
*/ | ||
public final class QueryBuilderResolver { | ||
|
||
private QueryBuilderResolver() {} | ||
|
||
public static void resolveQueryBuilders(LogicalPlan plan, TransportActionServices services, ActionListener<LogicalPlan> listener) { | ||
var hasFullTextFunctions = plan.anyMatch(p -> { | ||
Holder<Boolean> hasFullTextFunction = new Holder<>(false); | ||
p.forEachExpression(FullTextFunction.class, unused -> hasFullTextFunction.set(true)); | ||
return hasFullTextFunction.get(); | ||
}); | ||
if (hasFullTextFunctions) { | ||
Rewriteable.rewriteAndFetch( | ||
new FullTextFunctionsRewritable(plan), | ||
queryRewriteContext(services, indexNames(plan)), | ||
listener.delegateFailureAndWrap((l, r) -> l.onResponse(r.plan)) | ||
); | ||
} else { | ||
listener.onResponse(plan); | ||
} | ||
} | ||
|
||
private static QueryRewriteContext queryRewriteContext(TransportActionServices services, Set<String> indexNames) { | ||
ResolvedIndices resolvedIndices = ResolvedIndices.resolveWithIndexNamesAndOptions( | ||
indexNames.toArray(String[]::new), | ||
IndexResolver.FIELD_CAPS_INDICES_OPTIONS, | ||
services.clusterService().state(), | ||
services.indexNameExpressionResolver(), | ||
services.transportService().getRemoteClusterService(), | ||
System.currentTimeMillis() | ||
); | ||
|
||
return services.searchService().getRewriteContext(System::currentTimeMillis, resolvedIndices, null); | ||
} | ||
|
||
private static Set<String> indexNames(LogicalPlan plan) { | ||
Set<String> indexNames = new HashSet<>(); | ||
plan.forEachDown(EsRelation.class, esRelation -> indexNames.addAll(esRelation.concreteIndices())); | ||
return indexNames; | ||
} | ||
|
||
private record FullTextFunctionsRewritable(LogicalPlan plan) implements Rewriteable<QueryBuilderResolver.FullTextFunctionsRewritable> { | ||
@Override | ||
public FullTextFunctionsRewritable rewrite(QueryRewriteContext ctx) throws IOException { | ||
Holder<IOException> exceptionHolder = new Holder<>(); | ||
Holder<Boolean> updated = new Holder<>(false); | ||
LogicalPlan newPlan = plan.transformExpressionsDown(FullTextFunction.class, f -> { | ||
QueryBuilder builder = f.queryBuilder(), initial = builder; | ||
builder = builder == null ? f.asQuery(TranslatorHandler.TRANSLATOR_HANDLER).asBuilder() : builder; | ||
try { | ||
builder = builder.rewrite(ctx); | ||
} catch (IOException e) { | ||
exceptionHolder.setIfAbsent(e); | ||
} | ||
var rewritten = builder != initial; | ||
updated.set(updated.get() || rewritten); | ||
return rewritten ? f.replaceQueryBuilder(builder) : f; | ||
}); | ||
if (exceptionHolder.get() != null) { | ||
throw exceptionHolder.get(); | ||
} | ||
return updated.get() ? new FullTextFunctionsRewritable(newPlan) : this; | ||
} | ||
} | ||
} |
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.
Nit:
While this pattern (of using record) works, it's somewhat misleading - instead use a closure to encapsulate the method directly at the calling site to reference the plan:
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.
A nice proposal, but I'd like to keep it separated, just to maintain the legibility of that method (which would otherwise grow quite a bit).