[GitHub] [spark] HeartSaVioR commented on a change in pull request #27019: [SPARK-30027][SQL] Support codegen for aggregate filters in HashAggregateExec

2020-01-26 Thread GitBox
HeartSaVioR 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_r371073779
 
 

 ##
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala
 ##
 @@ -329,6 +328,39 @@ case class HashAggregateExec(
 }
   }
 
+  private def generateEvalCodeForAggFuncs(
+  ctx: CodegenContext,
+  input: Seq[ExprCode],
+  inputAttrs: Seq[Attribute],
+  boundUpdateExprs: Seq[Seq[Expression]],
+  aggNames: Seq[String],
+  aggCodeBlocks: Seq[Block],
+  subExprs: SubExprCodes): String = {
+val aggCodes = if (conf.codegenSplitAggregateFunc &&
+  aggCodeBlocks.map(_.length).sum > conf.methodSplitThreshold) {
+  val maybeSplitCodes = splitAggregateExpressions(
+ctx, aggNames, boundUpdateExprs, aggCodeBlocks, subExprs.states)
+
+  maybeSplitCodes.getOrElse(aggCodeBlocks.map(_.code))
+} else {
+  aggCodeBlocks.map(_.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);
 
 Review comment:
   NOTE in above code comment would be enough to explain why, right? It still 
executes only once, but be able to exit the specific code block instead of 
exiting the function/method in the middle of the code.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] HeartSaVioR commented on a change in pull request #27019: [SPARK-30027][SQL] Support codegen for aggregate filters in HashAggregateExec

2020-01-26 Thread GitBox
HeartSaVioR 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_r371073779
 
 

 ##
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala
 ##
 @@ -329,6 +328,39 @@ case class HashAggregateExec(
 }
   }
 
+  private def generateEvalCodeForAggFuncs(
+  ctx: CodegenContext,
+  input: Seq[ExprCode],
+  inputAttrs: Seq[Attribute],
+  boundUpdateExprs: Seq[Seq[Expression]],
+  aggNames: Seq[String],
+  aggCodeBlocks: Seq[Block],
+  subExprs: SubExprCodes): String = {
+val aggCodes = if (conf.codegenSplitAggregateFunc &&
+  aggCodeBlocks.map(_.length).sum > conf.methodSplitThreshold) {
+  val maybeSplitCodes = splitAggregateExpressions(
+ctx, aggNames, boundUpdateExprs, aggCodeBlocks, subExprs.states)
+
+  maybeSplitCodes.getOrElse(aggCodeBlocks.map(_.code))
+} else {
+  aggCodeBlocks.map(_.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);
 
 Review comment:
   NOTE in above code comment would be enough to explain why, right? It still 
executes only once, but be able to exit the specific code block via `continue` 
instead of exiting the function/method in the middle of the code.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org



[GitHub] [spark] HeartSaVioR commented on a change in pull request #27019: [SPARK-30027][SQL] Support codegen for aggregate filters in HashAggregateExec

2019-12-26 Thread GitBox
HeartSaVioR 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_r361565199
 
 

 ##
 File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala
 ##
 @@ -153,9 +153,7 @@ case class HashAggregateExec(
 
   override def supportCodegen: Boolean = {
 // ImperativeAggregate and filter predicate are not supported right now
 
 Review comment:
   nit: Let's also update the comment here as well.


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:
us...@infra.apache.org


With regards,
Apache Git Services

-
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org