Class ViewResolver
InSubquery expressions (in Filter conditions) into SemiJoin/AntiJoin/
MarkJoin nodes, so a single pass fully expands the plan — including views referenced from inside IN subqueries and IN
subqueries nested in view bodies.
Resolution (see replaceViews(org.elasticsearch.xpack.esql.plan.logical.LogicalPlan, java.lang.String, java.util.function.BiFunction<java.lang.String, java.lang.String, org.elasticsearch.xpack.esql.plan.logical.LogicalPlan>, org.elasticsearch.action.ActionListener<org.elasticsearch.xpack.esql.view.ViewResolver.ViewResolutionResult>)) is a depth-first, top-down (pre-order) traversal of the plan tree. During traversal it
intercepts specific node types:
UnresolvedRelation: Resolves views and replaces them with their query plans, then recursively processes those plansFork: Recursively processes each child branchUnionAll: Skipped (assumes rewriting is already complete)AbstractSubqueryJoin: Recursively processes the left and right sidesFilter: CallsInSubqueryResolverto expand anyInSubqueryinto aSemiJoin/AntiJoin/MarkJoin, then recurses into the newly created subquery plans to resolve view references nested thereViewUnionAll: Skipped (already the result of view resolution)
View resolution may introduce new nodes that need further processing, so explicit recursive calls are made on newly resolved view
plans. The traversal tracks circular references and enforces the maximum view depth (MAX_VIEW_DEPTH_SETTING).
TODO: ViewResolver needs rename or refactor, as it does two tasks - view resolution and IN subquery resolution. Keep the core
of view resolution in ViewResolver, and have a ViewAndSubqueryResolver drive the plan tree traversal, call
ViewResolver and InSubqueryResolver to do the view and IN subquery resolution respectively.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static final recordstatic final recordResult of view resolution containing the rewritten plan, the view queries, and whether anyInSubqueryexpression was rewritten into aSemiJoin/AntiJoin/MarkJoinduring resolution. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionPublic constructor for NOOP instance (in release mode, when component is not registered, but TransportEsqlQueryAction still needs it)ViewResolver(ThreadPool threadPool, ClusterService clusterService, ProjectResolver projectResolver, Client client, CrossProjectModeDecider crossProjectModeDecider) -
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoEsqlResolveViewsRequest(EsqlResolveViewAction.Request request, ActionListener<EsqlResolveViewAction.Response> listener) voidreplaceViews(LogicalPlan plan, String projectRouting, BiFunction<String, String, LogicalPlan> parser, ActionListener<ViewResolver.ViewResolutionResult> listener) Entry point for view + IN subquery resolution; see theViewResolverclass documentation for the traversal model and the node types it intercepts.protected boolean
-
Field Details
-
log
-
MAX_VIEW_DEPTH_SETTING
-
-
Constructor Details
-
ViewResolver
public ViewResolver()Public constructor for NOOP instance (in release mode, when component is not registered, but TransportEsqlQueryAction still needs it) -
ViewResolver
public ViewResolver(ThreadPool threadPool, ClusterService clusterService, ProjectResolver projectResolver, Client client, CrossProjectModeDecider crossProjectModeDecider)
-
-
Method Details
-
viewsFeatureEnabled
protected boolean viewsFeatureEnabled() -
replaceViews
public void replaceViews(LogicalPlan plan, String projectRouting, BiFunction<String, String, LogicalPlan> parser, ActionListener<ViewResolver.ViewResolutionResult> listener) Entry point for view + IN subquery resolution; see theViewResolverclass documentation for the traversal model and the node types it intercepts. Produces aViewResolver.ViewResolutionResultcontaining the rewritten (uncompacted) plan, the map of resolved view names to their queries, and — viaViewResolver.ViewResolutionResult.hasInSubquery()— whether any IN subquery was rewritten during resolution.- Parameters:
plan- the logical plan to processparser- function to parse view query strings into logical planslistener- callback that receives theViewResolver.ViewResolutionResult
-
doEsqlResolveViewsRequest
protected void doEsqlResolveViewsRequest(EsqlResolveViewAction.Request request, ActionListener<EsqlResolveViewAction.Response> listener)
-