kiszk commented on a change in pull request #27019: [SPARK-30027][SQL] Support 
codegen for aggregate filters in HashAggregateExec
URL: https://github.com/apache/spark/pull/27019#discussion_r368258356
 
 

 ##########
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala
 ##########
 @@ -375,16 +373,30 @@ case class HashAggregateExec(
        """.stripMargin
     }
 
-    val codeToEvalAggFunc = if (conf.codegenSplitAggregateFunc &&
+    val codeToEvalAggFunc = {
+      val aggCodes = if (conf.codegenSplitAggregateFunc &&
         aggCodeBlocks.map(_.length).sum > conf.methodSplitThreshold) {
-      val maybeSplitCode = splitAggregateExpressions(
-        ctx, aggNames, boundUpdateExprs, aggCodeBlocks, subExprs.states)
+        val maybeSplitCodes = splitAggregateExpressions(
+          ctx, aggNames, boundUpdateExprs, aggCodeBlocks, subExprs.states)
 
-      maybeSplitCode.getOrElse {
-        aggCodeBlocks.fold(EmptyBlock)(_ + _).code
+        maybeSplitCodes.getOrElse(aggCodeBlocks.map(_.code))
+      } else {
+        aggCodeBlocks.map(_.code)
       }
-    } else {
-      aggCodeBlocks.fold(EmptyBlock)(_ + _).code
+
+      aggCodes.zip(aggregateExpressions.map(ae => (ae.mode, ae.filter))).map {
+        case (aggCode, (Partial | Complete, Some(condition))) =>
+          // Note: wrap in "do { } while(false);", so the generated checks can 
jump out
+          // with "continue;"
+          s"""
+             |do {
+             |  ${generatePredicateCode(ctx, condition, inputAttrs, input)}
+             |  $aggCode
+             |} while(false);
+         """.stripMargin
 
 Review comment:
   nit: indentation problem?

----------------------------------------------------------------
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]

Reply via email to