Package org.apache.calcite.rel.metadata
Class RelMdPredicates
- java.lang.Object
-
- org.apache.calcite.rel.metadata.RelMdPredicates
-
- All Implemented Interfaces:
MetadataHandler<BuiltInMetadata.Predicates>
public class RelMdPredicates extends java.lang.Object implements MetadataHandler<BuiltInMetadata.Predicates>
Utility to infer Predicates that are applicable above a RelNode.This is currently used by
JoinPushTransitivePredicatesRule
to infer Predicates that can be inferred from one side of a Join to the other.The PullUp Strategy is sound but not complete. Here are some of the limitations:
- For Aggregations we only PullUp predicates that only contain
Grouping Keys. This can be extended to infer predicates on Aggregation
expressions from expressions on the aggregated columns. For e.g.
select a, max(b) from R1 where b > 7 → max(b) > 7 or max(b) is null
- For Projections we only look at columns that are projected without
any function applied. So:
select a from R1 where a > 7 → "a > 7" is pulled up from the Projection. select a + 1 from R1 where a + 1 > 7 → "a + 1 gt; 7" is not pulled up
- There are several restrictions on Joins:
- 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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
RelMdPredicates.JoinConditionBasedPredicateInference
Utility to infer predicates from one side of the join that apply on the other side.
-
Field Summary
Fields Modifier and Type Field Description private static java.util.List<RexNode>
EMPTY_LIST
static RelMetadataProvider
SOURCE
-
Constructor Summary
Constructors Constructor Description RelMdPredicates()
-
Method Summary
-
-
-
Field Detail
-
SOURCE
public static final RelMetadataProvider SOURCE
-
EMPTY_LIST
private static final java.util.List<RexNode> EMPTY_LIST
-
-
Method Detail
-
getDef
public MetadataDef<BuiltInMetadata.Predicates> getDef()
- Specified by:
getDef
in interfaceMetadataHandler<BuiltInMetadata.Predicates>
-
getPredicates
public RelOptPredicateList getPredicates(RelNode rel, RelMetadataQuery mq)
Catch-all implementation forBuiltInMetadata.Predicates.getPredicates()
, invoked using reflection.
-
getPredicates
public RelOptPredicateList getPredicates(HepRelVertex rel, RelMetadataQuery mq)
-
getPredicates
public RelOptPredicateList getPredicates(TableScan table, RelMetadataQuery mq)
Infers predicates for a table scan.
-
getPredicates
public RelOptPredicateList getPredicates(Project project, RelMetadataQuery mq)
Infers predicates for a project.- create a mapping from input to projection. Map only positions that directly reference an input column.
- Expressions that only contain above columns are retained in the Project's pullExpressions list.
- For e.g. expression 'a + e = 9' below will not be pulled up because 'e'
is not in the projection list.
inputPullUpExprs: {a > 7, b + c < 10, a + e = 9} projectionExprs: {a, b, c, e / 2} projectionPullupExprs: {a > 7, b + c < 10}
-
projectPredicate
private RexNode projectPredicate(RexBuilder rexBuilder, RelNode input, RexNode r, ImmutableBitSet columnsMapped)
Converts a predicate on a particular set of columns into a predicate on a subset of those columns, weakening if necessary.If not possible to simplify, returns
true
, which is the weakest possible predicate.Examples:
- The predicate
$7 = $9
on columns [7] becomes$7 is not null
- The predicate
$7 = $9 + $11
on columns [7, 9] becomes$7 is not null or $9 is not null
- The predicate
$7 = $9 and $9 = 5
on columns [7] becomes$7 = 5
- The predicate
$7 = $9 and ($9 = $1 or $9 = $2) and $1 > 3 and $2 > 10
on columns [7] becomes$7 > 3
We currently only handle examples 1 and 2.
- Parameters:
rexBuilder
- Rex builderinput
- Input relational expressionr
- Predicate expressioncolumnsMapped
- Columns which the final predicate can reference- Returns:
- Predicate expression narrowed to reference only certain columns
- The predicate
-
getPredicates
public RelOptPredicateList getPredicates(Filter filter, RelMetadataQuery mq)
Add the Filter condition to the pulledPredicates list from the input.
-
getPredicates
public RelOptPredicateList getPredicates(Join join, RelMetadataQuery mq)
-
getPredicates
public RelOptPredicateList getPredicates(Aggregate agg, RelMetadataQuery mq)
Infers predicates for an Aggregate.Pulls up predicates that only contains references to columns in the GroupSet. For e.g.
inputPullUpExprs : { a > 7, b + c < 10, a + e = 9} groupSet : { a, b} pulledUpExprs : { a > 7}
-
getPredicates
public RelOptPredicateList getPredicates(Union union, RelMetadataQuery mq)
Infers predicates for a Union.
-
getPredicates
public RelOptPredicateList getPredicates(Sort sort, RelMetadataQuery mq)
Infers predicates for a Sort.
-
getPredicates
public RelOptPredicateList getPredicates(Exchange exchange, RelMetadataQuery mq)
Infers predicates for an Exchange.
-
getPredicates
public RelOptPredicateList getPredicates(RelSubset r, RelMetadataQuery mq)
-
-