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
-
isDistinct
flag - 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 AggregateExpression
s with filters when requested to generateProcessRow.
AggregateMode¶
AggregateExpression
is given an AggregateMode
when created.
-
For
PartialMerge
orFinal
modes, the input to the AggregateFunction is immutable input aggregation buffers, and the actual children of theAggregateFunction
are not used -
AggregateExpressions of an AggregationIterator cannot have more than 2 distinct modes nor the modes be among
Partial
andPartialMerge
orFinal
andComplete
mode pairs -
Partial
andComplete
orPartialMerge
andFinal
pairs are supported
Complete¶
No prefix (in toString)
Used when:
ObjectAggregationIterator
is requested for the mergeAggregationBuffersTungstenAggregationIterator
is 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:
AggregateFunction
is requested to toAggregateExpressionAggUtils
is 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.