Class ViewResolver

java.lang.Object
org.elasticsearch.xpack.esql.view.ViewResolver

public class ViewResolver extends Object
Resolves view references in a logical plan by expanding each view into the plan parsed from its definition. As part of the same traversal it also rewrites 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 plans
  • Fork: Recursively processes each child branch
  • UnionAll: Skipped (assumes rewriting is already complete)
  • AbstractSubqueryJoin: Recursively processes the left and right sides
  • Filter: Calls InSubqueryResolver to expand any InSubquery into a SemiJoin/AntiJoin/ MarkJoin, then recurses into the newly created subquery plans to resolve view references nested there
  • ViewUnionAll: 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.