Class KuduMaterializedViewAggregateRule<C extends org.apache.calcite.rel.rules.materialize.MaterializedViewAggregateRule.Config>

java.lang.Object
org.apache.calcite.plan.RelOptRule
org.apache.calcite.plan.RelRule<C>
org.apache.calcite.rel.rules.materialize.KuduMaterializedViewRule<C>
org.apache.calcite.rel.rules.materialize.KuduMaterializedViewAggregateRule<C>
Type Parameters:
C - Configuration type
Direct Known Subclasses:
KuduMaterializedViewOnlyAggregateRule

public abstract class KuduMaterializedViewAggregateRule<C extends org.apache.calcite.rel.rules.materialize.MaterializedViewAggregateRule.Config> extends KuduMaterializedViewRule<C>
Materialized view rewriting for aggregate.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static interface 
    Rule configuration.

    Nested classes/interfaces inherited from class org.apache.calcite.plan.RelRule

    org.apache.calcite.plan.RelRule.Done, org.apache.calcite.plan.RelRule.MatchHandler<R extends org.apache.calcite.plan.RelOptRule>, org.apache.calcite.plan.RelRule.OperandBuilder, org.apache.calcite.plan.RelRule.OperandDetailBuilder<R extends org.apache.calcite.rel.RelNode>, org.apache.calcite.plan.RelRule.OperandTransform

    Nested classes/interfaces inherited from class org.apache.calcite.plan.RelOptRule

    org.apache.calcite.plan.RelOptRule.ConverterRelOptRuleOperand
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static final com.google.common.collect.ImmutableList<org.apache.calcite.avatica.util.TimeUnitRange>
     

    Fields inherited from class org.apache.calcite.plan.RelRule

    config

    Fields inherited from class org.apache.calcite.plan.RelOptRule

    description, operands, relBuilderFactory
  • Method Summary

    Modifier and Type
    Method
    Description
    compensateViewPartial(org.apache.calcite.tools.RelBuilder relBuilder, org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rel.metadata.RelMetadataQuery mq, org.apache.calcite.rel.RelNode input, @Nullable org.apache.calcite.rel.core.Project topProject, org.apache.calcite.rel.RelNode node, Set<org.apache.calcite.rex.RexTableInputRef.RelTableRef> queryTableRefs, KuduMaterializedViewRule.EquivalenceClasses queryEC, @Nullable org.apache.calcite.rel.core.Project topViewProject, org.apache.calcite.rel.RelNode viewNode, Set<org.apache.calcite.rex.RexTableInputRef.RelTableRef> viewTableRefs)
    It checks whether the query can be rewritten using the view even though the query uses additional tables.
    protected @Nullable org.apache.calcite.rel.RelNode
    createUnion(org.apache.calcite.tools.RelBuilder relBuilder, org.apache.calcite.rex.RexBuilder rexBuilder, @Nullable org.apache.calcite.rel.RelNode topProject, org.apache.calcite.rel.RelNode unionInputQuery, org.apache.calcite.rel.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 @Nullable com.google.common.collect.Multimap<Integer,Integer>
    generateMapping(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexSimplify simplify, org.apache.calcite.rel.metadata.RelMetadataQuery mq, org.apache.calcite.rel.RelNode node, org.apache.calcite.rel.RelNode target, org.apache.calcite.util.ImmutableBitSet positions, com.google.common.collect.BiMap<org.apache.calcite.rex.RexTableInputRef.RelTableRef,org.apache.calcite.rex.RexTableInputRef.RelTableRef> tableMapping, KuduMaterializedViewRule.EquivalenceClasses sourceEC, List<org.apache.calcite.rex.RexNode> additionalExprs)
    Mapping from node expressions to target expressions.
    protected org.apache.calcite.sql.SqlFunction
    getCeilSqlFunction(org.apache.calcite.avatica.util.TimeUnitRange flag)
    Get ceil function datetime.
    protected org.apache.calcite.sql.SqlFunction
    getFloorSqlFunction(org.apache.calcite.avatica.util.TimeUnitRange flag)
    Get floor function datetime.
    protected @Nullable org.apache.calcite.sql.SqlAggFunction
    getRollup(org.apache.calcite.sql.SqlAggFunction aggregation)
    Deprecated.
    protected boolean
    isValidPlan(@Nullable org.apache.calcite.rel.core.Project topProject, org.apache.calcite.rel.RelNode node, org.apache.calcite.rel.metadata.RelMetadataQuery mq)
     
    org.apache.calcite.util.Pair<@Nullable org.apache.calcite.rel.RelNode,org.apache.calcite.rel.RelNode>
    pushFilterToOriginalViewPlan(org.apache.calcite.tools.RelBuilder builder, @Nullable org.apache.calcite.rel.RelNode topViewProject, org.apache.calcite.rel.RelNode viewNode, org.apache.calcite.rex.RexNode cond)
    Once we create a compensation predicate, this method is responsible for pushing the resulting filter through the view nodes.
    protected @Nullable org.apache.calcite.rel.RelNode
    rewriteQuery(org.apache.calcite.tools.RelBuilder relBuilder, org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexSimplify simplify, org.apache.calcite.rel.metadata.RelMetadataQuery mq, org.apache.calcite.rex.RexNode compensationColumnsEquiPred, org.apache.calcite.rex.RexNode otherCompensationPred, @Nullable org.apache.calcite.rel.core.Project topProject, org.apache.calcite.rel.RelNode node, com.google.common.collect.BiMap<org.apache.calcite.rex.RexTableInputRef.RelTableRef,org.apache.calcite.rex.RexTableInputRef.RelTableRef> queryToViewTableMapping, KuduMaterializedViewRule.EquivalenceClasses viewEC, KuduMaterializedViewRule.EquivalenceClasses queryEC, boolean pushQueryFilter)
    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 org.apache.calcite.rel.RelNode
    rewriteView(org.apache.calcite.tools.RelBuilder relBuilder, org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexSimplify simplify, org.apache.calcite.rel.metadata.RelMetadataQuery mq, KuduMaterializedViewRule.MatchModality matchModality, boolean unionRewriting, org.apache.calcite.rel.RelNode input, @Nullable org.apache.calcite.rel.core.Project topProject, org.apache.calcite.rel.RelNode node, @Nullable org.apache.calcite.rel.core.Project topViewProject0, org.apache.calcite.rel.RelNode viewNode, com.google.common.collect.BiMap<org.apache.calcite.rex.RexTableInputRef.RelTableRef,org.apache.calcite.rex.RexTableInputRef.RelTableRef> queryToViewTableMapping, KuduMaterializedViewRule.EquivalenceClasses queryEC)
    Rewrites the query using the given view query.

    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

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • SUPPORTED_DATE_TIME_ROLLUP_UNITS

      protected static final com.google.common.collect.ImmutableList<org.apache.calcite.avatica.util.TimeUnitRange> SUPPORTED_DATE_TIME_ROLLUP_UNITS
  • Method Details

    • isValidPlan

      protected boolean isValidPlan(@Nullable org.apache.calcite.rel.core.Project topProject, org.apache.calcite.rel.RelNode node, org.apache.calcite.rel.metadata.RelMetadataQuery mq)
      Specified by:
      isValidPlan in class KuduMaterializedViewRule<C extends org.apache.calcite.rel.rules.materialize.MaterializedViewAggregateRule.Config>
    • compensateViewPartial

      protected @Nullable KuduMaterializedViewRule.ViewPartialRewriting compensateViewPartial(org.apache.calcite.tools.RelBuilder relBuilder, org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rel.metadata.RelMetadataQuery mq, org.apache.calcite.rel.RelNode input, @Nullable org.apache.calcite.rel.core.Project topProject, org.apache.calcite.rel.RelNode node, Set<org.apache.calcite.rex.RexTableInputRef.RelTableRef> queryTableRefs, KuduMaterializedViewRule.EquivalenceClasses queryEC, @Nullable org.apache.calcite.rel.core.Project topViewProject, org.apache.calcite.rel.RelNode viewNode, Set<org.apache.calcite.rex.RexTableInputRef.RelTableRef> viewTableRefs)
      Description copied from class: KuduMaterializedViewRule
      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 class KuduMaterializedViewRule<C extends org.apache.calcite.rel.rules.materialize.MaterializedViewAggregateRule.Config>
      Parameters:
      relBuilder - n/a
      rexBuilder - n/a
      mq - n/a
      input - n/a
      topProject - n/a
      node - n/a
      queryTableRefs - n/a
      queryEC - n/a
      topViewProject - n/a
      viewNode - n/a
      viewTableRefs - n/a
      Returns:
      ViewPartialRewriting, or null if the rewrite can't be done
    • rewriteQuery

      protected @Nullable org.apache.calcite.rel.RelNode rewriteQuery(org.apache.calcite.tools.RelBuilder relBuilder, org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexSimplify simplify, org.apache.calcite.rel.metadata.RelMetadataQuery mq, org.apache.calcite.rex.RexNode compensationColumnsEquiPred, org.apache.calcite.rex.RexNode otherCompensationPred, @Nullable org.apache.calcite.rel.core.Project topProject, org.apache.calcite.rel.RelNode node, com.google.common.collect.BiMap<org.apache.calcite.rex.RexTableInputRef.RelTableRef,org.apache.calcite.rex.RexTableInputRef.RelTableRef> queryToViewTableMapping, KuduMaterializedViewRule.EquivalenceClasses viewEC, KuduMaterializedViewRule.EquivalenceClasses queryEC, boolean pushQueryFilter)
      Description copied from class: KuduMaterializedViewRule
      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 class KuduMaterializedViewRule<C extends org.apache.calcite.rel.rules.materialize.MaterializedViewAggregateRule.Config>
      Parameters:
      relBuilder - n/a
      rexBuilder - n/a
      simplify - n/a
      mq - n/a
      compensationColumnsEquiPred - n/a
      otherCompensationPred - n/a
      topProject - n/a
      node - n/a
      queryToViewTableMapping - n/a
      viewEC - n/a
      queryEC - n/a
      pushQueryFilter - n/a
      Returns:
      n/a
    • createUnion

      protected @Nullable org.apache.calcite.rel.RelNode createUnion(org.apache.calcite.tools.RelBuilder relBuilder, org.apache.calcite.rex.RexBuilder rexBuilder, @Nullable org.apache.calcite.rel.RelNode topProject, org.apache.calcite.rel.RelNode unionInputQuery, org.apache.calcite.rel.RelNode unionInputView)
      Description copied from class: KuduMaterializedViewRule
      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 class KuduMaterializedViewRule<C extends org.apache.calcite.rel.rules.materialize.MaterializedViewAggregateRule.Config>
      Parameters:
      relBuilder - n/a
      rexBuilder - n/a
      topProject - n/a
      unionInputQuery - n/a
      unionInputView - n/a
      Returns:
      n/a
    • rewriteView

      protected @Nullable org.apache.calcite.rel.RelNode rewriteView(org.apache.calcite.tools.RelBuilder relBuilder, org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexSimplify simplify, org.apache.calcite.rel.metadata.RelMetadataQuery mq, KuduMaterializedViewRule.MatchModality matchModality, boolean unionRewriting, org.apache.calcite.rel.RelNode input, @Nullable org.apache.calcite.rel.core.Project topProject, org.apache.calcite.rel.RelNode node, @Nullable org.apache.calcite.rel.core.Project topViewProject0, org.apache.calcite.rel.RelNode viewNode, com.google.common.collect.BiMap<org.apache.calcite.rex.RexTableInputRef.RelTableRef,org.apache.calcite.rex.RexTableInputRef.RelTableRef> queryToViewTableMapping, KuduMaterializedViewRule.EquivalenceClasses queryEC)
      Description copied from class: KuduMaterializedViewRule
      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 class KuduMaterializedViewRule<C extends org.apache.calcite.rel.rules.materialize.MaterializedViewAggregateRule.Config>
      Parameters:
      relBuilder - n/a
      rexBuilder - n/a
      simplify - n/a
      mq - n/a
      matchModality - n/a
      unionRewriting - n/a
      input - n/a
      topProject - n/a
      node - n/a
      topViewProject0 - n/a
      viewNode - n/a
      queryToViewTableMapping - n/a
      queryEC - n/a
      Returns:
      n/a
    • generateMapping

      protected @Nullable com.google.common.collect.Multimap<Integer,Integer> generateMapping(org.apache.calcite.rex.RexBuilder rexBuilder, org.apache.calcite.rex.RexSimplify simplify, org.apache.calcite.rel.metadata.RelMetadataQuery mq, org.apache.calcite.rel.RelNode node, org.apache.calcite.rel.RelNode target, org.apache.calcite.util.ImmutableBitSet positions, com.google.common.collect.BiMap<org.apache.calcite.rex.RexTableInputRef.RelTableRef,org.apache.calcite.rex.RexTableInputRef.RelTableRef> tableMapping, KuduMaterializedViewRule.EquivalenceClasses sourceEC, List<org.apache.calcite.rex.RexNode> additionalExprs)
      Mapping from node expressions to target expressions.

      If any of the expressions cannot be mapped, we return null.

      Parameters:
      rexBuilder - n/a
      simplify - n/a
      mq - n/a
      node - n/a
      target - n/a
      positions - n/a
      tableMapping - n/a
      sourceEC - n/a
      additionalExprs - n/a
      Returns:
      n/a
    • getCeilSqlFunction

      protected org.apache.calcite.sql.SqlFunction getCeilSqlFunction(org.apache.calcite.avatica.util.TimeUnitRange flag)
      Get ceil function datetime.
      Parameters:
      flag - n/a
      Returns:
      n/a
    • getFloorSqlFunction

      protected org.apache.calcite.sql.SqlFunction getFloorSqlFunction(org.apache.calcite.avatica.util.TimeUnitRange flag)
      Get floor function datetime.
      Parameters:
      flag - n/a
      Returns:
      n/a
    • getRollup

      @Deprecated protected @Nullable org.apache.calcite.sql.SqlAggFunction getRollup(org.apache.calcite.sql.SqlAggFunction aggregation)
      Deprecated.
      Get rollup aggregation function.
      Parameters:
      aggregation - n/a
      Returns:
      n/a
    • pushFilterToOriginalViewPlan

      public org.apache.calcite.util.Pair<@Nullable org.apache.calcite.rel.RelNode,org.apache.calcite.rel.RelNode> pushFilterToOriginalViewPlan(org.apache.calcite.tools.RelBuilder builder, @Nullable org.apache.calcite.rel.RelNode topViewProject, org.apache.calcite.rel.RelNode viewNode, org.apache.calcite.rex.RexNode cond)
      Description copied from class: KuduMaterializedViewRule
      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 class KuduMaterializedViewRule<C extends org.apache.calcite.rel.rules.materialize.MaterializedViewAggregateRule.Config>
      Parameters:
      builder - n/a
      topViewProject - n/a
      viewNode - n/a
      cond - n/a
      Returns:
      n/a