Package org.apache.calcite.rel.metadata
Class RelMdPredicates.JoinConditionBasedPredicateInference
- java.lang.Object
-
- org.apache.calcite.rel.metadata.RelMdPredicates.JoinConditionBasedPredicateInference
-
- Enclosing class:
- RelMdPredicates
static class RelMdPredicates.JoinConditionBasedPredicateInference extends java.lang.Object
Utility to infer predicates from one side of the join that apply on the other side.Contract is:
- initialize with a
Join
and optional predicates applicable on its left and right subtrees. - you can then ask it for equivalentPredicate(s) given a predicate.
So for:
- '
R1(x) join R2(y) on x = y
' a call for equivalentPredicates on 'x > 7
' will return '[y > 7]
' - '
R1(x) join R2(y) on x = y join R3(z) on y = z
' a call for equivalentPredicates on the second join 'x > 7
' will return
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) class
RelMdPredicates.JoinConditionBasedPredicateInference.EquivalenceFinder
Find expressions of the form 'col_x = col_y'.(package private) class
RelMdPredicates.JoinConditionBasedPredicateInference.ExprsItr
Given an expression returns all the possible substitutions.
-
Field Summary
Fields Modifier and Type Field Description (package private) java.util.Set<RexNode>
allExprs
(package private) ImmutableBitSet
allFieldsBitSet
(package private) java.util.Set<RexNode>
equalityPredicates
(package private) java.util.SortedMap<java.lang.Integer,java.util.BitSet>
equivalence
(package private) java.util.Map<RexNode,ImmutableBitSet>
exprFields
(package private) boolean
isSemiJoin
(package private) Join
joinRel
(package private) RexNode
leftChildPredicates
(package private) ImmutableBitSet
leftFieldsBitSet
(package private) int
nFieldsLeft
(package private) int
nFieldsRight
(package private) int
nSysFields
(package private) RexNode
rightChildPredicates
(package private) ImmutableBitSet
rightFieldsBitSet
(package private) RexSimplify
simplify
-
Constructor Summary
Constructors Modifier Constructor Description private
JoinConditionBasedPredicateInference(Join joinRel, boolean isSemiJoin, RexNode leftPredicates, RexNode rightPredicates, RexSimplify simplify)
(package private)
JoinConditionBasedPredicateInference(Join joinRel, RexNode leftPredicates, RexNode rightPredicates, RexSimplify simplify)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
checkTarget(ImmutableBitSet inferringFields, java.util.Set<RexNode> allExprs, RexNode tr)
(package private) RexNode
compose(RexBuilder rexBuilder, java.lang.Iterable<RexNode> exprs)
private void
infer(RexNode predicates, java.util.Set<RexNode> allExprs, java.util.List<RexNode> inferredPredicates, boolean includeEqualityInference, ImmutableBitSet inferringFields)
RelOptPredicateList
inferPredicates(boolean includeEqualityInference)
The PullUp Strategy is sound but not complete.private boolean
isAlwaysTrue(RexNode predicate)
RexNode
left()
(package private) java.lang.Iterable<Mapping>
mappings(RexNode predicate)
private void
markAsEquivalent(int p1, int p2)
private int
pos(RexNode expr)
RexNode
right()
-
-
-
Field Detail
-
joinRel
final Join joinRel
-
isSemiJoin
final boolean isSemiJoin
-
nSysFields
final int nSysFields
-
nFieldsLeft
final int nFieldsLeft
-
nFieldsRight
final int nFieldsRight
-
leftFieldsBitSet
final ImmutableBitSet leftFieldsBitSet
-
rightFieldsBitSet
final ImmutableBitSet rightFieldsBitSet
-
allFieldsBitSet
final ImmutableBitSet allFieldsBitSet
-
equivalence
java.util.SortedMap<java.lang.Integer,java.util.BitSet> equivalence
-
exprFields
final java.util.Map<RexNode,ImmutableBitSet> exprFields
-
allExprs
final java.util.Set<RexNode> allExprs
-
equalityPredicates
final java.util.Set<RexNode> equalityPredicates
-
leftChildPredicates
final RexNode leftChildPredicates
-
rightChildPredicates
final RexNode rightChildPredicates
-
simplify
final RexSimplify simplify
-
-
Constructor Detail
-
JoinConditionBasedPredicateInference
JoinConditionBasedPredicateInference(Join joinRel, RexNode leftPredicates, RexNode rightPredicates, RexSimplify simplify)
-
JoinConditionBasedPredicateInference
private JoinConditionBasedPredicateInference(Join joinRel, boolean isSemiJoin, RexNode leftPredicates, RexNode rightPredicates, RexSimplify simplify)
-
-
Method Detail
-
inferPredicates
public RelOptPredicateList inferPredicates(boolean includeEqualityInference)
The PullUp Strategy is sound but not complete.- We only pullUp inferred predicates for now. Pulling up existing predicates causes an explosion of duplicates. The existing predicates are pushed back down as new predicates. Once we have rules to eliminate duplicate Filter conditions, we should pullUp all predicates.
- For Left Outer: we infer new predicates from the left and set them as applicable on the Right side. No predicates are pulledUp.
- Right Outer Joins are handled in an analogous manner.
- For Full Outer Joins no predicates are pulledUp or inferred.
-
left
public RexNode left()
-
right
public RexNode right()
-
infer
private void infer(RexNode predicates, java.util.Set<RexNode> allExprs, java.util.List<RexNode> inferredPredicates, boolean includeEqualityInference, ImmutableBitSet inferringFields)
-
checkTarget
private boolean checkTarget(ImmutableBitSet inferringFields, java.util.Set<RexNode> allExprs, RexNode tr)
-
markAsEquivalent
private void markAsEquivalent(int p1, int p2)
-
compose
@Nonnull RexNode compose(RexBuilder rexBuilder, java.lang.Iterable<RexNode> exprs)
-
pos
private int pos(RexNode expr)
-
isAlwaysTrue
private boolean isAlwaysTrue(RexNode predicate)
-
-