public abstract class ReduceExpressionsRule extends RelOptRule
Modifier and Type | Class and Description |
---|---|
static class |
ReduceExpressionsRule.CalcReduceExpressionsRule
Rule that reduces constants inside a
Calc . |
protected static class |
ReduceExpressionsRule.CaseShuttle
Shuttle that pushes predicates into a CASE.
|
static class |
ReduceExpressionsRule.FilterReduceExpressionsRule
Rule that reduces constants inside a
Filter . |
static class |
ReduceExpressionsRule.JoinReduceExpressionsRule
Rule that reduces constants inside a
Join . |
static class |
ReduceExpressionsRule.ProjectReduceExpressionsRule
Rule that reduces constants inside a
Project . |
protected static class |
ReduceExpressionsRule.ReducibleExprLocator
Helper class used to locate expressions that either can be reduced to
literals or contain redundant casts.
|
protected static class |
ReduceExpressionsRule.RexReplacer
Replaces expressions with their reductions.
|
static class |
ReduceExpressionsRule.WindowReduceExpressionsRule
Rule that reduces constants inside a
Window . |
Modifier and Type | Field and Description |
---|---|
static ReduceExpressionsRule |
CALC_INSTANCE
Singleton rule that reduces constants inside a
LogicalCalc . |
static java.util.regex.Pattern |
EXCLUSION_PATTERN
Regular expression that matches the description of all instances of this
rule and
ValuesReduceRule also. |
static ReduceExpressionsRule |
FILTER_INSTANCE
Singleton rule that reduces constants inside a
LogicalFilter . |
static ReduceExpressionsRule |
JOIN_INSTANCE
Singleton rule that reduces constants inside a
Join . |
protected boolean |
matchNullability |
static ReduceExpressionsRule |
PROJECT_INSTANCE
Singleton rule that reduces constants inside a
LogicalProject . |
static ReduceExpressionsRule |
WINDOW_INSTANCE
Singleton rule that reduces constants inside a
LogicalWindow . |
description, operands, relBuilderFactory
Modifier | Constructor and Description |
---|---|
protected |
ReduceExpressionsRule(java.lang.Class<? extends RelNode> clazz,
boolean matchNullability,
RelBuilderFactory relBuilderFactory,
java.lang.String description)
Creates a ReduceExpressionsRule.
|
protected |
ReduceExpressionsRule(java.lang.Class<? extends RelNode> clazz,
RelBuilderFactory relBuilderFactory,
java.lang.String description)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
protected static void |
findReducibleExps(RelDataTypeFactory typeFactory,
java.util.List<RexNode> exps,
com.google.common.collect.ImmutableMap<RexNode,RexNode> constants,
java.util.List<RexNode> constExps,
java.util.List<java.lang.Boolean> addCasts,
java.util.List<RexNode> removableCasts)
Locates expressions that can be reduced to literals or converted to
expressions with redundant casts removed.
|
static <C extends RexNode> |
predicateConstants(java.lang.Class<C> clazz,
RexBuilder rexBuilder,
RelOptPredicateList predicates)
Deprecated.
|
static RexCall |
pushPredicateIntoCase(RexCall call)
Pushes predicates into a CASE.
|
protected static boolean |
reduceExpressions(RelNode rel,
java.util.List<RexNode> expList,
RelOptPredicateList predicates)
Reduces a list of expressions.
|
protected static boolean |
reduceExpressions(RelNode rel,
java.util.List<RexNode> expList,
RelOptPredicateList predicates,
boolean unknownAsFalse)
Deprecated.
|
protected static boolean |
reduceExpressions(RelNode rel,
java.util.List<RexNode> expList,
RelOptPredicateList predicates,
boolean unknownAsFalse,
boolean matchNullability)
Reduces a list of expressions.
|
protected static boolean |
reduceExpressionsInternal(RelNode rel,
RexSimplify simplify,
RexUnknownAs unknownAs,
java.util.List<RexNode> expList,
RelOptPredicateList predicates) |
protected static RexNode |
substitute(RexCall call,
int ordinal,
RexNode node)
Converts op(arg0, ..., argOrdinal, ..., argN) to op(arg0,..., node, ..., argN).
|
any, convert, convert, convertList, convertOperand, convertOperand, equals, equals, getOperand, getOperands, getOutConvention, getOutTrait, hashCode, matches, none, onMatch, operand, operand, operand, operand, operand, operandJ, operandJ, some, toString, unordered
public static final java.util.regex.Pattern EXCLUSION_PATTERN
ValuesReduceRule
also. Use
it to prevent the planner from invoking these rules.public static final ReduceExpressionsRule FILTER_INSTANCE
LogicalFilter
.public static final ReduceExpressionsRule PROJECT_INSTANCE
LogicalProject
.public static final ReduceExpressionsRule JOIN_INSTANCE
Join
.public static final ReduceExpressionsRule CALC_INSTANCE
LogicalCalc
.public static final ReduceExpressionsRule WINDOW_INSTANCE
LogicalWindow
.protected final boolean matchNullability
protected ReduceExpressionsRule(java.lang.Class<? extends RelNode> clazz, boolean matchNullability, RelBuilderFactory relBuilderFactory, java.lang.String description)
clazz
- class of rels to which this rule should applymatchNullability
- Whether to add a CAST when a nullable expression
reduces to a NOT NULL literal@Deprecated protected ReduceExpressionsRule(java.lang.Class<? extends RelNode> clazz, RelBuilderFactory relBuilderFactory, java.lang.String description)
protected static boolean reduceExpressions(RelNode rel, java.util.List<RexNode> expList, RelOptPredicateList predicates)
rel
- Relational expressionexpList
- List of expressions, modified in placepredicates
- Constraints known to hold on input expressions@Deprecated protected static boolean reduceExpressions(RelNode rel, java.util.List<RexNode> expList, RelOptPredicateList predicates, boolean unknownAsFalse)
protected static boolean reduceExpressions(RelNode rel, java.util.List<RexNode> expList, RelOptPredicateList predicates, boolean unknownAsFalse, boolean matchNullability)
The matchNullability
flag comes into play when reducing a
expression whose type is nullable. Suppose we are reducing an expression
CASE WHEN 'a' = 'a' THEN 1 ELSE NULL END
. Before reduction the
type is INTEGER
(nullable), but after reduction the literal 1 has
type INTEGER 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 to
INTEGER
(nullable).
In other situations, you would rather propagate the new stronger type,
because it may allow further optimizations later; pass
matchNullability = false
and no cast will be added, but you may
need to adjust types elsewhere in the expression tree.
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 NULLprotected static boolean reduceExpressionsInternal(RelNode rel, RexSimplify simplify, RexUnknownAs unknownAs, java.util.List<RexNode> expList, RelOptPredicateList predicates)
protected static void findReducibleExps(RelDataTypeFactory typeFactory, java.util.List<RexNode> exps, com.google.common.collect.ImmutableMap<RexNode,RexNode> constants, java.util.List<RexNode> constExps, java.util.List<java.lang.Boolean> addCasts, java.util.List<RexNode> removableCasts)
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 necessaryremovableCasts
- returns the list of cast expressions where the cast@Deprecated public static <C extends RexNode> com.google.common.collect.ImmutableMap<RexNode,C> predicateConstants(java.lang.Class<C> clazz, RexBuilder rexBuilder, RelOptPredicateList predicates)
RelOptPredicateList.constantMap
C
- what to consider a constant: RexLiteral
to use a narrow
definition of constant, or RexNode
to use
RexUtil.isConstant(RexNode)
clazz
- Class of expression that is considered constantrexBuilder
- Rex builderpredicates
- Predicate listpublic static RexCall pushPredicateIntoCase(RexCall call)
We have a loose definition of 'predicate': any boolean expression will do, except CASE. For example '(CASE ...) = 5' or '(CASE ...) IS NULL'.
Copyright © 2012–2019 The Apache Software Foundation. All rights reserved.