Class MaterializedViewJoinRule<C extends MaterializedViewRule.Config>
java.lang.Object
org.apache.calcite.plan.RelOptRule
org.apache.calcite.plan.RelRule<C>
org.apache.calcite.rel.rules.materialize.MaterializedViewRule<C>
org.apache.calcite.rel.rules.materialize.MaterializedViewJoinRule<C>
- Type Parameters:
C
- Configuration type
- Direct Known Subclasses:
MaterializedViewOnlyFilterRule
,MaterializedViewOnlyJoinRule
,MaterializedViewProjectFilterRule
,MaterializedViewProjectJoinRule
public abstract class MaterializedViewJoinRule<C extends MaterializedViewRule.Config>
extends MaterializedViewRule<C>
Materialized view rewriting for join.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.calcite.rel.rules.materialize.MaterializedViewRule
MaterializedViewRule.Config, MaterializedViewRule.Edge, MaterializedViewRule.EquivalenceClasses, MaterializedViewRule.MatchModality, MaterializedViewRule.NodeLineage, MaterializedViewRule.ViewPartialRewriting
Nested classes/interfaces inherited from class org.apache.calcite.plan.RelRule
RelRule.Done, RelRule.MatchHandler<R extends RelOptRule>, RelRule.OperandBuilder, RelRule.OperandDetailBuilder<R extends RelNode>, RelRule.OperandTransform
Nested classes/interfaces inherited from class org.apache.calcite.plan.RelOptRule
RelOptRule.ConverterRelOptRuleOperand
-
Field Summary
Fields inherited from class org.apache.calcite.plan.RelOptRule
description, operands, relBuilderFactory
-
Method Summary
Modifier and TypeMethodDescriptionprotected @Nullable MaterializedViewRule.ViewPartialRewriting
compensateViewPartial
(RelBuilder relBuilder, RexBuilder rexBuilder, RelMetadataQuery mq, RelNode input, @Nullable Project topProject, RelNode node, Set<RexTableInputRef.RelTableRef> queryTableRefs, MaterializedViewRule.EquivalenceClasses queryEC, @Nullable Project topViewProject, RelNode viewNode, Set<RexTableInputRef.RelTableRef> viewTableRefs) It checks whether the query can be rewritten using the view even though the query uses additional tables.protected @Nullable RelNode
createUnion
(RelBuilder relBuilder, RexBuilder rexBuilder, @Nullable RelNode topProject, RelNode unionInputQuery, RelNode unionInputView) If the view will be used in a union rewriting, this method is responsible for generating the union and any other operator needed on top of it, e.g., a Project operator.protected boolean
isValidPlan
(@Nullable Project topProject, RelNode node, RelMetadataQuery mq) pushFilterToOriginalViewPlan
(RelBuilder builder, @Nullable RelNode topViewProject, RelNode viewNode, RexNode cond) Once we create a compensation predicate, this method is responsible for pushing the resulting filter through the view nodes.protected @Nullable RelNode
rewriteQuery
(RelBuilder relBuilder, RexBuilder rexBuilder, RexSimplify simplify, RelMetadataQuery mq, RexNode compensationColumnsEquiPred, RexNode otherCompensationPred, @Nullable Project topProject, RelNode node, com.google.common.collect.BiMap<RexTableInputRef.RelTableRef, RexTableInputRef.RelTableRef> viewToQueryTableMapping, MaterializedViewRule.EquivalenceClasses viewEC, MaterializedViewRule.EquivalenceClasses queryEC) If the view will be used in a union rewriting, this method is responsible for rewriting the query branch of the union using the given compensation predicate.protected @Nullable RelNode
rewriteView
(RelBuilder relBuilder, RexBuilder rexBuilder, RexSimplify simplify, RelMetadataQuery mq, MaterializedViewRule.MatchModality matchModality, boolean unionRewriting, RelNode input, @Nullable Project topProject, RelNode node, @Nullable Project topViewProject, RelNode viewNode, com.google.common.collect.BiMap<RexTableInputRef.RelTableRef, RexTableInputRef.RelTableRef> queryToViewTableMapping, MaterializedViewRule.EquivalenceClasses queryEC) Rewrites the query using the given view query.Methods inherited from class org.apache.calcite.rel.rules.materialize.MaterializedViewRule
compensatePartial, computeCompensationPredicates, extractPossibleMapping, extractReferences, generateEquivalenceClasses, generateSwapColumnTableReferencesLineage, generateSwapTableColumnReferencesLineage, generateTableMappings, isValidRelNodePlan, matches, perform, replaceWithOriginalReferences, rewriteExpression, rewriteExpressions, shuttleReferences, shuttleReferences, shuttleReferences, splitPredicates
Methods inherited from class org.apache.calcite.plan.RelOptRule
any, convert, convert, convert, convert, convertList, convertOperand, convertOperand, equals, equals, getOperand, getOperands, getOutConvention, getOutTrait, hashCode, none, onMatch, operand, operand, operand, operand, operand, operandJ, operandJ, some, toString, unordered
-
Method Details
-
isValidPlan
- Specified by:
isValidPlan
in classMaterializedViewRule<C extends MaterializedViewRule.Config>
-
compensateViewPartial
protected @Nullable MaterializedViewRule.ViewPartialRewriting compensateViewPartial(RelBuilder relBuilder, RexBuilder rexBuilder, RelMetadataQuery mq, RelNode input, @Nullable Project topProject, RelNode node, Set<RexTableInputRef.RelTableRef> queryTableRefs, MaterializedViewRule.EquivalenceClasses queryEC, @Nullable Project topViewProject, RelNode viewNode, Set<RexTableInputRef.RelTableRef> viewTableRefs) Description copied from class:MaterializedViewRule
It checks whether the query can be rewritten using the view even though the query uses additional tables.Rules implementing the method should follow different approaches depending on the operators they rewrite.
- Specified by:
compensateViewPartial
in classMaterializedViewRule<C extends MaterializedViewRule.Config>
- Returns:
- ViewPartialRewriting, or null if the rewrite can't be done
-
rewriteQuery
protected @Nullable RelNode rewriteQuery(RelBuilder relBuilder, RexBuilder rexBuilder, RexSimplify simplify, RelMetadataQuery mq, RexNode compensationColumnsEquiPred, RexNode otherCompensationPred, @Nullable Project topProject, RelNode node, com.google.common.collect.BiMap<RexTableInputRef.RelTableRef, RexTableInputRef.RelTableRef> viewToQueryTableMapping, MaterializedViewRule.EquivalenceClasses viewEC, MaterializedViewRule.EquivalenceClasses queryEC) Description copied from class:MaterializedViewRule
If the view will be used in a union rewriting, this method is responsible for rewriting the query branch of the union using the given compensation predicate.If a rewriting can be produced, we return that rewriting. If it cannot be produced, we will return null.
- Specified by:
rewriteQuery
in classMaterializedViewRule<C extends MaterializedViewRule.Config>
-
createUnion
protected @Nullable RelNode createUnion(RelBuilder relBuilder, RexBuilder rexBuilder, @Nullable RelNode topProject, RelNode unionInputQuery, RelNode unionInputView) Description copied from class:MaterializedViewRule
If the view will be used in a union rewriting, this method is responsible for generating the union and any other operator needed on top of it, e.g., a Project operator.- Specified by:
createUnion
in classMaterializedViewRule<C extends MaterializedViewRule.Config>
-
rewriteView
protected @Nullable RelNode rewriteView(RelBuilder relBuilder, RexBuilder rexBuilder, RexSimplify simplify, RelMetadataQuery mq, MaterializedViewRule.MatchModality matchModality, boolean unionRewriting, RelNode input, @Nullable Project topProject, RelNode node, @Nullable Project topViewProject, RelNode viewNode, com.google.common.collect.BiMap<RexTableInputRef.RelTableRef, RexTableInputRef.RelTableRef> queryToViewTableMapping, MaterializedViewRule.EquivalenceClasses queryEC) Description copied from class:MaterializedViewRule
Rewrites the query using the given view query.The input node is a Scan on the view table and possibly a compensation Filter on top. If a rewriting can be produced, we return that rewriting. If it cannot be produced, we will return null.
- Specified by:
rewriteView
in classMaterializedViewRule<C extends MaterializedViewRule.Config>
-
pushFilterToOriginalViewPlan
public Pair<@Nullable RelNode,RelNode> pushFilterToOriginalViewPlan(RelBuilder builder, @Nullable RelNode topViewProject, RelNode viewNode, RexNode cond) Description copied from class:MaterializedViewRule
Once we create a compensation predicate, this method is responsible for pushing the resulting filter through the view nodes. This might be useful for rewritings containing Aggregate operators, as some of the grouping columns might be removed, which results in additional matching possibilities.The method will return a pair of nodes: the new top project on the left and the new node on the right.
- Specified by:
pushFilterToOriginalViewPlan
in classMaterializedViewRule<C extends MaterializedViewRule.Config>
-