Class GroupAggregateNode

  • All Implemented Interfaces:
    java.lang.Cloneable
    Direct Known Subclasses:
    HashedGroupAggregateNode, SortedGroupAggregateNode

    public abstract class GroupAggregateNode
    extends PlanNode
    This class provides the common functionality necessary for grouping and aggregation. Concrete subclasses implement grouping and aggregation using different strategies.
    • Field Detail

      • logger

        private static org.apache.logging.log4j.Logger logger
        A logging object for reporting anything interesting that happens.
      • inputSchema

        protected Schema inputSchema
        The schema of the plan-node feeding this grouping/aggregate node. We use it a lot, so it makes sense to have it cached.
      • groupByExprs

        protected java.util.List<Expression> groupByExprs
        A list of zero or more expressions that the grouping/aggregate node will use for generating aggregates over. If the list is empty then the aggregates will be computed over the entire input data-set.
      • aggregates

        protected java.util.Map<java.lang.String,​FunctionCall> aggregates
        A list of one or more aggregate functions to compute over the input data.
      • estimatedNumTuples

        protected int estimatedNumTuples
        The estimated number of tuples this plan-node produces. Cached to make plan-costing easier.
    • Constructor Detail

      • GroupAggregateNode

        protected GroupAggregateNode​(PlanNode subplan,
                                     java.util.List<Expression> groupByExprs,
                                     java.util.Map<java.lang.String,​FunctionCall> aggregates)
    • Method Detail

      • prepareSchemaStats

        protected void prepareSchemaStats()
        This helper function computes the schema of the grouping/aggregate plan-node, based on the schema of its child-plan, and also the expressions specified in the grouping/aggregate operation.
      • evaluateGroupByExprs

        protected TupleLiteral evaluateGroupByExprs()

        This helper method computes the value of each group-by expression and returns a TupleLiteral containing the results. If there are no group-by expressions (because the node is computing its aggregates over the entire input), the method returns null.

        This method uses the plan node's Environment object to evaluate the group-by expressions against; it expects that the environment has already been properly initialized before it is called.

        Returns:
        a TupleLiteral object containing the results of evaluating the group-by expressions, or null if there are no group-by expressions for this node.
      • clearAggregates

        protected void clearAggregates​(java.util.Map<java.lang.String,​FunctionCall> groupAggregates)
        This helper method iterates through a collection of aggregate functions, and clears (reinitializes) each aggregate's internal state.
        Parameters:
        groupAggregates - the collection of aggregates to clear
      • updateAggregates

        protected void updateAggregates​(java.util.Map<java.lang.String,​FunctionCall> groupAggregates)
                                 throws ExpressionException
        This helper method updates a collection of aggregate functions with values based on the state of the plan node's current Environment object. Of course, the method expects that the environment has already been properly initialized before it is called.
        Parameters:
        groupAggregates - the collection of aggregates to update
        Throws:
        ExpressionException - if an error is encountered while evaluating expressions for the aggregate operations.