class ConstantExpressionVisitor extends java.lang.Object implements Visitor
This visitor replaces a
ValueNode with a node representing a
constant value, if the
ValueNode is known to always evaluate to the
same value. It may for instance replace a sub-tree representing
with a constant
The actual evaluation of the
ValueNodes is performed by invoking
ValueNode.evaluateConstantExpressions() on every
in the query tree.
In contrast to most other visitors, this visitor walks the tree bottom-up.
Top-down processing of the tree would only evaluate constant expressions
at the leaf level, so for instance
(1=1)=(1=2) would only be
TRUE=FALSE. With bottom-up processing, the top-level
= node will be processed after the leaves, and it sees the intermediate
TRUE=FALSE which it is able to transform into the even simpler
|Constructor and Description|
|Modifier and Type||Method and Description|
Method that is called to indicate whether we should skip all nodes below this node for traversal.
Method that is called to see if query tree traversal should be stopped before visiting all nodes.
Visit the node and call
Method that is called to see if
public Visitable visit(Visitable node, QueryTreeNode parent) throws StandardException
evaluateConstantExpressions()if it is a
node- the node to process
parent- the parent of the node being visited, or, more generally, the node that contains a reference to the node being visited.
StandardException- may be throw an error as needed by the visitor (i.e. may be a normal error if a particular node is found, e.g. if checking a group by, we don't expect to find any ColumnReferences that aren't under an AggregateNode -- the easiest thing to do is just throw an error when we find the questionable node).
public boolean stopTraversal()
public boolean skipChildren(Visitable node)
Differs from stopTraversal() in that it only affects subtrees, rather than the entire traversal.
public boolean visitChildrenFirst(Visitable node)
visit()should be called on the children of
nodebefore it is called on
nodeitself. If this method always returns
true, the visitor will walk the tree bottom-up. If it always returns
false, the tree is visited top-down.