rednaxelafx commented on a change in pull request #20965: [SPARK-21870][SQL]
Split aggregation code into small functions
URL: https://github.com/apache/spark/pull/20965#discussion_r316428843
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala
##########
@@ -844,9 +931,51 @@ case class HashAggregateExec(
|// update unsafe row buffer
|${updateUnsafeRowBuffer.mkString("\n").trim}
""".stripMargin
+ } else {
+ // We need to copy the aggregation row buffer to a local row first
because each aggregate
+ // function directly updates the buffer when it finishes.
+ val localRowBuffer = ctx.freshName("localUnsafeRowBuffer")
+ val initLocalRowBuffer = s"InternalRow $localRowBuffer =
$unsafeRowBuffer.copy();"
+
+ ctx.INPUT_ROW = localRowBuffer
+ val boundUpdateExpr = updateExpr.map(BindReferences.bindReference(_,
inputAttr))
+ val subExprs =
ctx.subexpressionEliminationForWholeStageCodegen(boundUpdateExpr)
+ val effectiveCodes = subExprs.codes.mkString("\n")
+ val unsafeRowBufferEvals =
ctx.withSubExprEliminationExprs(subExprs.states) {
+ boundUpdateExpr.map(_.genCode(ctx))
+ }
+
+ val evalAndUpdateCodes = unsafeRowBufferEvals.zipWithIndex.map { case
(ev, i) =>
+ val dt = updateExpr(i).dataType
+ val updateColumnCode =
+ CodeGenerator.updateColumn(unsafeRowBuffer, dt, i, ev,
updateExpr(i).nullable)
+ s"""
+ | // evaluate aggregate function
Review comment:
Ditto on leading space
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]