Class Aggregate

    • Field Detail

      • 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

        public final boolean indicator
        Whether there are indicator fields.

        We strongly discourage the use indicator fields, because they cause the output row type of GROUPING SETS queries to be different from regular GROUP BY queries, and recommend that you set this field to false.

      • aggCalls

        protected final java.util.List<AggregateCall> aggCalls
      • groupSets

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

      • Aggregate

        protected Aggregate​(RelOptCluster cluster,
                            RelTraitSet traits,
                            RelNode child,
                            boolean indicator,
                            ImmutableBitSet groupSet,
                            java.util.List<ImmutableBitSet> groupSets,
                            java.util.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.

        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
        traits - Traits
        child - Child
        indicator - Whether row type should include indicator fields to indicate which grouping set is active; true is deprecated
        groupSet - Bit set of grouping fields
        groupSets - List of all grouping sets; null for just groupSet
        aggCalls - Collection of calls to aggregate functions
      • Aggregate

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

      • isNotGrandTotal

        public static boolean isNotGrandTotal​(Aggregate aggregate)
      • noIndicator

        public static boolean noIndicator​(Aggregate aggregate)
      • isPredicate

        private boolean isPredicate​(RelNode input,
                                    int index)
      • copy

        public final RelNode copy​(RelTraitSet traitSet,
                                  java.util.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,
                                       boolean indicator,
                                       ImmutableBitSet groupSet,
                                       java.util.List<ImmutableBitSet> groupSets,
                                       java.util.List<AggregateCall> aggCalls)
        Creates a copy of this aggregate.
        Parameters:
        traitSet - Traits
        input - Input
        indicator - Whether row type should include indicator fields to indicate which grouping set is active; must be true if aggregate is not simple
        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(org.apache.calcite.plan.RelTraitSet, java.util.List)
      • getAggCallList

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

        public java.util.List<Pair<AggregateCall,​java.lang.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

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

        This is the same as getGroupCount() if indicator is true, zero if indicator is false.

        The offset of the first aggregate call in the output record is always groupCount + indicatorCount.

        Returns:
        number of indicator fields
      • 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; null for just groupSet
      • deriveRowType

        public static RelDataType deriveRowType​(RelDataTypeFactory typeFactory,
                                                RelDataType inputRowType,
                                                boolean indicator,
                                                ImmutableBitSet groupSet,
                                                java.util.List<ImmutableBitSet> groupSets,
                                                java.util.List<AggregateCall> aggCalls)
        Computes the row type of an Aggregate before it exists.
        Parameters:
        typeFactory - Type factory
        inputRowType - Input row type
        indicator - Whether row type should include indicator fields to indicate which grouping set is active; must be true if aggregate is not simple
        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
      • allContain

        private static boolean allContain​(java.util.List<ImmutableBitSet> groupSets,
                                          int groupKey)
      • isValid

        public boolean isValid​(Litmus litmus,
                               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
      • typeMatchesInferred

        private boolean typeMatchesInferred​(AggregateCall aggCall,
                                            Litmus litmus)
        Returns whether the inferred type of an AggregateCall matches the type it was given when it was created.
        Parameters:
        aggCall - Aggregate call
        litmus - What to do if an error is detected (types do not match)
        Returns:
        Whether the inferred and declared types match
      • containsDistinctCall

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

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