Class Aggregate

All Implemented Interfaces:
Cloneable, RelOptNode, Hintable, RelNode
Direct Known Subclasses:
Bindables.BindableAggregate, ElasticsearchAggregate, EnumerableAggregateBase, GeodeAggregate, JdbcRules.JdbcAggregate, LogicalAggregate, MongoAggregate, PigAggregate

public abstract class Aggregate extends SingleRel implements Hintable
Relational operator that eliminates duplicates and computes totals.

It corresponds to the GROUP BY operator in a SQL query statement, together with the aggregate functions in the SELECT clause.

Rules:

  • Field Details

    • hints

      protected final com.google.common.collect.ImmutableList<RelHint> hints
    • IS_SIMPLE

      @Deprecated public static final com.google.common.base.Predicate<Aggregate> IS_SIMPLE
      Deprecated.
    • NO_INDICATOR

      @Deprecated public static final com.google.common.base.Predicate<Aggregate> NO_INDICATOR
      Deprecated.
    • IS_NOT_GRAND_TOTAL

      @Deprecated public static final com.google.common.base.Predicate<Aggregate> IS_NOT_GRAND_TOTAL
      Deprecated.
    • indicator

      @Deprecated public final boolean indicator
      Deprecated.
      See Also:
    • aggCalls

      protected final List<AggregateCall> aggCalls
    • groupSet

      protected final ImmutableBitSet groupSet
    • groupSets

      public final com.google.common.collect.ImmutableList<ImmutableBitSet> groupSets
  • Constructor Details

    • Aggregate

      protected Aggregate(RelOptCluster cluster, RelTraitSet traitSet, List<RelHint> hints, RelNode input, ImmutableBitSet groupSet, @Nullable List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls)
      Creates an Aggregate.

      All members of groupSets must be sub-sets of groupSet. For a simple GROUP BY, groupSets is a singleton list containing groupSet.

      It is allowed for groupSet to contain bits that are not in any of the groupSets, even this does not correspond to valid SQL. See discussion in RelBuilder.groupKey(ImmutableBitSet, Iterable).

      If GROUP BY is not specified, or equivalently if GROUP BY () is specified, groupSet will be the empty set, and groupSets will have one element, that empty set.

      If CUBE, ROLLUP or GROUPING SETS are specified, groupSets will have additional elements, but they must each be a subset of groupSet, and they must be sorted by inclusion: (0, 1, 2), (1), (0, 2), (0), ().

      Parameters:
      cluster - Cluster
      traitSet - Trait set
      hints - Hints of this relational expression
      input - Input relational expression
      groupSet - Bit set of grouping fields
      groupSets - List of all grouping sets; null for just groupSet
      aggCalls - Collection of calls to aggregate functions
    • Aggregate

      @Deprecated protected Aggregate(RelOptCluster cluster, RelTraitSet traitSet, RelNode input, ImmutableBitSet groupSet, List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls)
      Deprecated.
    • Aggregate

      @Deprecated protected Aggregate(RelOptCluster cluster, RelTraitSet traits, RelNode child, boolean indicator, ImmutableBitSet groupSet, List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls)
      Deprecated.
    • Aggregate

      protected Aggregate(RelInput input)
      Creates an Aggregate by parsing serialized output.
  • Method Details

    • isSimple

      public static boolean isSimple(Aggregate aggregate)
    • checkIndicator

      public static void checkIndicator(boolean indicator)
      Used internally; will removed when indicator is removed, before 2.0.
    • isNotGrandTotal

      public static boolean isNotGrandTotal(Aggregate aggregate)
    • noIndicator

      @Deprecated public static boolean noIndicator(Aggregate aggregate)
      Deprecated.
    • copy

      public final RelNode copy(RelTraitSet traitSet, List<RelNode> inputs)
      Description copied from interface: RelNode
      Creates a copy of this relational expression, perhaps changing traits and inputs.

      Sub-classes with other important attributes are encouraged to create variants of this method with more parameters.

      Specified by:
      copy in interface RelNode
      Overrides:
      copy in class AbstractRelNode
      Parameters:
      traitSet - Trait set
      inputs - Inputs
      Returns:
      Copy of this relational expression, substituting traits and inputs
    • copy

      public abstract Aggregate copy(RelTraitSet traitSet, RelNode input, ImmutableBitSet groupSet, @Nullable List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls)
      Creates a copy of this aggregate.
      Parameters:
      traitSet - Traits
      input - Input
      groupSet - Bit set of grouping fields
      groupSets - List of all grouping sets; null for just groupSet
      aggCalls - Collection of calls to aggregate functions
      Returns:
      New Aggregate if any parameter differs from the value of this Aggregate, or just this if all the parameters are the same
      See Also:
    • copy

      @Deprecated public Aggregate copy(RelTraitSet traitSet, RelNode input, boolean indicator, ImmutableBitSet groupSet, List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls)
      Deprecated.
    • getAggCallList

      public List<AggregateCall> getAggCallList()
      Returns a list of calls to aggregate functions.
      Returns:
      list of calls to aggregate functions
    • getNamedAggCalls

      public List<Pair<AggregateCall,String>> getNamedAggCalls()
      Returns a list of calls to aggregate functions together with their output field names.
      Returns:
      list of calls to aggregate functions and their output field names
    • getGroupCount

      public int getGroupCount()
      Returns the number of grouping fields. These grouping fields are the leading fields in both the input and output records.

      NOTE: The getGroupSet() data structure allows for the grouping fields to not be on the leading edge. New code should, if possible, assume that grouping fields are in arbitrary positions in the input relational expression.

      Returns:
      number of grouping fields
    • getIndicatorCount

      @Deprecated public int getIndicatorCount()
      Deprecated.
      Returns the number of indicator fields.

      Always zero.

      Returns:
      number of indicator fields, always zero
    • getGroupSet

      public ImmutableBitSet getGroupSet()
      Returns a bit set of the grouping fields.
      Returns:
      bit set of ordinals of grouping fields
    • getGroupSets

      public com.google.common.collect.ImmutableList<ImmutableBitSet> getGroupSets()
      Returns the list of grouping sets computed by this Aggregate.
      Returns:
      List of all grouping sets
    • explainTerms

      public RelWriter explainTerms(RelWriter pw)
      Description copied from class: AbstractRelNode
      Describes the inputs and attributes of this relational expression. Each node should call super.explainTerms, then call the RelWriter.input(String, RelNode) and RelWriter.item(String, Object) methods for each input and attribute.
      Overrides:
      explainTerms in class SingleRel
      Parameters:
      pw - Plan writer
      Returns:
      Plan writer for fluent-explain pattern
    • estimateRowCount

      public double estimateRowCount(RelMetadataQuery mq)
      Description copied from interface: RelNode
      Returns an estimate of the number of rows this relational expression will return.

      NOTE jvs 29-Mar-2006: Don't call this method directly. Instead, use RelMetadataQuery.getRowCount(org.apache.calcite.rel.RelNode), which gives plugins a chance to override the rel's default ideas about row count.

      Specified by:
      estimateRowCount in interface RelNode
      Overrides:
      estimateRowCount in class SingleRel
      Parameters:
      mq - Metadata query
      Returns:
      Estimate of the number of rows this relational expression will return
    • computeSelfCost

      public @Nullable RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq)
      Description copied from interface: RelNode
      Returns the cost of this plan (not including children). The base implementation throws an error; derived classes should override.

      NOTE jvs 29-Mar-2006: Don't call this method directly. Instead, use RelMetadataQuery.getNonCumulativeCost(org.apache.calcite.rel.RelNode), which gives plugins a chance to override the rel's default ideas about cost.

      Specified by:
      computeSelfCost in interface RelNode
      Overrides:
      computeSelfCost in class AbstractRelNode
      Parameters:
      planner - Planner for cost calculation
      mq - Metadata query
      Returns:
      Cost of this plan (not including children)
    • deriveRowType

      protected RelDataType deriveRowType()
      Overrides:
      deriveRowType in class SingleRel
    • deriveRowType

      public static RelDataType deriveRowType(RelDataTypeFactory typeFactory, RelDataType inputRowType, boolean indicator, ImmutableBitSet groupSet, @Nullable List<ImmutableBitSet> groupSets, List<AggregateCall> aggCalls)
      Computes the row type of an Aggregate before it exists.
      Parameters:
      typeFactory - Type factory
      inputRowType - Input row type
      indicator - Deprecated, always false
      groupSet - Bit set of grouping fields
      groupSets - List of all grouping sets; null for just groupSet
      aggCalls - Collection of calls to aggregate functions
      Returns:
      Row type of the aggregate
    • isValid

      public boolean isValid(Litmus litmus, @Nullable RelNode.Context context)
      Description copied from interface: RelNode
      Returns whether this relational expression is valid.

      If assertions are enabled, this method is typically called with litmus = THROW, as follows:

      assert rel.isValid(Litmus.THROW)

      This signals that the method can throw an AssertionError if it is not valid.

      Specified by:
      isValid in interface RelNode
      Overrides:
      isValid in class AbstractRelNode
      Parameters:
      litmus - What to do if invalid
      context - Context for validity checking
      Returns:
      Whether relational expression is valid
    • containsDistinctCall

      public boolean containsDistinctCall()
      Returns whether any of the aggregates are DISTINCT.
      Returns:
      Whether any of the aggregates are DISTINCT
    • getHints

      public com.google.common.collect.ImmutableList<RelHint> getHints()
      Description copied from interface: Hintable
      Returns the hints of this relational expressions as an immutable list.
      Specified by:
      getHints in interface Hintable
    • getGroupType

      public Aggregate.Group getGroupType()
      Returns the type of roll-up.
      Returns:
      Type of roll-up