public class RexSimplify extends Object
| Modifier and Type | Class and Description |
|---|---|
private static class |
RexSimplify.Comparison
Comparison between a
RexInputRef or RexFieldAccess and a
literal. |
| Modifier and Type | Field and Description |
|---|---|
private RexExecutor |
executor |
private RelOptPredicateList |
predicates |
RexBuilder |
rexBuilder |
(package private) boolean |
unknownAsFalse |
| Constructor and Description |
|---|
RexSimplify(RexBuilder rexBuilder,
boolean unknownAsFalse,
RexExecutor executor)
Deprecated.
|
RexSimplify(RexBuilder rexBuilder,
RelOptPredicateList predicates,
boolean unknownAsFalse,
RexExecutor executor)
Creates a RexSimplify.
|
| Modifier and Type | Method and Description |
|---|---|
private static boolean |
canRollUp(org.apache.calcite.avatica.util.TimeUnit outer,
org.apache.calcite.avatica.util.TimeUnit inner)
Method that returns whether we can rollup from inner time unit
to outer time unit.
|
private static List<Pair<RexNode,RexNode>> |
casePairs(RexBuilder rexBuilder,
List<RexNode> operands)
Given "CASE WHEN p1 THEN v1 ...
|
private static boolean |
isLowerBound(RexNode e) |
private static boolean |
isUpperBound(RexNode e) |
private static <C extends Comparable<C>> |
processRange(RexBuilder rexBuilder,
List<RexNode> terms,
Map<String,Pair<com.google.common.collect.Range<C>,List<RexNode>>> rangeTerms,
RexNode term,
RexNode ref,
C v0,
SqlKind comparison) |
private static <C extends Comparable<C>> |
range(SqlKind comparison,
C c) |
RexNode |
removeNullabilityCast(RexNode e)
Removes any casts that change nullability but not type.
|
private <C extends Comparable<C>> |
residue(RexNode ref,
com.google.common.collect.Range<C> r0,
List<RexNode> predicates,
Class<C> clazz)
Weakens a term so that it checks only what is not implied by predicates.
|
RexNode |
simplify(RexNode e)
Simplifies a boolean expression.
|
RexNode |
simplifyAnd(RexCall e) |
(package private) RexNode |
simplifyAnd2(List<RexNode> terms,
List<RexNode> notTerms) |
(package private) RexNode |
simplifyAnd2ForUnknownAsFalse(List<RexNode> terms,
List<RexNode> notTerms)
As
simplifyAnd2(List, List) but we assume that if the expression
returns UNKNOWN it will be interpreted as FALSE. |
private <C extends Comparable<C>> |
simplifyAnd2ForUnknownAsFalse(List<RexNode> terms,
List<RexNode> notTerms,
Class<C> clazz) |
RexNode |
simplifyAnds(Iterable<? extends RexNode> nodes)
Simplifies a conjunction of boolean expressions.
|
private RexNode |
simplifyCase(RexCall call) |
private RexNode |
simplifyCast(RexCall e) |
private RexNode |
simplifyCeilFloor(RexCall e)
Tries to simplify CEIL/FLOOR function on top of CEIL/FLOOR.
|
private RexNode |
simplifyComparison(RexCall e) |
private <C extends Comparable<C>> |
simplifyComparison(RexCall e,
Class<C> clazz) |
private RexNode |
simplifyIs(RexCall call) |
private RexNode |
simplifyIs2(SqlKind kind,
RexNode a) |
private RexNode |
simplifyIsNotNull(RexNode a) |
private void |
simplifyList(List<RexNode> terms) |
private RexNode |
simplifyNot(RexCall call) |
RexNode |
simplifyOr(RexCall call)
Simplifies OR(x, x) into x, and similar.
|
RexNode |
simplifyOrs(List<RexNode> terms)
Simplifies a list of terms and combines them into an OR.
|
RexNode |
simplifyPreservingType(RexNode e)
Simplifies a boolean expression, always preserving its type and its
nullability.
|
private <C extends Comparable<C>> |
simplifyUsingPredicates(RexNode e,
Class<C> clazz) |
RexSimplify |
withPredicates(RelOptPredicateList predicates)
Returns a RexSimplify the same as this but with a specified
predicates value. |
RexSimplify |
withUnknownAsFalse(boolean unknownAsFalse)
Returns a RexSimplify the same as this but with a specified
unknownAsFalse value. |
public final RexBuilder rexBuilder
private final RelOptPredicateList predicates
final boolean unknownAsFalse
private final RexExecutor executor
public RexSimplify(RexBuilder rexBuilder, RelOptPredicateList predicates, boolean unknownAsFalse, RexExecutor executor)
rexBuilder - Rex builderpredicates - Predicates known to hold on input fieldsunknownAsFalse - Whether to convert UNKNOWN values to FALSEexecutor - Executor for constant reduction, not null@Deprecated public RexSimplify(RexBuilder rexBuilder, boolean unknownAsFalse, RexExecutor executor)
public RexSimplify withUnknownAsFalse(boolean unknownAsFalse)
unknownAsFalse value.public RexSimplify withPredicates(RelOptPredicateList predicates)
predicates value.public RexNode simplifyPreservingType(RexNode e)
This is useful if you are simplifying expressions in a
Project.
public RexNode simplify(RexNode e)
In particular:
simplify(x = 1 AND y = 2 AND NOT x = 1)
returns y = 2simplify(x = 1 AND FALSE)
returns FALSEIf the expression is a predicate in a WHERE clause, UNKNOWN values have
the same effect as FALSE. In situations like this, specify
unknownAsFalse = true, so and we can switch from 3-valued logic to
simpler 2-valued logic and make more optimizations.
e - Expression to simplifyprivate <C extends Comparable<C>> RexNode simplifyComparison(RexCall e, Class<C> clazz)
public RexNode simplifyAnds(Iterable<? extends RexNode> nodes)
private static List<Pair<RexNode,RexNode>> casePairs(RexBuilder rexBuilder, List<RexNode> operands)
RexNode simplifyAnd2ForUnknownAsFalse(List<RexNode> terms, List<RexNode> notTerms)
simplifyAnd2(List, List) but we assume that if the expression
returns UNKNOWN it will be interpreted as FALSE.private <C extends Comparable<C>> RexNode simplifyAnd2ForUnknownAsFalse(List<RexNode> terms, List<RexNode> notTerms, Class<C> clazz)
private <C extends Comparable<C>> RexNode simplifyUsingPredicates(RexNode e, Class<C> clazz)
private <C extends Comparable<C>> com.google.common.collect.Range<C> residue(RexNode ref, com.google.common.collect.Range<C> r0, List<RexNode> predicates, Class<C> clazz)
The term is broken into "ref comparison constant", for example "$0 < 5".
Examples:
residue($0 < 10, [$0 < 5]) returns true
residue($0 < 10, [$0 < 20, $0 > 0]) returns $0 < 10
public RexNode simplifyOrs(List<RexNode> terms)
private RexNode simplifyCeilFloor(RexCall e)
Examples:
ceil(floor($0, flag(hour)), flag(day)) returns ceil($0, flag(day))
floor(floor($0, flag(second)), flag(day)) returns floor($0, flag(day))
floor(ceil($0, flag(day)), flag(second)) does not change
private static boolean canRollUp(org.apache.calcite.avatica.util.TimeUnit outer,
org.apache.calcite.avatica.util.TimeUnit inner)
public RexNode removeNullabilityCast(RexNode e)
For example, CAST(1 = 0 AS BOOLEAN) becomes 1 = 0.
private static <C extends Comparable<C>> RexNode processRange(RexBuilder rexBuilder, List<RexNode> terms, Map<String,Pair<com.google.common.collect.Range<C>,List<RexNode>>> rangeTerms, RexNode term, RexNode ref, C v0, SqlKind comparison)
private static <C extends Comparable<C>> com.google.common.collect.Range<C> range(SqlKind comparison, C c)
private static boolean isUpperBound(RexNode e)
private static boolean isLowerBound(RexNode e)
Copyright © 2012–2018 The Apache Software Foundation. All rights reserved.