Class ReduceExpressionsRule<C extends ReduceExpressionsRule.Config>
- Type Parameters:
C- Configuration type
- All Implemented Interfaces:
SubstitutionRule,TransformationRule
- Direct Known Subclasses:
ReduceExpressionsRule.CalcReduceExpressionsRule,ReduceExpressionsRule.FilterReduceExpressionsRule,ReduceExpressionsRule.JoinReduceExpressionsRule,ReduceExpressionsRule.ProjectReduceExpressionsRule,ReduceExpressionsRule.WindowReduceExpressionsRule
- Constant reduction, which evaluates constant subtrees, replacing them with a corresponding RexLiteral
- Removal of redundant casts, which occurs when the argument into the cast is the same as the type of the resulting cast expression
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRule that reduces constants inside aCalc.protected static classShuttle that pushes predicates into a CASE.static interfaceRule configuration.static classRule that reduces constants inside aFilter.static classRule that reduces constants inside aJoin.static classRule that reduces constants inside aProject.protected static classHelper class used to locate expressions that either can be reduced to literals or contain redundant casts.protected static classReplaces expressions with their reductions.static classRule that reduces constants inside aWindow.Nested classes/interfaces inherited from class org.apache.calcite.plan.RelRule
RelRule.Done, RelRule.MatchHandler<R extends RelOptRule>, RelRule.OperandBuilder, RelRule.OperandDetailBuilder<R extends RelNode>, RelRule.OperandTransformNested classes/interfaces inherited from class org.apache.calcite.plan.RelOptRule
RelOptRule.ConverterRelOptRuleOperand -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final PatternRegular expression that matches the description of all instances of this rule andValuesReduceRulealso.Fields inherited from class org.apache.calcite.plan.RelOptRule
description, operands, relBuilderFactory -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedReduceExpressionsRule(C config) Creates a ReduceExpressionsRule. -
Method Summary
Modifier and TypeMethodDescriptionprotected static voidfindReducibleExps(RelDataTypeFactory typeFactory, List<RexNode> exps, com.google.common.collect.ImmutableMap<RexNode, RexNode> constants, List<RexNode> constExps, List<Boolean> addCasts, boolean treatDynamicCallsAsConstant) Locates expressions that can be reduced to literals or converted to expressions with redundant casts removed.predicateConstants(Class<C> clazz, RexBuilder rexBuilder, RelOptPredicateList predicates) Deprecated.static RexCallpushPredicateIntoCase(RexCall call) Pushes predicates into a CASE.protected static booleanreduceExpressions(RelNode rel, List<RexNode> expList, RelOptPredicateList predicates) Reduces a list of expressions.protected static booleanreduceExpressions(RelNode rel, List<RexNode> expList, RelOptPredicateList predicates, boolean unknownAsFalse) Deprecated.protected static booleanreduceExpressions(RelNode rel, List<RexNode> expList, RelOptPredicateList predicates, boolean unknownAsFalse, boolean matchNullability, boolean treatDynamicCallsAsConstant) Reduces a list of expressions.protected static booleanreduceExpressionsInternal(RelNode rel, RexSimplify simplify, RexUnknownAs unknownAs, List<RexNode> expList, RelOptPredicateList predicates, boolean treatDynamicCallsAsConstant) protected static RexNodesubstitute(RexCall call, int ordinal, RexNode node) Converts op(arg0, ..., argOrdinal, ..., argN) to op(arg0,..., node, ..., argN).Methods inherited from class org.apache.calcite.plan.RelOptRule
any, convert, convert, convert, convert, convertList, convertOperand, convertOperand, equals, equals, getOperand, getOperands, getOutConvention, getOutTrait, hashCode, matches, none, onMatch, operand, operand, operand, operand, operand, operandJ, operandJ, some, toString, unorderedMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.calcite.rel.rules.SubstitutionRule
autoPruneOld
-
Field Details
-
EXCLUSION_PATTERN
Regular expression that matches the description of all instances of this rule andValuesReduceRulealso. Use it to prevent the planner from invoking these rules.
-
-
Constructor Details
-
ReduceExpressionsRule
Creates a ReduceExpressionsRule.
-
-
Method Details
-
reduceExpressions
protected static boolean reduceExpressions(RelNode rel, List<RexNode> expList, RelOptPredicateList predicates) Reduces a list of expressions.- Parameters:
rel- Relational expressionexpList- List of expressions, modified in placepredicates- Constraints known to hold on input expressions- Returns:
- whether reduction found something to change, and succeeded
-
reduceExpressions
@Deprecated protected static boolean reduceExpressions(RelNode rel, List<RexNode> expList, RelOptPredicateList predicates, boolean unknownAsFalse) Deprecated. -
reduceExpressions
protected static boolean reduceExpressions(RelNode rel, List<RexNode> expList, RelOptPredicateList predicates, boolean unknownAsFalse, boolean matchNullability, boolean treatDynamicCallsAsConstant) Reduces a list of expressions.The
matchNullabilityflag comes into play when reducing an expression whose type is nullable. Suppose we are reducing an expressionCASE WHEN 'a' = 'a' THEN 1 ELSE NULL END. Before reduction the type isINTEGER(nullable), but after reduction the literal 1 has typeINTEGER NOT NULL.In some situations it is more important to preserve types; in this case you should use
matchNullability = true(which used to be the default behavior of this method), and it will cast the literal toINTEGER(nullable).In other situations, you would rather propagate the new stronger type, because it may allow further optimizations later; pass
matchNullability = falseand no cast will be added, but you may need to adjust types elsewhere in the expression tree.- Parameters:
rel- Relational expressionexpList- List of expressions, modified in placepredicates- Constraints known to hold on input expressionsunknownAsFalse- Whether UNKNOWN will be treated as FALSEmatchNullability- Whether Calcite should add a CAST to a literal resulting from simplification and expression if the expression had nullable type and the literal is NOT NULLtreatDynamicCallsAsConstant- Whether to treat dynamic functions as constants- Returns:
- whether reduction found something to change, and succeeded
-
reduceExpressionsInternal
protected static boolean reduceExpressionsInternal(RelNode rel, RexSimplify simplify, RexUnknownAs unknownAs, List<RexNode> expList, RelOptPredicateList predicates, boolean treatDynamicCallsAsConstant) -
findReducibleExps
protected static void findReducibleExps(RelDataTypeFactory typeFactory, List<RexNode> exps, com.google.common.collect.ImmutableMap<RexNode, RexNode> constants, List<RexNode> constExps, List<Boolean> addCasts, boolean treatDynamicCallsAsConstant) Locates expressions that can be reduced to literals or converted to expressions with redundant casts removed.- Parameters:
typeFactory- Type factoryexps- list of candidate expressions to be examined for reductionconstants- List of expressions known to be constantconstExps- returns the list of expressions that can be constant reducedaddCasts- indicator for each expression that can be constant reduced, whether a cast of the resulting reduced expression is potentially necessarytreatDynamicCallsAsConstant- Whether to treat dynamic functions as constants
-
predicateConstants
@Deprecated public static <C extends RexNode> com.google.common.collect.ImmutableMap<RexNode,C> predicateConstants(Class<C> clazz, RexBuilder rexBuilder, RelOptPredicateList predicates) Deprecated.Creates a map containing each (e, constant) pair that occurs within a predicate list.- Type Parameters:
C- what to consider a constant:RexLiteralto use a narrow definition of constant, orRexNodeto useRexUtil.isConstant(RexNode)- Parameters:
clazz- Class of expression that is considered constantrexBuilder- Rex builderpredicates- Predicate list- Returns:
- Map from values to constants
-
pushPredicateIntoCase
Pushes predicates into a CASE.We have a loose definition of 'predicate': any boolean expression will do, except CASE. For example '(CASE ...) = 5' or '(CASE ...) IS NULL'.
-
substitute
Converts op(arg0, ..., argOrdinal, ..., argN) to op(arg0,..., node, ..., argN).
-
RelOptPredicateList.constantMap