Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ case class Aggregate(
resultAttribute: AttributeReference)

/** A list of aggregates that need to be computed for each group. */
@transient
private[this] lazy val computedAggregates = aggregateExpressions.flatMap { agg =>
private[this] val computedAggregates = aggregateExpressions.flatMap { agg =>
agg.collect {
case a: AggregateExpression =>
ComputedAggregate(
Expand All @@ -89,8 +88,7 @@ case class Aggregate(
}.toArray

/** The schema of the result of all aggregate evaluations */
@transient
private[this] lazy val computedSchema = computedAggregates.map(_.resultAttribute)
private[this] val computedSchema = computedAggregates.map(_.resultAttribute)

/** Creates a new aggregate buffer for a group. */
private[this] def newAggregateBuffer(): Array[AggregateFunction] = {
Expand All @@ -104,8 +102,7 @@ case class Aggregate(
}

/** Named attributes used to substitute grouping attributes into the final result. */
@transient
private[this] lazy val namedGroups = groupingExpressions.map {
private[this] val namedGroups = groupingExpressions.map {
case ne: NamedExpression => ne -> ne.toAttribute
case e => e -> Alias(e, s"groupingExpr:$e")().toAttribute
}
Expand All @@ -114,16 +111,14 @@ case class Aggregate(
* A map of substitutions that are used to insert the aggregate expressions and grouping
* expression into the final result expression.
*/
@transient
private[this] lazy val resultMap =
private[this] val resultMap =
(computedAggregates.map { agg => agg.unbound -> agg.resultAttribute } ++ namedGroups).toMap

/**
* Substituted version of aggregateExpressions expressions which are used to compute final
* output rows given a group and the result of all aggregate computations.
*/
@transient
private[this] lazy val resultExpressions = aggregateExpressions.map { agg =>
private[this] val resultExpressions = aggregateExpressions.map { agg =>
agg.transform {
case e: Expression if resultMap.contains(e) => resultMap(e)
}
Expand Down