Package org.apache.calcite.plan
Class RexImplicationChecker
- java.lang.Object
-
- org.apache.calcite.plan.RexImplicationChecker
-
public class RexImplicationChecker extends java.lang.Object
Checks whether one condition logically implies another.If A ⇒ B, whenever A is true, B will be true also.
For example:
- (x > 10) ⇒ (x > 5)
- (x = 10) ⇒ (x < 30 OR y > 30)
- (x = 10) ⇒ (x IS NOT NULL)
- (x > 10 AND y = 20) ⇒ (x > 5)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
RexImplicationChecker.InputRefUsage<T1,T2>
Usage of aRexInputRef
in an expression.private static class
RexImplicationChecker.InputUsageFinder
Visitor that builds a usage map of inputs used by an expression.
-
Field Summary
Fields Modifier and Type Field Description (package private) RexBuilder
builder
(package private) RexExecutorImpl
executor
private static CalciteLogger
LOGGER
(package private) RelDataType
rowType
-
Constructor Summary
Constructors Constructor Description RexImplicationChecker(RexBuilder builder, RexExecutorImpl executor, RelDataType rowType)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
checkSupport(RexImplicationChecker.InputUsageFinder firstUsageFinder, RexImplicationChecker.InputUsageFinder secondUsageFinder)
Looks at the usage of variables in first and second conjunction to decide whether this kind of expression is currently supported for proving first implies second.boolean
implies(RexNode first, RexNode second)
Checks if condition first implies (⇒) condition second.private boolean
implies2(RexNode first, RexNode second)
Returns whether the predicatefirst
(not a conjunction) impliessecond
.private boolean
impliesAny(RexNode first, java.util.List<RexNode> seconds)
Returns whether the predicatefirst
implies (⇒) at least one predicate inseconds
.private boolean
impliesConjunction(RexNode first, RexNode second)
Returns whether the predicatefirst
impliessecond
(both may be conjunctions).private boolean
isEquivalentOp(SqlKind fKind, SqlKind sKind)
private boolean
isOppositeOp(SqlKind fKind, SqlKind sKind)
private boolean
isSatisfiable(RexNode second, DataContext dataValues)
private boolean
isSupportedUnaryOperators(SqlKind kind)
private boolean
validate(RexNode first, RexNode second)
-
-
-
Field Detail
-
LOGGER
private static final CalciteLogger LOGGER
-
builder
final RexBuilder builder
-
executor
final RexExecutorImpl executor
-
rowType
final RelDataType rowType
-
-
Constructor Detail
-
RexImplicationChecker
public RexImplicationChecker(RexBuilder builder, RexExecutorImpl executor, RelDataType rowType)
-
-
Method Detail
-
implies
public boolean implies(RexNode first, RexNode second)
Checks if condition first implies (⇒) condition second.This reduces to SAT problem which is NP-Complete. When this method says first implies second then it is definitely true. But it cannot prove that first does not imply second.
- Parameters:
first
- first conditionsecond
- second condition- Returns:
- true if it can prove first ⇒ second; otherwise false i.e., it doesn't know if implication holds
-
impliesAny
private boolean impliesAny(RexNode first, java.util.List<RexNode> seconds)
Returns whether the predicatefirst
implies (⇒) at least one predicate inseconds
.
-
impliesConjunction
private boolean impliesConjunction(RexNode first, RexNode second)
Returns whether the predicatefirst
impliessecond
(both may be conjunctions).
-
implies2
private boolean implies2(RexNode first, RexNode second)
Returns whether the predicatefirst
(not a conjunction) impliessecond
.
-
isSatisfiable
private boolean isSatisfiable(RexNode second, DataContext dataValues)
-
checkSupport
private boolean checkSupport(RexImplicationChecker.InputUsageFinder firstUsageFinder, RexImplicationChecker.InputUsageFinder secondUsageFinder)
Looks at the usage of variables in first and second conjunction to decide whether this kind of expression is currently supported for proving first implies second.- Variables should be used only once in both the conjunction against given set of operations only: >, <, ≤, ≥, =; ≠.
- All the variables used in second condition should be used even in the first.
- If operator used for variable in first is op1 and op2 for second, then
we support these combination for conjunction (op1, op2) then op1, op2
belongs to one of the following sets:
- (<, ≤) X (<, ≤) note: X represents cartesian product
- (> / ≥) X (>, ≥)
- (=) X (>, ≥, <, ≤, =, ≠)
- (≠, =)
- We support at most 2 operators to be be used for a variable in first and second usages.
- Returns:
- whether input usage pattern is supported
-
isSupportedUnaryOperators
private boolean isSupportedUnaryOperators(SqlKind kind)
-
-