Class Node<T extends Node<T>>

java.lang.Object
org.elasticsearch.xpack.esql.core.tree.Node<T>
Type Parameters:
T - node type
All Implemented Interfaces:
NamedWriteable, Writeable
Direct Known Subclasses:
Expression, QueryPlan

public abstract class Node<T extends Node<T>> extends Object implements NamedWriteable
Immutable tree structure. The traversal is done depth-first, pre-order (first the node then its children), that is seeks up and then goes down. Alternative method for post-order (children first, then node) is also offered, that is seeks down and then goes up. Allows transformation which returns the same tree (if no change has been performed) or a new tree otherwise. While it tries as much as possible to use functional Java, due to lack of parallelism, the use of streams and iterators is not really useful and brings too much baggage which might be used incorrectly.
  • Field Details

  • Constructor Details

  • Method Details

    • source

      public Source source()
    • sourceLocation

      public Location sourceLocation()
    • sourceText

      public String sourceText()
    • children

      public final List<T> children()
    • forEachDown

      public void forEachDown(Consumer<? super T> action)
    • forEachDownMayReturnEarly

      public boolean forEachDownMayReturnEarly(BiConsumer<? super T,Holder<Boolean>> action)
      Same as forEachDown, but can end the traverse early, by setting the boolean argument in the action.
    • forEachDown

      public <E extends T> void forEachDown(Class<E> typeToken, Consumer<? super E> action)
    • forEachUp

      public void forEachUp(Consumer<? super T> action)
    • forEachUp

      public <E extends T> void forEachUp(Class<E> typeToken, Consumer<? super E> action)
    • forEachPropertyOnly

      public <E> void forEachPropertyOnly(Class<E> typeToken, Consumer<? super E> rule)
    • forEachPropertyDown

      public <E> void forEachPropertyDown(Class<E> typeToken, Consumer<? super E> rule)
    • forEachPropertyUp

      public <E> void forEachPropertyUp(Class<E> typeToken, Consumer<? super E> rule)
    • forEachProperty

      protected <E> void forEachProperty(Class<E> typeToken, Consumer<? super E> rule)
    • anyMatch

      public boolean anyMatch(Predicate<? super T> predicate)
    • allMatch

      public boolean allMatch(Predicate<? super T> predicate)
      Traverse the plan tree from the current node to the leaves, checking the given predicate. This function will short circuit and return early if it is able to.
      Parameters:
      predicate - condition to check against all nodes
      Returns:
      true iff the given predicate is true for all nodes
    • collect

      public List<T> collect(Predicate<? super T> predicate)
    • collect

      public <E extends T> List<E> collect(Class<E> typeToken)
    • collect

      public <E extends T> List<E> collect(Class<E> typeToken, Predicate<? super E> predicate)
    • collectLeaves

      public List<T> collectLeaves()
    • collectFirstChildren

      public List<T> collectFirstChildren(Predicate<? super T> predicate)
    • doCollectFirst

      protected void doCollectFirst(Predicate<? super T> predicate, List<T> matches)
    • transformDown

      public T transformDown(Function<? super T,? extends T> rule)
    • transformDownSkipBranch

      public T transformDownSkipBranch(BiFunction<? super T,Holder<Boolean>,? extends T> rule)
    • transformDown

      public <E extends T> T transformDown(Class<E> typeToken, Function<E,? extends T> rule)
    • transformDown

      public <E extends T> T transformDown(Predicate<Node<?>> nodePredicate, Function<E,? extends T> rule)
    • transformDown

      public void transformDown(BiConsumer<? super T,ActionListener<T>> rule, ActionListener<T> listener)
      Asynchronous variant of transformDown(Function) that allows the transformation rule to perform async I/O operations (e.g., transport actions) without blocking the caller thread.

      Children are transformed sequentially, not concurrently, one after another in order. This method is intended for cases where async I/O is needed during transformation, not for parallel processing.

    • transformChildren

      protected void transformChildren(BiConsumer<T,ActionListener<T>> traversalOperation, ActionListener<T> listener)
    • transformUp

      public T transformUp(Function<? super T,? extends T> rule)
    • transformUp

      public <E extends T> T transformUp(Class<E> typeToken, Function<E,? extends T> rule)
    • transformUp

      public <E extends T> T transformUp(Predicate<Node<?>> nodePredicate, Function<E,? extends T> rule)
    • transformChildren

      protected <R extends Function<? super T, ? extends T>> T transformChildren(Function<T,? extends T> traversalOperation)
    • replaceChildrenSameSize

      public final T replaceChildrenSameSize(List<T> newChildren)
    • replaceChildren

      public abstract T replaceChildren(List<T> newChildren)
    • transformPropertiesOnly

      public <E> T transformPropertiesOnly(Class<E> typeToken, Function<? super E,? extends E> rule)
    • transformPropertiesDown

      public <E> T transformPropertiesDown(Class<E> typeToken, Function<? super E,? extends E> rule)
    • transformPropertiesUp

      public <E> T transformPropertiesUp(Class<E> typeToken, Function<? super E,? extends E> rule)
    • transformNodeProps

      protected final <E> T transformNodeProps(Class<E> typeToken, Function<? super E,? extends E> rule)
      Transform this node's properties.

      This always returns something of the same type as the current node but since Node doesn't have a SelfT parameter we return the closest thing we do have: T, which is the root of the hierarchy for this node.

    • info

      protected abstract NodeInfo<? extends T> info()
      Normally, you want to use one of the static create methods to implement this.

      For QueryPlans, it is very important that the properties contain all of the expressions and references relevant to this node, and that all the properties are used in the provided constructor; otherwise query plan transformations like QueryPlan#transformExpressionsOnly(Function) will not have an effect.

    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • nodeName

      public String nodeName()
    • nodeProperties

      public List<Object> nodeProperties()
      The values of all the properties that are important to this Node.
    • nodeString

      public final String nodeString()
      Render this Node to a String with the limited format. This does not include this node's children().
    • nodeString

      public void nodeString(StringBuilder sb, Node.NodeStringFormat format)
      Append this Node's string representation to sb. This does not include this node's children().
      Parameters:
      sb - target for the string
      format - configuration for rendering the string representation
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toString

      public String toString(Node.NodeStringFormat format)
    • propertiesToString

      protected void propertiesToString(StringBuilder sb, boolean skipIfChild, Node.NodeStringFormat format)