Github user JoshRosen commented on a diff in the pull request:
https://github.com/apache/spark/pull/9038#discussion_r41671105
--- Diff:
sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/TungstenAggregationIterator.scala
---
@@ -288,17 +419,33 @@ class TungstenAggregationIterator(
val joinedRow = new JoinedRow()
val evalExpressions = allAggregateFunctions.map {
case ae: DeclarativeAggregate => ae.evaluateExpression
- // case agg: AggregateFunction2 => Literal.create(null,
agg.dataType)
+ case agg: AggregateFunction2 => NoOp
}
- val expressionAggEvalProjection =
UnsafeProjection.create(evalExpressions, bufferAttributes)
+ val expressionAggEvalProjection =
newMutableProjection(evalExpressions, bufferAttributes)()
// These are the attributes of the row produced by
`expressionAggEvalProjection`
val aggregateResultSchema = nonCompleteAggregateAttributes ++
completeAggregateAttributes
+ // TODO: Use unsafe row.
+ val aggregateResult = new
SpecificMutableRow(aggregateResultSchema.map(_.dataType))
+ expressionAggEvalProjection.target(aggregateResult)
val resultProjection =
UnsafeProjection.create(resultExpressions, groupingAttributes ++
aggregateResultSchema)
+ val allImperativeAggregateFunctions: Array[ImperativeAggregate] =
+ allImperativeAggregateFunctionPositions
+ .map(allAggregateFunctions)
+ .map(_.asInstanceOf[ImperativeAggregate])
+
(currentGroupingKey: UnsafeRow, currentBuffer: UnsafeRow) => {
// Generate results for all expression-based aggregate functions.
- val aggregateResult =
expressionAggEvalProjection.apply(currentBuffer)
+ expressionAggEvalProjection(currentBuffer)
+ // Generate results for all imperative aggregate functions.
+ var i = 0
+ while (i < allImperativeAggregateFunctions.length) {
+ aggregateResult.update(
--- End diff --
Oh, right; this was on my list of things to discuss. I think that we can
handle this by calling the specific setter methods because we happen to know
the data type. We might want to do this by building up an array of functions to
perform the update, similar to how we used to do things in
CatalystTypeConverters.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]