Package org.apache.calcite.rex
Class RexChecker
- All Implemented Interfaces:
RexVisitor<Boolean>
Visitor which checks the validity of a
RexNode
expression.
There are two modes of operation:
- Use
fail=true
to throw anAssertionError
as soon as an invalid node is detected:
This mode requires that assertions are enabled.RexNode node;
RelDataType rowType;
assert new RexChecker(rowType, true).isValid(node); - Use
fail=false
to test for validity without throwing an error.RexNode node;
RelDataType rowType;
RexChecker checker = new RexChecker(rowType, false);
node.accept(checker);
if (!checker.valid) {
...
}
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final @Nullable RelNode.Context
protected int
protected final List<RelDataType>
protected final Litmus
Fields inherited from class org.apache.calcite.rex.RexVisitorImpl
deep
-
Constructor Summary
ConstructorsConstructorDescriptionRexChecker
(List<RelDataType> inputTypeList, @Nullable RelNode.Context context, Litmus litmus) Creates a RexChecker with a given set of input fields.RexChecker
(RelDataType inputRowType, @Nullable RelNode.Context context, Litmus litmus) Creates a RexChecker with a given input row type. -
Method Summary
Modifier and TypeMethodDescriptionint
Returns the number of failures encountered.final boolean
Returns whether an expression is valid.visitFieldAccess
(RexFieldAccess fieldAccess) visitInputRef
(RexInputRef ref) visitLocalRef
(RexLocalRef ref) Methods inherited from class org.apache.calcite.rex.RexVisitorImpl
visitArrayAnd, visitArrayOr, visitDynamicParam, visitLiteral, visitOver, visitPatternFieldRef, visitRangeRef, visitSubQuery, visitTableInputRef
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.calcite.rex.RexVisitor
visitEach, visitList, visitList
-
Field Details
-
context
-
litmus
-
inputTypeList
-
failCount
protected int failCount
-
-
Constructor Details
-
RexChecker
Creates a RexChecker with a given input row type.If
fail
is true, the checker will throw anAssertionError
if an invalid node is found and assertions are enabled.Otherwise, each method returns whether its part of the tree is valid.
- Parameters:
inputRowType
- Input row typecontext
- Context of the enclosingRelNode
, or nulllitmus
- What to do if an invalid node is detected
-
RexChecker
public RexChecker(List<RelDataType> inputTypeList, @Nullable RelNode.Context context, Litmus litmus) Creates a RexChecker with a given set of input fields.If
fail
is true, the checker will throw anAssertionError
if an invalid node is found and assertions are enabled.Otherwise, each method returns whether its part of the tree is valid.
- Parameters:
inputTypeList
- Input row typecontext
- Context of the enclosingRelNode
, or nulllitmus
- What to do if an error is detected
-
-
Method Details
-
getFailureCount
public int getFailureCount()Returns the number of failures encountered.- Returns:
- Number of failures
-
visitInputRef
- Specified by:
visitInputRef
in interfaceRexVisitor<Boolean>
- Overrides:
visitInputRef
in classRexVisitorImpl<@Nullable Boolean>
-
visitLocalRef
- Specified by:
visitLocalRef
in interfaceRexVisitor<Boolean>
- Overrides:
visitLocalRef
in classRexVisitorImpl<@Nullable Boolean>
-
visitCall
- Specified by:
visitCall
in interfaceRexVisitor<Boolean>
- Overrides:
visitCall
in classRexVisitorImpl<@Nullable Boolean>
-
visitFieldAccess
- Specified by:
visitFieldAccess
in interfaceRexVisitor<Boolean>
- Overrides:
visitFieldAccess
in classRexVisitorImpl<@Nullable Boolean>
-
visitCorrelVariable
- Specified by:
visitCorrelVariable
in interfaceRexVisitor<Boolean>
- Overrides:
visitCorrelVariable
in classRexVisitorImpl<@Nullable Boolean>
-
isValid
Returns whether an expression is valid.
-