Package org.apache.calcite.rel.rules
Class AbstractMaterializedViewRule.MaterializedViewAggregateRule
- java.lang.Object
-
- org.apache.calcite.plan.RelOptRule
-
- org.apache.calcite.rel.rules.AbstractMaterializedViewRule
-
- org.apache.calcite.rel.rules.AbstractMaterializedViewRule.MaterializedViewAggregateRule
-
- Direct Known Subclasses:
AbstractMaterializedViewRule.MaterializedViewOnlyAggregateRule
,AbstractMaterializedViewRule.MaterializedViewProjectAggregateRule
- Enclosing class:
- AbstractMaterializedViewRule
private abstract static class AbstractMaterializedViewRule.MaterializedViewAggregateRule extends AbstractMaterializedViewRule
Materialized view rewriting for aggregate
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.calcite.rel.rules.AbstractMaterializedViewRule
AbstractMaterializedViewRule.MaterializedViewOnlyAggregateRule, AbstractMaterializedViewRule.MaterializedViewOnlyFilterRule, AbstractMaterializedViewRule.MaterializedViewOnlyJoinRule, AbstractMaterializedViewRule.MaterializedViewProjectAggregateRule, AbstractMaterializedViewRule.MaterializedViewProjectFilterRule, AbstractMaterializedViewRule.MaterializedViewProjectJoinRule
-
-
Field Summary
Fields Modifier and Type Field Description protected RelOptRule
aggregateProjectPullUpConstantsRule
Instance of rule to pull up constants into aggregate.protected RelOptRule
filterAggregateTransposeRule
Instance of rule to push filter through aggregate.protected RelOptRule
filterProjectTransposeRule
Instance of rule to push filter through project.protected RelOptRule
projectMergeRule
Instance of rule to merge project operators.private static com.google.common.collect.ImmutableList<org.apache.calcite.avatica.util.TimeUnitRange>
SUPPORTED_DATE_TIME_ROLLUP_UNITS
-
Fields inherited from class org.apache.calcite.rel.rules.AbstractMaterializedViewRule
fastBailOut, generateUnionRewriting, INSTANCE_AGGREGATE, INSTANCE_FILTER, INSTANCE_JOIN, INSTANCE_PROJECT_AGGREGATE, INSTANCE_PROJECT_FILTER, INSTANCE_PROJECT_JOIN, unionRewritingPullProgram
-
Fields inherited from class org.apache.calcite.plan.RelOptRule
description, operands, relBuilderFactory
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
MaterializedViewAggregateRule(RelOptRuleOperand operand, RelBuilderFactory relBuilderFactory, java.lang.String description, boolean generateUnionRewriting, HepProgram unionRewritingPullProgram)
Creates a MaterializedViewAggregateRule.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected AbstractMaterializedViewRule.ViewPartialRewriting
compensateViewPartial(RelBuilder relBuilder, RexBuilder rexBuilder, RelMetadataQuery mq, RelNode input, Project topProject, RelNode node, java.util.Set<RexTableInputRef.RelTableRef> queryTableRefs, AbstractMaterializedViewRule.EquivalenceClasses queryEC, Project topViewProject, RelNode viewNode, java.util.Set<RexTableInputRef.RelTableRef> viewTableRefs)
It checks whether the query can be rewritten using the view even though the query uses additional tables.protected RelNode
createUnion(RelBuilder relBuilder, RexBuilder rexBuilder, 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 com.google.common.collect.Multimap<java.lang.Integer,java.lang.Integer>
generateMapping(RexBuilder rexBuilder, RexSimplify simplify, RelMetadataQuery mq, RelNode node, RelNode target, ImmutableBitSet positions, com.google.common.collect.BiMap<RexTableInputRef.RelTableRef,RexTableInputRef.RelTableRef> tableMapping, AbstractMaterializedViewRule.EquivalenceClasses sourceEC, java.util.List<RexNode> additionalExprs)
Mapping from node expressions to target expressions.protected SqlFunction
getCeilSqlFunction(org.apache.calcite.avatica.util.TimeUnitRange flag)
Get ceil function datetime.protected SqlFunction
getFloorSqlFunction(org.apache.calcite.avatica.util.TimeUnitRange flag)
Get floor function datetime.protected SqlAggFunction
getRollup(SqlAggFunction aggregation)
Get rollup aggregation function.protected boolean
isValidPlan(Project topProject, RelNode node, RelMetadataQuery mq)
Pair<RelNode,RelNode>
pushFilterToOriginalViewPlan(RelBuilder builder, 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 RelNode
rewriteQuery(RelBuilder relBuilder, RexBuilder rexBuilder, RexSimplify simplify, RelMetadataQuery mq, RexNode compensationColumnsEquiPred, RexNode otherCompensationPred, Project topProject, RelNode node, com.google.common.collect.BiMap<RexTableInputRef.RelTableRef,RexTableInputRef.RelTableRef> queryToViewTableMapping, AbstractMaterializedViewRule.EquivalenceClasses viewEC, AbstractMaterializedViewRule.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 RelNode
rewriteView(RelBuilder relBuilder, RexBuilder rexBuilder, RexSimplify simplify, RelMetadataQuery mq, AbstractMaterializedViewRule.MatchModality matchModality, boolean unionRewriting, RelNode input, Project topProject, RelNode node, Project topViewProject, RelNode viewNode, com.google.common.collect.BiMap<RexTableInputRef.RelTableRef,RexTableInputRef.RelTableRef> queryToViewTableMapping, AbstractMaterializedViewRule.EquivalenceClasses queryEC)
Rewrites the query using the given view query.-
Methods inherited from class org.apache.calcite.rel.rules.AbstractMaterializedViewRule
perform
-
Methods inherited from class org.apache.calcite.plan.RelOptRule
any, convert, convert, convertList, convertOperand, convertOperand, equals, equals, getOperand, getOperands, getOutConvention, getOutTrait, hashCode, matches, none, onMatch, operand, operand, operand, operand, operand, operandJ, operandJ, some, toString, unordered
-
-
-
-
Field Detail
-
SUPPORTED_DATE_TIME_ROLLUP_UNITS
private static final com.google.common.collect.ImmutableList<org.apache.calcite.avatica.util.TimeUnitRange> SUPPORTED_DATE_TIME_ROLLUP_UNITS
-
filterProjectTransposeRule
protected final RelOptRule filterProjectTransposeRule
Instance of rule to push filter through project.
-
filterAggregateTransposeRule
protected final RelOptRule filterAggregateTransposeRule
Instance of rule to push filter through aggregate.
-
aggregateProjectPullUpConstantsRule
protected final RelOptRule aggregateProjectPullUpConstantsRule
Instance of rule to pull up constants into aggregate.
-
projectMergeRule
protected final RelOptRule projectMergeRule
Instance of rule to merge project operators.
-
-
Constructor Detail
-
MaterializedViewAggregateRule
protected MaterializedViewAggregateRule(RelOptRuleOperand operand, RelBuilderFactory relBuilderFactory, java.lang.String description, boolean generateUnionRewriting, HepProgram unionRewritingPullProgram)
Creates a MaterializedViewAggregateRule.
-
-
Method Detail
-
isValidPlan
protected boolean isValidPlan(Project topProject, RelNode node, RelMetadataQuery mq)
- Specified by:
isValidPlan
in classAbstractMaterializedViewRule
-
compensateViewPartial
protected AbstractMaterializedViewRule.ViewPartialRewriting compensateViewPartial(RelBuilder relBuilder, RexBuilder rexBuilder, RelMetadataQuery mq, RelNode input, Project topProject, RelNode node, java.util.Set<RexTableInputRef.RelTableRef> queryTableRefs, AbstractMaterializedViewRule.EquivalenceClasses queryEC, Project topViewProject, RelNode viewNode, java.util.Set<RexTableInputRef.RelTableRef> viewTableRefs)
Description copied from class:AbstractMaterializedViewRule
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 classAbstractMaterializedViewRule
-
rewriteQuery
protected RelNode rewriteQuery(RelBuilder relBuilder, RexBuilder rexBuilder, RexSimplify simplify, RelMetadataQuery mq, RexNode compensationColumnsEquiPred, RexNode otherCompensationPred, Project topProject, RelNode node, com.google.common.collect.BiMap<RexTableInputRef.RelTableRef,RexTableInputRef.RelTableRef> queryToViewTableMapping, AbstractMaterializedViewRule.EquivalenceClasses viewEC, AbstractMaterializedViewRule.EquivalenceClasses queryEC)
Description copied from class:AbstractMaterializedViewRule
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 classAbstractMaterializedViewRule
-
createUnion
protected RelNode createUnion(RelBuilder relBuilder, RexBuilder rexBuilder, RelNode topProject, RelNode unionInputQuery, RelNode unionInputView)
Description copied from class:AbstractMaterializedViewRule
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 classAbstractMaterializedViewRule
-
rewriteView
protected RelNode rewriteView(RelBuilder relBuilder, RexBuilder rexBuilder, RexSimplify simplify, RelMetadataQuery mq, AbstractMaterializedViewRule.MatchModality matchModality, boolean unionRewriting, RelNode input, Project topProject, RelNode node, Project topViewProject, RelNode viewNode, com.google.common.collect.BiMap<RexTableInputRef.RelTableRef,RexTableInputRef.RelTableRef> queryToViewTableMapping, AbstractMaterializedViewRule.EquivalenceClasses queryEC)
Description copied from class:AbstractMaterializedViewRule
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 classAbstractMaterializedViewRule
-
generateMapping
protected com.google.common.collect.Multimap<java.lang.Integer,java.lang.Integer> generateMapping(RexBuilder rexBuilder, RexSimplify simplify, RelMetadataQuery mq, RelNode node, RelNode target, ImmutableBitSet positions, com.google.common.collect.BiMap<RexTableInputRef.RelTableRef,RexTableInputRef.RelTableRef> tableMapping, AbstractMaterializedViewRule.EquivalenceClasses sourceEC, java.util.List<RexNode> additionalExprs)
Mapping from node expressions to target expressions.If any of the expressions cannot be mapped, we return null.
-
getCeilSqlFunction
protected SqlFunction getCeilSqlFunction(org.apache.calcite.avatica.util.TimeUnitRange flag)
Get ceil function datetime.
-
getFloorSqlFunction
protected SqlFunction getFloorSqlFunction(org.apache.calcite.avatica.util.TimeUnitRange flag)
Get floor function datetime.
-
getRollup
protected SqlAggFunction getRollup(SqlAggFunction aggregation)
Get rollup aggregation function.
-
pushFilterToOriginalViewPlan
public Pair<RelNode,RelNode> pushFilterToOriginalViewPlan(RelBuilder builder, RelNode topViewProject, RelNode viewNode, RexNode cond)
Description copied from class:AbstractMaterializedViewRule
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 classAbstractMaterializedViewRule
-
-