Package org.apache.calcite.rel.metadata
Class RelMdPredicates
java.lang.Object
org.apache.calcite.rel.metadata.RelMdPredicates
- All Implemented Interfaces:
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.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptiongetDef()
Returns theBuiltInMetadata.Predicates.getPredicates()
statistic.getPredicates
(Aggregate agg, RelMetadataQuery mq) Infers predicates for an Aggregate.getPredicates
(Correlate correlate, RelMetadataQuery mq) Infers predicates for a correlate node.getPredicates
(Exchange exchange, RelMetadataQuery mq) Infers predicates for an Exchange.getPredicates
(Filter filter, RelMetadataQuery mq) Add the Filter condition to the pulledPredicates list from the input.getPredicates
(Intersect intersect, RelMetadataQuery mq) Infers predicates for a Intersect.getPredicates
(Join join, RelMetadataQuery mq) Infers predicates for aJoin
(includingSemiJoin
).getPredicates
(Minus minus, RelMetadataQuery mq) Infers predicates for a Minus.getPredicates
(Project project, RelMetadataQuery mq) Infers predicates for a project.getPredicates
(Sample sample, RelMetadataQuery mq) Infers predicates for a Sample.getPredicates
(Sort sort, RelMetadataQuery mq) Infers predicates for a Sort.getPredicates
(TableModify tableModify, RelMetadataQuery mq) Infers predicates for a TableModify.getPredicates
(TableScan scan, RelMetadataQuery mq) Infers predicates for a table scan.getPredicates
(Union union, RelMetadataQuery mq) Infers predicates for a Union.getPredicates
(Values values, RelMetadataQuery mq) Infers predicates for a Values.getPredicates
(RelNode rel, RelMetadataQuery mq) Catch-all implementation forBuiltInMetadata.Predicates.getPredicates()
, invoked using reflection.
-
Field Details
-
SOURCE
-
-
Constructor Details
-
RelMdPredicates
public RelMdPredicates()
-
-
Method Details
-
getDef
- Specified by:
getDef
in interfaceMetadataHandler<BuiltInMetadata.Predicates>
-
getPredicates
Catch-all implementation forBuiltInMetadata.Predicates.getPredicates()
, invoked using reflection. -
getPredicates
Infers predicates for a table scan. -
getPredicates
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}
-
getPredicates
Infers predicates for a correlate node. -
getPredicates
Add the Filter condition to the pulledPredicates list from the input. -
getPredicates
Infers predicates for aJoin
(includingSemiJoin
). -
getPredicates
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
Infers predicates for a Union. -
getPredicates
Infers predicates for a Intersect. -
getPredicates
Infers predicates for a Minus. -
getPredicates
Infers predicates for a Sample. -
getPredicates
Infers predicates for a Sort. -
getPredicates
Infers predicates for a TableModify. -
getPredicates
Infers predicates for an Exchange. -
getPredicates
Infers predicates for a Values.The predicates on
T (w, x, y, z)
with rows(1, 2, 3, null), (1, 2, null, null), (5, 2, 3, null)
are'SEARCH($0, Sarg[1, 5])'
,'=($1, 2)'
,'SEARCH($2, Sarg[3; NULL AS TRUE])'
and'[IS NULL($3)'
. -
getPredicates
Returns theBuiltInMetadata.Predicates.getPredicates()
statistic.
-