AggregateExpression¶
AggregateExpression is an unevaluable expression that acts as a container (wrapper) for an AggregateFunction.
Creating Instance¶
AggregateExpression takes the following to be created:
- AggregateFunction
- AggregateMode
-
isDistinctflag - Aggregate Filter Expression
- Result
ExprId
AggregateExpression is created using apply utility.
Aggregate Filter Expression¶
AggregateExpression can be given an Expression for an aggregate filter.
The filter is assumed undefined by default when AggregateExpression is created.
A filter is used in Partial and Complete modes only (cf. AggUtils).
AggregationIterator initializes predicates with AggregateExpressions with filters when requested to generateProcessRow.
AggregateMode¶
AggregateExpression is given an AggregateMode when created.
-
For
PartialMergeorFinalmodes, the input to the AggregateFunction is immutable input aggregation buffers, and the actual children of theAggregateFunctionare not used -
AggregateExpressions of an AggregationIterator cannot have more than 2 distinct modes nor the modes be among
PartialandPartialMergeorFinalandCompletemode pairs -
PartialandCompleteorPartialMergeandFinalpairs are supported
Complete¶
No prefix (in toString)
Used when:
ObjectAggregationIteratoris requested for the mergeAggregationBuffersTungstenAggregationIteratoris requested for the switchToSortBasedAggregation- others
Final¶
No prefix (in toString)
Partial¶
- Partial aggregation
partial_prefix (in toString)
PartialMerge¶
merge_prefix (in toString)
Creating AggregateExpression¶
apply(
aggregateFunction: AggregateFunction,
mode: AggregateMode,
isDistinct: Boolean,
filter: Option[Expression] = None): AggregateExpression
apply creates an AggregateExpression with an auto-generated ExprId.
apply is used when:
AggregateFunctionis requested to toAggregateExpressionAggUtilsis requested to planAggregateWithOneDistinct
Human-Friendly Textual Representation¶
toString: String
toString returns the following text:
[prefix][name]([args]) FILTER (WHERE [predicate])
toString converts the mode to a prefix.
| mode | prefix |
|---|---|
| Partial | partial_ |
| PartialMerge | merge_ |
| Final or Complete | (empty) |
toString requests the AggregateFunction for the toAggString (with the isDistinct flag).
In the end, toString adds FILTER (WHERE [predicate]) based on the optional filter expression.