Package edu.caltech.nanodb.plannodes
Class GroupAggregateNode
- java.lang.Object
-
- edu.caltech.nanodb.plannodes.PlanNode
-
- edu.caltech.nanodb.plannodes.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 Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,FunctionCall>
aggregates
A list of one or more aggregate functions to compute over the input data.protected int
estimatedNumTuples
The estimated number of tuples this plan-node produces.protected java.util.List<Expression>
groupByExprs
A list of zero or more expressions that the grouping/aggregate node will use for generating aggregates over.protected Schema
inputSchema
The schema of the plan-node feeding this grouping/aggregate node.private static org.apache.logging.log4j.Logger
logger
A logging object for reporting anything interesting that happens.-
Fields inherited from class edu.caltech.nanodb.plannodes.PlanNode
cost, environment, leftChild, rightChild, schema, stats
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
GroupAggregateNode(PlanNode subplan, java.util.List<Expression> groupByExprs, java.util.Map<java.lang.String,FunctionCall> aggregates)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.protected TupleLiteral
evaluateGroupByExprs()
This helper method computes the value of each group-by expression and returns aTupleLiteral
containing the results.protected TupleLiteral
generateOutputTuple(TupleLiteral groupValues, java.util.Map<java.lang.String,FunctionCall> groupAggregates)
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.protected void
updateAggregates(java.util.Map<java.lang.String,FunctionCall> groupAggregates)
This helper method updates a collection of aggregate functions with values based on the state of the plan node's currentEnvironment
object.-
Methods inherited from class edu.caltech.nanodb.plannodes.PlanNode
addParentEnvironmentToPlanTree, cleanUp, clone, duplicate, equals, getCost, getEnvironment, getNextTuple, getSchema, getStats, hashCode, initialize, markCurrentPosition, prepare, printNodeTree, printNodeTree, printNodeTree, printNodeTreeToString, printNodeTreeToString, requiresLeftMarking, requiresRightMarking, resetToLastMark, resultsOrderedBy, setEnvironment, supportsMarking, toString
-
-
-
-
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 returnsnull
.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, ornull
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 currentEnvironment
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.
-
generateOutputTuple
protected TupleLiteral generateOutputTuple(TupleLiteral groupValues, java.util.Map<java.lang.String,FunctionCall> groupAggregates)
-
-