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
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumConfiguration for rendering the string representation.Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V> -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMaximum number of lines rendered bytoString().static final intMaximum number of characters per line rendered bytoString(). -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanTraverse the plan tree from the current node to the leaves, checking the given predicate.booleanchildren()collectFirstChildren(Predicate<? super T> predicate) protected voiddoCollectFirst(Predicate<? super T> predicate, List<T> matches) boolean<E extends T>
voidforEachDown(Class<E> typeToken, Consumer<? super E> action) voidforEachDown(Consumer<? super T> action) booleanforEachDownMayReturnEarly(BiConsumer<? super T, Holder<Boolean>> action) Same as forEachDown, but can end the traverse early, by setting the boolean argument in the action.protected <E> voidforEachProperty(Class<E> typeToken, Consumer<? super E> rule) <E> voidforEachPropertyDown(Class<E> typeToken, Consumer<? super E> rule) <E> voidforEachPropertyOnly(Class<E> typeToken, Consumer<? super E> rule) <E> voidforEachPropertyUp(Class<E> typeToken, Consumer<? super E> rule) <E extends T>
voidvoidinthashCode()info()Normally, you want to use one of the staticcreatemethods to implement this.nodeName()The values of all the properties that are important to thisNode.final StringvoidnodeString(StringBuilder sb, Node.NodeStringFormat format) Append thisNode's string representation tosb.protected voidpropertiesToString(StringBuilder sb, boolean skipIfChild, Node.NodeStringFormat format) abstract TreplaceChildren(List<T> newChildren) final TreplaceChildrenSameSize(List<T> newChildren) source()toString()toString(Node.NodeStringFormat format) protected voidtransformChildren(BiConsumer<T, ActionListener<T>> traversalOperation, ActionListener<T> listener) transformChildren(Function<T, ? extends T> traversalOperation) transformDown(Class<E> typeToken, Function<E, ? extends T> rule) voidtransformDown(BiConsumer<? super T, ActionListener<T>> rule, ActionListener<T> listener) Asynchronous variant oftransformDown(Function)that allows the transformation rule to perform async I/O operations (e.g., transport actions) without blocking the caller thread.transformDown(Function<? super T, ? extends T> rule) transformDown(Predicate<Node<?>> nodePredicate, Function<E, ? extends T> rule) transformDownSkipBranch(BiFunction<? super T, Holder<Boolean>, ? extends T> rule) protected final <E> TtransformNodeProps(Class<E> typeToken, Function<? super E, ? extends E> rule) Transform this node's properties.<E> TtransformPropertiesDown(Class<E> typeToken, Function<? super E, ? extends E> rule) <E> TtransformPropertiesOnly(Class<E> typeToken, Function<? super E, ? extends E> rule) <E> TtransformPropertiesUp(Class<E> typeToken, Function<? super E, ? extends E> rule) transformUp(Class<E> typeToken, Function<E, ? extends T> rule) transformUp(Function<? super T, ? extends T> rule) transformUp(Predicate<Node<?>> nodePredicate, Function<E, ? extends T> rule) Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.elasticsearch.common.io.stream.NamedWriteable
getWriteableName
-
Field Details
-
TO_STRING_MAX_WIDTH
public static final int TO_STRING_MAX_WIDTHMaximum number of characters per line rendered bytoString().- See Also:
-
TO_STRING_MAX_LINES
public static final int TO_STRING_MAX_LINESMaximum number of lines rendered bytoString().- See Also:
-
-
Constructor Details
-
Node
-
-
Method Details
-
source
-
sourceLocation
-
sourceText
-
children
-
forEachDown
-
forEachDownMayReturnEarly
Same as forEachDown, but can end the traverse early, by setting the boolean argument in the action. -
forEachDown
-
forEachUp
-
forEachUp
-
forEachPropertyOnly
-
forEachPropertyDown
-
forEachPropertyUp
-
forEachProperty
-
anyMatch
-
allMatch
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
-
collect
-
collect
-
collectLeaves
-
collectFirstChildren
-
doCollectFirst
-
transformDown
-
transformDownSkipBranch
-
transformDown
-
transformDown
-
transformDown
Asynchronous variant oftransformDown(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
-
transformUp
-
transformUp
-
transformChildren
-
replaceChildrenSameSize
-
replaceChildren
-
transformPropertiesOnly
-
transformPropertiesDown
-
transformPropertiesUp
-
transformNodeProps
Transform this node's properties.This always returns something of the same type as the current node but since
Nodedoesn't have aSelfTparameter we return the closest thing we do have:T, which is the root of the hierarchy for this node. -
info
Normally, you want to use one of the staticcreatemethods 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 likeQueryPlan#transformExpressionsOnly(Function)will not have an effect. -
hashCode
public int hashCode() -
equals
-
nodeName
-
nodeProperties
The values of all the properties that are important to thisNode. -
nodeString
-
nodeString
- Parameters:
sb- target for the stringformat- configuration for rendering the string representation
-
toString
-
toString
-
propertiesToString
protected void propertiesToString(StringBuilder sb, boolean skipIfChild, Node.NodeStringFormat format)
-