You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by maropu <gi...@git.apache.org> on 2017/08/30 00:56:42 UTC

[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

GitHub user maropu opened a pull request:

    https://github.com/apache/spark/pull/19082

    [SPARK-21870][SQL] Split aggregation code into small functions for the HotSpot

    ## What changes were proposed in this pull request?
    This pr proposes to split aggregation code into pieces in `HashAggregateExec` for the JVM HotSpot.
    In #18810, we got performance regression if the HotSpot didn't compile too long functions (the limit is 80000 in bytecode size). I checked and I found the codegen of `HashAggregateExec` frequently goes over the limit, for example:
    
    ```
    spark.range(10000000).selectExpr("id % 1024 AS a", "id AS b").write.saveAsTable("t")
    sql("SELECT a, KURTOSIS(b)FROM t GROUP BY a")
    ```
    
    This query goes over the limit and the actual bytecode size is `12356`.
    This pr split the aggregation code into small separate functions and, in a simple example;
    
    ```
    sql("SELECT SUM(a), AVG(a) FROM VALUES(1) t(a)").debugCodegen
    ```
    
    - generated  code with this pr:
    ```
    /* 083 */   private void agg_doAggregateWithoutKey() throws java.io.IOException {
    /* 084 */     // initialize aggregation buffer
    /* 085 */     final long agg_value = -1L;
    /* 086 */     agg_bufIsNull = true;
    /* 087 */     agg_bufValue = agg_value;
    /* 088 */     boolean agg_isNull1 = false;
    /* 089 */     double agg_value1 = -1.0;
    /* 090 */     if (!false) {
    /* 091 */       agg_value1 = (double) 0;
    /* 092 */     }
    /* 093 */     agg_bufIsNull1 = agg_isNull1;
    /* 094 */     agg_bufValue1 = agg_value1;
    /* 095 */     agg_bufIsNull2 = false;
    /* 096 */     agg_bufValue2 = 0L;
    /* 097 */
    /* 098 */     while (inputadapter_input.hasNext() && !stopEarly()) {
    /* 099 */       InternalRow inputadapter_row = (InternalRow) inputadapter_input.next();
    /* 100 */       boolean inputadapter_isNull = inputadapter_row.isNullAt(0);
    /* 101 */       long inputadapter_value = inputadapter_isNull ? -1L : (inputadapter_row.getLong(0));
    /* 102 */       boolean inputadapter_isNull1 = inputadapter_row.isNullAt(1);
    /* 103 */       double inputadapter_value1 = inputadapter_isNull1 ? -1.0 : (inputadapter_row.getDouble(1));
    /* 104 */       boolean inputadapter_isNull2 = inputadapter_row.isNullAt(2);
    /* 105 */       long inputadapter_value2 = inputadapter_isNull2 ? -1L : (inputadapter_row.getLong(2));
    /* 106 */
    /* 107 */       // do aggregate
    /* 108 */       // copy aggregation buffer to the local
    /* 109 */       boolean agg_localBufIsNull = agg_bufIsNull;
    /* 110 */       long agg_localBufValue = agg_bufValue;
    /* 111 */       boolean agg_localBufIsNull1 = agg_bufIsNull1;
    /* 112 */       double agg_localBufValue1 = agg_bufValue1;
    /* 113 */       boolean agg_localBufIsNull2 = agg_bufIsNull2;
    /* 114 */       long agg_localBufValue2 = agg_bufValue2;
    /* 115 */       // common sub-expressions
    /* 116 */
    /* 117 */       // process aggregate functions to update aggregation buffer
    /* 118 */       agg_doAggregateVal_coalesce(agg_localBufIsNull, agg_localBufValue, inputadapter_value, inputadapter_isNull);
    /* 119 */       agg_doAggregateVal_add(agg_localBufValue1, inputadapter_isNull1, inputadapter_value1, agg_localBufIsNull1);
    /* 120 */       agg_doAggregateVal_add1(inputadapter_isNull2, inputadapter_value2, agg_localBufIsNull2, agg_localBufValue2);
    /* 121 */       if (shouldStop()) return;
    /* 122 */     }
    ```
    
    - generated code in the current master
    ```
    /* 083 */   private void agg_doAggregateWithoutKey() throws java.io.IOException {
    /* 084 */     // initialize aggregation buffer
    /* 085 */     final long agg_value = -1L;
    /* 086 */     agg_bufIsNull = true;
    /* 087 */     agg_bufValue = agg_value;
    /* 088 */     boolean agg_isNull1 = false;
    /* 089 */     double agg_value1 = -1.0;
    /* 090 */     if (!false) {
    /* 091 */       agg_value1 = (double) 0;
    /* 092 */     }
    /* 093 */     agg_bufIsNull1 = agg_isNull1;
    /* 094 */     agg_bufValue1 = agg_value1;
    /* 095 */     agg_bufIsNull2 = false;
    /* 096 */     agg_bufValue2 = 0L;
    /* 097 */
    /* 098 */     while (inputadapter_input.hasNext() && !stopEarly()) {
    /* 099 */       InternalRow inputadapter_row = (InternalRow) inputadapter_input.next();
    /* 100 */       boolean inputadapter_isNull = inputadapter_row.isNullAt(0);
    /* 101 */       long inputadapter_value = inputadapter_isNull ? -1L : (inputadapter_row.getLong(0));
    /* 102 */       boolean inputadapter_isNull1 = inputadapter_row.isNullAt(1);
    /* 103 */       double inputadapter_value1 = inputadapter_isNull1 ? -1.0 : (inputadapter_row.getDouble(1));
    /* 104 */       boolean inputadapter_isNull2 = inputadapter_row.isNullAt(2);
    /* 105 */       long inputadapter_value2 = inputadapter_isNull2 ? -1L : (inputadapter_row.getLong(2));
    /* 106 */
    /* 107 */       // do aggregate
    /* 108 */       // common sub-expressions
    /* 109 */
    /* 110 */       // evaluate aggregate function
    /* 111 */       boolean agg_isNull12 = true;
    /* 112 */       long agg_value12 = -1L;
    /* 113 */
    /* 114 */       boolean agg_isNull13 = agg_bufIsNull;
    /* 115 */       long agg_value13 = agg_bufValue;
    /* 116 */       if (agg_isNull13) {
    /* 117 */         boolean agg_isNull15 = false;
    /* 118 */         long agg_value15 = -1L;
    /* 119 */         if (!false) {
    /* 120 */           agg_value15 = (long) 0;
    /* 121 */         }
    /* 122 */         if (!agg_isNull15) {
    /* 123 */           agg_isNull13 = false;
    /* 124 */           agg_value13 = agg_value15;
    /* 125 */         }
    /* 126 */       }
    /* 127 */
    /* 128 */       if (!inputadapter_isNull) {
    /* 129 */         agg_isNull12 = false; // resultCode could change nullability.
    /* 130 */         agg_value12 = agg_value13 + inputadapter_value;
    /* 131 */
    /* 132 */       }
    /* 133 */       boolean agg_isNull11 = agg_isNull12;
    /* 134 */       long agg_value11 = agg_value12;
    /* 135 */       if (agg_isNull11) {
    /* 136 */         if (!agg_bufIsNull) {
    /* 137 */           agg_isNull11 = false;
    /* 138 */           agg_value11 = agg_bufValue;
    /* 139 */         }
    /* 140 */       }
    /* 141 */       boolean agg_isNull19 = true;
    /* 142 */       double agg_value19 = -1.0;
    /* 143 */
    /* 144 */       if (!agg_bufIsNull1) {
    /* 145 */         if (!inputadapter_isNull1) {
    /* 146 */           agg_isNull19 = false; // resultCode could change nullability.
    /* 147 */           agg_value19 = agg_bufValue1 + inputadapter_value1;
    /* 148 */
    /* 149 */         }
    /* 150 */
    /* 151 */       }
    /* 152 */       boolean agg_isNull22 = true;
    /* 153 */       long agg_value22 = -1L;
    /* 154 */
    /* 155 */       if (!agg_bufIsNull2) {
    /* 156 */         if (!inputadapter_isNull2) {
    /* 157 */           agg_isNull22 = false; // resultCode could change nullability.
    /* 158 */           agg_value22 = agg_bufValue2 + inputadapter_value2;
    /* 159 */
    /* 160 */         }
    /* 161 */
    /* 162 */       }
    /* 163 */       // update aggregation buffer
    /* 164 */       agg_bufIsNull = agg_isNull11;
    /* 165 */       agg_bufValue = agg_value11;
    /* 166 */
    /* 167 */       agg_bufIsNull1 = agg_isNull19;
    /* 168 */       agg_bufValue1 = agg_value19;
    /* 169 */
    /* 170 */       agg_bufIsNull2 = agg_isNull22;
    /* 171 */       agg_bufValue2 = agg_value22;
    /* 172 */       if (shouldStop()) return;
    /* 173 */     }
    /* 174 */
    /* 175 */   }
    /* 176 */
    /* 177 */ }
    ```
    
    ## How was this patch tested?
    Added tests in `WholeStageCodegenSuite`.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/maropu/spark SPARK-21870

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/spark/pull/19082.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #19082
    
----
commit 6dacad4e6d0f588ce6f02e33da9625cc9ea116aa
Author: Takeshi Yamamuro <ya...@apache.org>
Date:   2017-08-28T12:46:00Z

    Split aggregation into small functions

----


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/81235/
    Test FAILed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #84770 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84770/testReport)** for PR 19082 at commit [`0e5d366`](https://github.com/apache/spark/commit/0e5d366dfce50ec3f879193f78c6a77213680926).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Aha, I feel fair enough. Based the insight, there is one of solutions to make the wholestage codegen consider #calls of gen'd functions though, it seems the approach is not simple. So, splitting functions step-by-step is a preferred approach now...


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by srowen <gi...@git.apache.org>.
Github user srowen commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Yes no need for a back-and-forth. @gatorsmile I think it's reasonable to ask for a little more detail on your comment.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    > You know, when we disable the whole-stage codegen, we still do the expression codegen, whose byte code size is smaller than 8K at most cases. Thus, it could be faster than whole-stage codegen. That is why we saw the performance difference in the PR #18810
    
    I think the case disabled wholestage codegen is faster than wholestage codegen is only happened when the methods of wholestage codegen are not compiled, right? Once the methods are compiled, I'm doubt that we will see performance regression when wholestage codegen enabled.



---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Basically, cutting is to decide the boundaries of `blocking loop`.
    
    @kiszk and @rednaxelafx can explain what I said above better. This is related to how JVM works and how whole-stage codegen works  


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by kiszk <gi...@git.apache.org>.
Github user kiszk commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    I agree with you. #18810 compares the following two code.
    1. Interpreter execution of Java code by whole-stage codegen with passing row data in scalar values
    2. JITted execution of Java code by expression codegen with passing row data using iterator
    
    In the above case, 1. is slower than 2. due to the advantage of JIT compilation.
    
    #18931 can cut the boundary of whole-stage operators. *Hopefully*, this cutting makes the byte code size smaller. #19082 can encourage this assumption.  
    Do you want add a feature to disable whole-stage codegen if JVM bytecode size of one of cut methods is larger than 8KB after applying cutting at the boundary of whole-stage operators?
    



---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test FAILed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #81328 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81328/testReport)** for PR 19082 at commit [`78d0a00`](https://github.com/apache/spark/commit/78d0a00eb209aae54383050dd1134d9d4db635d2).


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    I checked the TPCDS performance;
    https://docs.google.com/spreadsheets/d/1DJP8BC8aOE4Fp8t9XAYki0vauCTowt2D1n7lmNXI7xw/edit?usp=sharing
    Q66 is explicitly faster and the other queries are almost the same with the previous ones.



---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test FAILed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    ping


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    I checked `q66` has two warnings on the current master(83488cc3180ca18f829516f550766efb3095881e);
    ```
    17/10/06 07:32:26 INFO WholeStageCodegenExec: Found too long generated codes and JIT optimization might not work: the bytecode size (13420) is above the limit 8000, and the whole-stage codegen was disabled for this plan. To avoid this, you can raise the limit `spark.sql.codegen.hugeMethodLimit`:
    17/10/06 07:37:51 INFO WholeStageCodegenExec: Found too long generated codes and JIT optimization might not work: the bytecode size (16634) is above the limit 15000, and the whole-stage codegen was disabled for this plan. To avoid this, you can raise the limit `spark.sql.codegen.hugeMethodLimit`:
    ```
    
    So, I run bench with `hugeMethodLimit=8000 or 20000`;
    
    ```
    OpenJDK 64-Bit Server VM 1.8.0_141-b16 on Linux 4.9.38-16.35.amzn1.x86_64
    Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
    TPCDS Snappy:                            Best/Avg Time(ms)    Rate(M/s)   Per Row(ns)   Relative
    ------------------------------------------------------------------------------------------------
    q66 (hugeMethodLimit=8000)                  15905 / 15990          0.7        1452.0       1.0X
    
    
    OpenJDK 64-Bit Server VM 1.8.0_141-b16 on Linux 4.9.38-16.35.amzn1.x86_64
    Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
    TPCDS Snappy:                            Best/Avg Time(ms)    Rate(M/s)   Per Row(ns)   Relative
    ------------------------------------------------------------------------------------------------
    q66 (hugeMethodLimit=20000)                   7524 / 7638          1.5         686.9       1.0X
    ```
    



---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r156092874
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -863,25 +984,43 @@ case class HashAggregateExec(
         }
     
         val updateRowInUnsafeRowMap: String = {
    -      ctx.INPUT_ROW = unsafeRowBuffer
    +      // 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 updateUnsafeRowBuffer = unsafeRowBufferEvals.zipWithIndex.map { case (ev, i) =>
    +
    +      val evalAndUpdateCodes = unsafeRowBufferEvals.zipWithIndex.map { case (ev, i) =>
             val dt = updateExpr(i).dataType
    -        ctx.updateColumn(unsafeRowBuffer, dt, i, ev, updateExpr(i).nullable)
    +        val updateColumnCode = ctx.updateColumn(unsafeRowBuffer, dt, i, ev, updateExpr(i).nullable)
    +        s"""
    +           | // evaluate aggregate function
    +           | ${ev.code}
    +           | // update unsafe row buffer
    +           | $updateColumnCode
    +         """.stripMargin
           }
    +
    +      val updateAggValCode = splitAggregateExpressions(
    +        ctx, boundUpdateExpr, evalAndUpdateCodes, subExprs.states,
    +        Seq(("InternalRow", unsafeRowBuffer)))
    --- End diff --
    
    Need more indents here?


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/84774/
    Test PASSed.


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r143897031
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -244,6 +246,89 @@ case class HashAggregateExec(
     
       protected override val shouldStopRequired = false
     
    +  // Extracts all the input variable references for a given `aggExpr`. This result will be used
    +  // to split aggregation into small functions.
    +  private def getInputVariableReferences(
    +      ctx: CodegenContext,
    +      aggExpr: Expression,
    +      subExprs: Map[Expression, SubExprEliminationState]): Set[(String, String)] = {
    +    // `argSet` collects all the pairs of variable names and their types, the first in the pair is
    +    // a type name and the second is a variable name.
    +    val argSet = mutable.Set[(String, String)]()
    +    val stack = mutable.Stack[Expression](aggExpr)
    +    while (stack.nonEmpty) {
    +      stack.pop() match {
    +        case e if subExprs.contains(e) =>
    +          val exprCode = subExprs(e)
    +          if (CodegenContext.isJavaIdentifier(exprCode.value)) {
    +            argSet += ((ctx.javaType(e.dataType), exprCode.value))
    +          }
    +          if (CodegenContext.isJavaIdentifier(exprCode.isNull)) {
    +            argSet += (("boolean", exprCode.isNull))
    +          }
    +          // Since the children possibly has common expressions, we push them here
    +          stack.pushAll(e.children)
    +        case ref: BoundReference
    +            if ctx.currentVars != null && ctx.currentVars(ref.ordinal) != null =>
    +          val value = ctx.currentVars(ref.ordinal).value
    +          val isNull = ctx.currentVars(ref.ordinal).isNull
    +          if (CodegenContext.isJavaIdentifier(value)) {
    +            argSet += ((ctx.javaType(ref.dataType), value))
    +          }
    +          if (CodegenContext.isJavaIdentifier(isNull)) {
    +            argSet += (("boolean", isNull))
    +          }
    +        case _: BoundReference =>
    +          argSet += (("InternalRow", ctx.INPUT_ROW))
    +        case e =>
    +          stack.pushAll(e.children)
    +      }
    +    }
    +
    +    argSet.toSet
    +  }
    +
    +  // Splits the aggregation into small functions because the HotSpot does not compile
    +  // too long functions.
    +  private def splitAggregateExpressions(
    +      ctx: CodegenContext,
    +      aggExprs: Seq[Expression],
    +      evalAndUpdateCodes: Seq[String],
    +      subExprs: Map[Expression, SubExprEliminationState],
    +      otherArgs: Seq[(String, String)] = Seq.empty): Seq[String] = {
    +    aggExprs.zipWithIndex.map { case (aggExpr, i) =>
    +      // The maximum number of parameters in non-static Java methods is 254, so this method gives
    +      // up splitting the code if the number goes over the limit.
    +      // You can find more information about the limit in the JVM specification:
    +      //   - The number of method parameters is limited to 255 by the definition of a method
    --- End diff --
    
    I just fixed the code to give up splitting if the length goes over 127 because IIUC the current implemented aggregate functions in spark do not go over the limit. I feel it is some complicated to check types there...


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/84126/
    Test PASSed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Either way, I think we first need to know why the regression on `q66` happens when turning off wholestage codegen. We first thought turning off too-long functions had better performance, but it is not always true. Also, we better know if this regression happens on other JVM impls, too. Next, I'll look into these issues.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #82498 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/82498/testReport)** for PR 19082 at commit [`a95816c`](https://github.com/apache/spark/commit/a95816c07146e8a15910abca62573f0ba7fd32e2).
     * This patch **fails due to an unknown error code, -9**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    >In the above case, 1. is slower than 2. due to the advantage of JIT compilation.
    >#18931 can cut the boundary of whole-stage operators. Hopefully, this cutting makes the byte code size smaller than current aggressive embedding...
    
    That is correct to me. 
    
    > #18931 is not what we want, although it can partially resolves some issues. Simply disabling the whole-stage codegen after the cut might still trigger the regression like Q66.
    
    The regression of Q66 is explained in previous comment: https://github.com/apache/spark/pull/19082#issuecomment-335340888. A hot method which can't be compiled can cause regression. I think the split operator functions are hot methods for sure, if they can't be compiled, disabling wholestage codegen should not bring regreesion IMO.



---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    @kiszk Thanks for explanation! It sounds reasonable behavior by JIT compiler.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/83981/
    Test FAILed.


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r156002134
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -863,25 +984,43 @@ case class HashAggregateExec(
         }
     
         val updateRowInUnsafeRowMap: String = {
    -      ctx.INPUT_ROW = unsafeRowBuffer
    +      // 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 updateUnsafeRowBuffer = unsafeRowBufferEvals.zipWithIndex.map { case (ev, i) =>
    +
    +      val evalAndUpdateCodes = unsafeRowBufferEvals.zipWithIndex.map { case (ev, i) =>
             val dt = updateExpr(i).dataType
    -        ctx.updateColumn(unsafeRowBuffer, dt, i, ev, updateExpr(i).nullable)
    +        val updateColumnCode = ctx.updateColumn(unsafeRowBuffer, dt, i, ev, updateExpr(i).nullable)
    +        s"""
    +           | // evaluate aggregate function
    +           | ${ev.code}
    +           | // update unsafe row buffer
    +           | $updateColumnCode
    +         """.stripMargin
           }
    +
    +      val updateAggValCode = splitAggregateExpressions(
    +        ctx, boundUpdateExpr, evalAndUpdateCodes, subExprs.states,
    +        Seq(("InternalRow", unsafeRowBuffer)))
    --- End diff --
    
    indents.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #84807 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84807/testReport)** for PR 19082 at commit [`2555e5a`](https://github.com/apache/spark/commit/2555e5a3eb1223a19f3f523abc7c1e5a9251e528).


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #84126 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84126/testReport)** for PR 19082 at commit [`8bae975`](https://github.com/apache/spark/commit/8bae975ebfe56745b626b39b2b430269e5a2b1ca).


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by kiszk <gi...@git.apache.org>.
Github user kiszk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r143216395
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala ---
    @@ -944,6 +945,24 @@ class CodegenContext {
       }
     }
     
    +object CodegenContext {
    +
    +  private val javaKeywords = Set(
    --- End diff --
    
    Do we need add `enum`?


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    I don't think `spark.sql.codegen.hugeMethodLimit` is the same level thing as #18931 or this PR.
    
    `hugeMethodLimit` didn't do anything to affect how generated codes are split.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    TPC-DS benchmark just shows the perf of one of the Spark workloads. To avoid introducing the unexpected regressions, we have to be very careful when merging this PR and https://github.com/apache/spark/pull/18931, unless we fully understand all the impacts inside JVM. 
    
    In the community, we have two JVM experts @kiszk @rednaxelafx who developed features/fixes in JVM. 
    
    Q66 is a good example for us to do more investigation. 


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #84734 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84734/testReport)** for PR 19082 at commit [`0e5d366`](https://github.com/apache/spark/commit/0e5d366dfce50ec3f879193f78c6a77213680926).
     * This patch **fails SparkR unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r179391181
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -257,6 +259,78 @@ case class HashAggregateExec(
          """.stripMargin
       }
     
    +  // Extracts all the input variable references for a given `aggExpr`. This result will be used
    +  // to split aggregation into small functions.
    +  private def getInputVariableReferences(
    +      context: CodegenContext,
    +      aggregateExpression: Expression,
    +      subExprs: Map[Expression, SubExprEliminationState]): Set[(String, String)] = {
    +    // `argSet` collects all the pairs of variable names and their types, the first in the pair is
    +    // a type name and the second is a variable name.
    +    val argSet = mutable.Set[(String, String)]()
    +    val stack = mutable.Stack[Expression](aggregateExpression)
    +    while (stack.nonEmpty) {
    +      stack.pop() match {
    +        case e if subExprs.contains(e) =>
    +          val exprCode = subExprs(e)
    +          if (CodegenContext.isJavaIdentifier(exprCode.value)) {
    --- End diff --
    
    hey, good news! Thanks for letting me know ;)


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by rednaxelafx <gi...@git.apache.org>.
Github user rednaxelafx commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r179367236
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -257,6 +259,78 @@ case class HashAggregateExec(
          """.stripMargin
       }
     
    +  // Extracts all the input variable references for a given `aggExpr`. This result will be used
    +  // to split aggregation into small functions.
    +  private def getInputVariableReferences(
    +      context: CodegenContext,
    +      aggregateExpression: Expression,
    +      subExprs: Map[Expression, SubExprEliminationState]): Set[(String, String)] = {
    +    // `argSet` collects all the pairs of variable names and their types, the first in the pair is
    +    // a type name and the second is a variable name.
    +    val argSet = mutable.Set[(String, String)]()
    +    val stack = mutable.Stack[Expression](aggregateExpression)
    +    while (stack.nonEmpty) {
    +      stack.pop() match {
    +        case e if subExprs.contains(e) =>
    +          val exprCode = subExprs(e)
    +          if (CodegenContext.isJavaIdentifier(exprCode.value)) {
    --- End diff --
    
    Once we have @viirya 's https://github.com/apache/spark/pull/20043 merged we won't need the ugly `CodegenContext.isJavaIdentifier` hack any more >_<|||


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Also, I checked the performance of the master + this pr;
    ```
    OpenJDK 64-Bit Server VM 1.8.0_141-b16 on Linux 4.9.38-16.35.amzn1.x86_64
    Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
    TPCDS Snappy:                            Best/Avg Time(ms)    Rate(M/s)   Per Row(ns)   Relative
    ------------------------------------------------------------------------------------------------
    q66 (hugeMethodLimit=8000, w/this pr)         2107 / 2217          5.2         192.3       1.0X
    ``` 


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by kiszk <gi...@git.apache.org>.
Github user kiszk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r143895917
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -244,6 +246,89 @@ case class HashAggregateExec(
     
       protected override val shouldStopRequired = false
     
    +  // Extracts all the input variable references for a given `aggExpr`. This result will be used
    +  // to split aggregation into small functions.
    +  private def getInputVariableReferences(
    +      ctx: CodegenContext,
    +      aggExpr: Expression,
    +      subExprs: Map[Expression, SubExprEliminationState]): Set[(String, String)] = {
    +    // `argSet` collects all the pairs of variable names and their types, the first in the pair is
    +    // a type name and the second is a variable name.
    +    val argSet = mutable.Set[(String, String)]()
    +    val stack = mutable.Stack[Expression](aggExpr)
    +    while (stack.nonEmpty) {
    +      stack.pop() match {
    +        case e if subExprs.contains(e) =>
    +          val exprCode = subExprs(e)
    +          if (CodegenContext.isJavaIdentifier(exprCode.value)) {
    +            argSet += ((ctx.javaType(e.dataType), exprCode.value))
    +          }
    +          if (CodegenContext.isJavaIdentifier(exprCode.isNull)) {
    +            argSet += (("boolean", exprCode.isNull))
    +          }
    +          // Since the children possibly has common expressions, we push them here
    +          stack.pushAll(e.children)
    +        case ref: BoundReference
    +            if ctx.currentVars != null && ctx.currentVars(ref.ordinal) != null =>
    +          val value = ctx.currentVars(ref.ordinal).value
    +          val isNull = ctx.currentVars(ref.ordinal).isNull
    +          if (CodegenContext.isJavaIdentifier(value)) {
    +            argSet += ((ctx.javaType(ref.dataType), value))
    +          }
    +          if (CodegenContext.isJavaIdentifier(isNull)) {
    +            argSet += (("boolean", isNull))
    +          }
    +        case _: BoundReference =>
    +          argSet += (("InternalRow", ctx.INPUT_ROW))
    +        case e =>
    +          stack.pushAll(e.children)
    +      }
    +    }
    +
    +    argSet.toSet
    +  }
    +
    +  // Splits the aggregation into small functions because the HotSpot does not compile
    +  // too long functions.
    +  private def splitAggregateExpressions(
    +      ctx: CodegenContext,
    +      aggExprs: Seq[Expression],
    +      evalAndUpdateCodes: Seq[String],
    +      subExprs: Map[Expression, SubExprEliminationState],
    +      otherArgs: Seq[(String, String)] = Seq.empty): Seq[String] = {
    +    aggExprs.zipWithIndex.map { case (aggExpr, i) =>
    +      // The maximum number of parameters in non-static Java methods is 254, so this method gives
    +      // up splitting the code if the number goes over the limit.
    +      // You can find more information about the limit in the JVM specification:
    +      //   - The number of method parameters is limited to 255 by the definition of a method
    --- End diff --
    
    @a10y Good catch. You are right. We have 254 slots. Each Long or double takes two slots.
    We need to check type of parameters, too. cc: @maropu, @viirya 


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r143218854
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala ---
    @@ -944,6 +945,24 @@ class CodegenContext {
       }
     }
     
    +object CodegenContext {
    +
    +  private val javaKeywords = Set(
    --- End diff --
    
    cc:  @rednaxelafx


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/84717/
    Test FAILed.


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r136500779
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -244,6 +246,92 @@ case class HashAggregateExec(
     
       protected override val shouldStopRequired = false
     
    +  // We assume a prefix has lower cases and a name has camel cases
    +  private val variableName = "^[a-z]+_[a-zA-Z]+[0-9]*".r
    +
    +  // Returns true if a given name id belongs to this `CodegenContext`
    +  private def isVariable(nameId: String): Boolean = nameId match {
    +    case variableName() => true
    +    case _ => false
    +  }
    +
    +  // Extracts all the outer references for a given `aggExpr`. This result will be used to split
    +  // aggregation into small functions.
    +  private def getOuterReferences(
    --- End diff --
    
    `OuterReference` actually has special meaning in correlated subquery. This name can be confusing.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/81354/
    Test PASSed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #84774 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84774/testReport)** for PR 19082 at commit [`4077608`](https://github.com/apache/spark/commit/4077608c47bc5059b3e00aa882362829d729476b).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/84807/
    Test PASSed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test PASSed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    If you really can't or don't willing to explain, we can wait for @kiszk or @rednaxelafx to explain it.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #81235 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81235/testReport)** for PR 19082 at commit [`6dacad4`](https://github.com/apache/spark/commit/6dacad4e6d0f588ce6f02e33da9625cc9ea116aa).
     * This patch **fails SparkR unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r143359416
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -797,26 +904,44 @@ case class HashAggregateExec(
     
     
         def updateRowInFastHashMap(isVectorized: Boolean): Option[String] = {
    -      ctx.INPUT_ROW = fastRowBuffer
    +      // 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("localFastRowBuffer")
    +      val initLocalRowBuffer = s"InternalRow $localRowBuffer = $fastRowBuffer.copy();"
    --- End diff --
    
    I just passed the local variable as each function argument;
    ```
    /* 329 */         // do aggregate
    /* 330 */         // copy aggregation row buffer to the local
    /* 331 */         InternalRow agg_localFastRowBuffer = agg_fastAggBuffer.copy();
    /* 332 */         // common sub-expressions
    /* 333 */         boolean agg_isNull27 = false;
    /* 334 */         long agg_value30 = -1L;
    /* 335 */         if (!false) {
    /* 336 */           agg_value30 = (long) inputadapter_value;
    /* 337 */         }
    /* 338 */         // process aggregate functions to update aggregation buffer
    /* 339 */         agg_doAggregateVal_add2(inputadapter_value, agg_value30, agg_fastAggBuffer, agg_localFastRowBuffer, agg_isNull27);
    /* 340 */         agg_doAggregateVal_add3(inputadapter_value, agg_value30, agg_fastAggBuffer, agg_localFastRowBuffer, agg_isNull27);
    /* 341 */         agg_doAggregateVal_if1(inputadapter_value, agg_value30, agg_fastAggBuffer, agg_localFastRowBuffer, agg_isNull27);
    /* 342 */
    ```
    Since each split function directly updates an input row, we need to copy it to the local so that all the split functions can reference the old state.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    You know, when we disable the whole-stage codegen, we still do the expression codegen, which byte code size is smaller than 8K at most cases. Thus, it could be faster than whole-stage codegen. That is why we saw the performance difference in the PR https://github.com/apache/spark/pull/18810 
    
    If we can cut the boundary of operators better, we still can make the byte code size smaller than 8K. That means, we are not completely disabling the whole-stage codegen. 


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #83982 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/83982/testReport)** for PR 19082 at commit [`4c2816b`](https://github.com/apache/spark/commit/4c2816bd6513dc3ab2568584ecc8da6d1547fbf6).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by kiszk <gi...@git.apache.org>.
Github user kiszk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r136090141
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -244,6 +246,92 @@ case class HashAggregateExec(
     
       protected override val shouldStopRequired = false
     
    +  // We assume a prefix has lower cases and a name has camel cases
    +  private val variableName = "^[a-z]+_[a-zA-Z]+[0-9]*".r
    +
    +  // Returns true if a given name id belongs to this `CodegenContext`
    +  private def isVariable(nameId: String): Boolean = nameId match {
    +    case variableName() => true
    +    case _ => false
    +  }
    +
    +  // Extracts all the outer references for a given `aggExpr`. This result will be used to split
    +  // aggregation into small functions.
    +  private def getOuterReferences(
    +      ctx: CodegenContext,
    +      aggExpr: Expression,
    +      subExprs: Map[Expression, SubExprEliminationState]): Set[(String, String)] = {
    +    val stack = mutable.Stack[Expression](aggExpr)
    +    val argSet = mutable.Set[(String, String)]()
    +    val addIfNotLiteral = (value: String, tpe: String) => {
    +      if (isVariable(value)) {
    +        argSet += ((tpe, value))
    +      }
    +    }
    +    while (stack.nonEmpty) {
    +      stack.pop() match {
    +        case e if subExprs.contains(e) =>
    +          val exprCode = subExprs(e)
    +          addIfNotLiteral(exprCode.value, ctx.javaType(e.dataType))
    +          addIfNotLiteral(exprCode.isNull, "boolean")
    +          // Since the children possibly has common expressions, we push them here
    +          stack.pushAll(e.children)
    +        case ref: BoundReference
    +            if ctx.currentVars != null && ctx.currentVars(ref.ordinal) != null =>
    +          val argVal = ctx.currentVars(ref.ordinal).value
    +          addIfNotLiteral(argVal, ctx.javaType(ref.dataType))
    +          addIfNotLiteral(ctx.currentVars(ref.ordinal).isNull, "boolean")
    +        case _: BoundReference =>
    +          argSet += (("InternalRow", ctx.INPUT_ROW))
    +        case e =>
    +          stack.pushAll(e.children)
    +      }
    +    }
    +
    +    argSet.toSet
    +  }
    +
    +  // Splits the aggregation into small functions because the HotSpot does not compile
    +  // too long functions.
    +  private def splitAggregateExpressions(
    +      ctx: CodegenContext,
    +      aggExprs: Seq[Expression],
    +      evalAndUpdateCodes: Seq[String],
    +      subExprs: Map[Expression, SubExprEliminationState],
    +      otherArgs: Seq[(String, String)] = Seq.empty): Seq[String] = {
    +    aggExprs.zipWithIndex.map { case (aggExpr, i) =>
    +      // The maximum number of parameters in Java methods is 255, so this method gives up splitting
    +      // the code if the number goes over the limit.
    +      // You can find more information about the limit in the JVM specification:
    +      //   - The number of method parameters is limited to 255 by the definition of a method
    +      //     descriptor, where the limit includes one unit for this in the case of instance
    +      //     or interface method invocations.
    +      val args = (getOuterReferences(ctx, aggExpr, subExprs) ++ otherArgs).toSeq
    +
    +      // This is for testing/benchmarking only
    +      val maxParamNumInJavaMethod =
    +          sqlContext.getConf("spark.sql.codegen.aggregate.maxParamNumInJavaMethod", null) match {
    +        case null | "" => 256
    --- End diff --
    
    Since `$doAggVal` is [non-static method](https://stackoverflow.com/questions/30581531/maximum-number-of-parameters-in-java-method-declaration), this number should be `255`.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test PASSed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    I didn't look into the code yet, #18931 also could solve a query below?
    ```
     sql("SELECT a, KURTOSIS(b)FROM t GROUP BY a")
    ```


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test FAILed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Thanks @maropu.
    
    After counting accurate bytecode size, there seems a bottleneck in generated codes in aggregation, so this can improve q66 a lot.
    
    Overall, the numbers looks great, except for there is a significant regression in q94 when applying this change.
    



---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    just a sec, I'll re-run `q94` (sometimes, numbers fluctuate).


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    @kiszk Thanks for your summary. I had a few related discussions with @rednaxelafx and @liancheng in the recent weeks. Vertical cuts like https://github.com/apache/spark/pull/19082 is pretty promising for improving the performance. Thus, I plan to review the implementation in the recent days.
    
    At the beginning, I did not notice https://github.com/apache/spark/pull/18931 is using `private` or `final` attributes; otherwise, inlining does not benefit. It will be the same as the whole-stage codegen is turned off. The current proposal in https://github.com/apache/spark/pull/18931 is pretty limited due to the parameter number limits and the others. Thus, we need a better design for horizontal/ring cuts. The design is highly dependent on JVM internals and whole-stage codegen algorithms. So far, we do not have anything significant to share yet. 


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    > At the beginning, I did not notice #18931 is using private or final attributes; otherwise, inlining does not benefit. It will be the same as the whole-stage codegen is turned off. The current proposal in #18931 is pretty limited due to the parameter number limits and the others.
    
    @gatorsmile Sorry, but may I ask what is the "others"?


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r156184646
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -863,25 +984,43 @@ case class HashAggregateExec(
         }
     
         val updateRowInUnsafeRowMap: String = {
    -      ctx.INPUT_ROW = unsafeRowBuffer
    +      // 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 updateUnsafeRowBuffer = unsafeRowBufferEvals.zipWithIndex.map { case (ev, i) =>
    +
    +      val evalAndUpdateCodes = unsafeRowBufferEvals.zipWithIndex.map { case (ev, i) =>
             val dt = updateExpr(i).dataType
    -        ctx.updateColumn(unsafeRowBuffer, dt, i, ev, updateExpr(i).nullable)
    +        val updateColumnCode = ctx.updateColumn(unsafeRowBuffer, dt, i, ev, updateExpr(i).nullable)
    +        s"""
    +           | // evaluate aggregate function
    +           | ${ev.code}
    +           | // update unsafe row buffer
    +           | $updateColumnCode
    +         """.stripMargin
           }
    +
    +      val updateAggValCode = splitAggregateExpressions(
    +        ctx, boundUpdateExpr, evalAndUpdateCodes, subExprs.states,
    +        Seq(("InternalRow", unsafeRowBuffer)))
    --- End diff --
    
    ```
    ctx,
    boundUpdateExpr,
    evalAndUpdateCodes,
    subExprs.states,
    Seq(("InternalRow", unsafeRowBuffer)))
    ```


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r155999993
  
    --- Diff: sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala ---
    @@ -1070,6 +1071,24 @@ class CodegenContext {
       }
     }
     
    +object CodegenContext {
    +
    +  private val javaKeywords = Set(
    +    "abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const",
    +    "continue", "default", "do", "double", "else", "extends", "false", "final", "finally", "float",
    +    "for", "goto", "if", "implements", "import", "instanceof", "int", "interface", "long", "native",
    +    "new", "null", "package", "private", "protected", "public", "return", "short", "static",
    +    "strictfp", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true",
    +    "try", "void", "volatile", "while"
    +  )
    +
    +  def isJavaIdentifier(str: String): Boolean = str match {
    +    case null | "" => false
    +    case _ => !javaKeywords.contains(str) && isJavaIdentifierStart(str.charAt(0)) &&
    +      (1 until str.length).forall(i => isJavaIdentifierPart(str.charAt(i)))
    +  }
    --- End diff --
    
    ```Scala
      /**
       * Returns true if the given `str` is a valid java identifier.
       */
      def isJavaIdentifier(str: String): Boolean = str match {
        case null | "" =>
          false
        case _ =>
          !javaKeywords.contains(str) && isJavaIdentifierStart(str.charAt(0)) &&
            (1 until str.length).forall(i => isJavaIdentifierPart(str.charAt(i)))
      }
    ```


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by maropu <gi...@git.apache.org>.
Github user maropu closed the pull request at:

    https://github.com/apache/spark/pull/19082


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #81351 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81351/testReport)** for PR 19082 at commit [`a2b3dd3`](https://github.com/apache/spark/commit/a2b3dd35a733cd3a209d90266eaa5cdc75be3086).
     * This patch **fails due to an unknown error code, -9**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #81329 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81329/testReport)** for PR 19082 at commit [`abc5450`](https://github.com/apache/spark/commit/abc5450d6010e6a6db4f005782f60970160ddb4a).


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/82498/
    Test FAILed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #81330 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81330/testReport)** for PR 19082 at commit [`e432136`](https://github.com/apache/spark/commit/e43213620d70f0b229cd79468900d1095843e7e1).
     * This patch **fails Scala style tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/81248/
    Test FAILed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r156229346
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -863,25 +984,43 @@ case class HashAggregateExec(
         }
     
         val updateRowInUnsafeRowMap: String = {
    -      ctx.INPUT_ROW = unsafeRowBuffer
    +      // 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 updateUnsafeRowBuffer = unsafeRowBufferEvals.zipWithIndex.map { case (ev, i) =>
    +
    +      val evalAndUpdateCodes = unsafeRowBufferEvals.zipWithIndex.map { case (ev, i) =>
             val dt = updateExpr(i).dataType
    -        ctx.updateColumn(unsafeRowBuffer, dt, i, ev, updateExpr(i).nullable)
    +        val updateColumnCode = ctx.updateColumn(unsafeRowBuffer, dt, i, ev, updateExpr(i).nullable)
    +        s"""
    +           | // evaluate aggregate function
    +           | ${ev.code}
    +           | // update unsafe row buffer
    +           | $updateColumnCode
    +         """.stripMargin
           }
    +
    +      val updateAggValCode = splitAggregateExpressions(
    +        ctx, boundUpdateExpr, evalAndUpdateCodes, subExprs.states,
    +        Seq(("InternalRow", unsafeRowBuffer)))
    --- End diff --
    
    ok


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    ya, enjoy!


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    > The regression caused by spark.sql.codegen.hugeMethodLimit shows the potential regression caused by horizontal cuts, although spark.sql.codegen.hugeMethodLimit does nothing.
    
    `hugeMethodLimit` just affects if wholestage codegen is enabled. The regression is possibly caused by we completely disable wholestage codegen when detecting maybe one huge method. The regression of disabled wholestage codegen is larger than the affect of huge method.
    
    I didn't know how you link it to so-called "horizontal cuts" or split generated code.
    



---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    The regression caused by `spark.sql.codegen.hugeMethodLimit` shows the potential regression caused by horizontal cuts, although `spark.sql.codegen.hugeMethodLimit` does nothing. 


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #81400 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81400/testReport)** for PR 19082 at commit [`6c502a9`](https://github.com/apache/spark/commit/6c502a94de64db1e33ce03ba64fc1183a689f5af).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    https://github.com/apache/spark/pull/18931 is not what we want, although it can partially resolves some issues. Simply disabling the whole-stage codegen might trigger the regression like Q66. The general goal is to maximize the advantage of both whole-stage codegen and JIT optimization. Now, the point is how to cut the boundaries without introducing the extra IR. 
    



---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #84126 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84126/testReport)** for PR 19082 at commit [`8bae975`](https://github.com/apache/spark/commit/8bae975ebfe56745b626b39b2b430269e5a2b1ca).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by kiszk <gi...@git.apache.org>.
Github user kiszk commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Let me summarize recent interesting PRs for code generation regarding JVM bytecode limit for JIT compilation. These PRs encourages to apply JIT compilation to more methods since most of JIT compilers stop performing JIT compilation for a method with larger size (e.g. 8000 byte in HotSpot compiler). There are two categories for PRs.
    1. limit the total JVM bytecode size of the generated Java method (#18810, #19083)
    2. Generate a Java method with smaller size (#18931, #19082).
    
    I think that both categories are complementary. I like these activities.
    
    In category 1., it is to disable a whole-stage codegen for a large method (i.e. more than 8000 JVM byte code) that will not be JIT-compiled.  
    #18810 tries to **estimate whether JVM bytecode size** is less than 8000 or not by using the number of lines of a method. The threshold of the line is 2667. If estimated bytecode size more than 8000, whole-stage codegen is disabled. This threshold worked well for most of programs. However, as @maropu summarized [here](https://github.com/apache/spark/pull/19082#issuecomment-335336076), it did not work for some program (e.g. [q66](https://github.com/apache/spark/pull/18810#issuecomment-323620029)).  
    Then, #19083 **checks actual JVM bytecode size** by using the compiled JVM bytecode. This PR can precisely avoids not to perform JIT compilation.  
    Category 1. cannot encourage JIT compilation to the whole-staged method.
    
    In category 2., code generation in each part tries to smaller methods (i.e. 8000 JVM byte codes per method) to apply JIT compilations to more methods or to avoid JVM byte code generation failure (beyond 64KB per methods). This will not dis  
    One of activities is to use `CodeGenerator.splitExpressions()`.  
    #18931 splits a set of `comsume()` functions in a physical plan [into multiple methods](https://github.com/apache/spark/pull/18931#issuecomment-325907224) instead of embedding into one method (e.g. `processNext()`).  
    #19082 splits operations in aggregation into multiple methods instead of embedding into one method (e.g. `agg_doAggregateWithoutKey()`).  
    Even if these PRs create smaller methods, *JIT compiler can make compilation unit larger* by applying method inlining. To make compilation unit larger encourages to apply more optimizations in the compilation. For example, in HotSpot, a method whose JVM bytecode size is up to [325 (frequently executed)](http://isuru-perera.blogspot.jp/2014/12/java-jit-compilation-inlining-jitwatch.html) or [35 (normal)](http://www.oracle.com/technetwork/java/vmoptions-jsp-140102.html) will be inlined. Thus, I think that we will rarely see performance regression.  
    Category 2. tries to encourage JIT compilation to the whole-staged method by making its method size smaller.
    
    @gatorsmile, @viirya, @maropu, @rednaxelafx what do you think? Do you have any comments or questions?


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #82502 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/82502/testReport)** for PR 19082 at commit [`1880dfd`](https://github.com/apache/spark/commit/1880dfdfedbdef11d39cb092202a6bc7db95e374).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #82499 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/82499/testReport)** for PR 19082 at commit [`a95816c`](https://github.com/apache/spark/commit/a95816c07146e8a15910abca62573f0ba7fd32e2).


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r178716133
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -825,52 +924,92 @@ case class HashAggregateExec(
         ctx.currentVars = new Array[ExprCode](aggregateBufferAttributes.length) ++ input
     
         val updateRowInRegularHashMap: String = {
    -      ctx.INPUT_ROW = unsafeRowBuffer
    +      // We need to copy the aggregation row buffer to a local row first because each aggregate
    +      // function directly updates the buffer when it finishes.
    --- End diff --
    
    We need this copy because: https://github.com/apache/spark/pull/19082#discussion_r143326742


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r156002166
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -805,26 +908,44 @@ case class HashAggregateExec(
     
     
         def updateRowInFastHashMap(isVectorized: Boolean): Option[String] = {
    -      ctx.INPUT_ROW = fastRowBuffer
    +      // 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("localFastRowBuffer")
    +      val initLocalRowBuffer = s"InternalRow $localRowBuffer = $fastRowBuffer.copy();"
    +
    +      ctx.INPUT_ROW = localRowBuffer
           val boundUpdateExpr = updateExpr.map(BindReferences.bindReference(_, inputAttr))
           val subExprs = ctx.subexpressionEliminationForWholeStageCodegen(boundUpdateExpr)
           val effectiveCodes = subExprs.codes.mkString("\n")
           val fastRowEvals = ctx.withSubExprEliminationExprs(subExprs.states) {
             boundUpdateExpr.map(_.genCode(ctx))
           }
    -      val updateFastRow = fastRowEvals.zipWithIndex.map { case (ev, i) =>
    +
    +      val evalAndUpdateCodes = fastRowEvals.zipWithIndex.map { case (ev, i) =>
             val dt = updateExpr(i).dataType
    -        ctx.updateColumn(fastRowBuffer, dt, i, ev, updateExpr(i).nullable, isVectorized)
    +        val updateColumnCode = ctx.updateColumn(
    +          fastRowBuffer, dt, i, ev, updateExpr(i).nullable, isVectorized)
    +        s"""
    +           | // evaluate aggregate function
    +           | ${ev.code}
    +           | // update fast row
    +           | $updateColumnCode
    +         """.stripMargin
           }
    +
    +      val updateAggValCode = splitAggregateExpressions(
    +        ctx, boundUpdateExpr, evalAndUpdateCodes, subExprs.states,
    +        Seq(("InternalRow", fastRowBuffer)))
    --- End diff --
    
    indents


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    @maropu Thanks. Then looks there isn't any significant regression brought by this or #18931. We need to be careful but this numbers give more confidence.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test PASSed.


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r156003342
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -256,6 +258,85 @@ case class HashAggregateExec(
          """.stripMargin
       }
     
    +  // Extracts all the input variable references for a given `aggExpr`. This result will be used
    +  // to split aggregation into small functions.
    +  private def getInputVariableReferences(
    +      ctx: CodegenContext,
    +      aggExpr: Expression,
    +      subExprs: Map[Expression, SubExprEliminationState]): Set[(String, String)] = {
    +    // `argSet` collects all the pairs of variable names and their types, the first in the pair is
    +    // a type name and the second is a variable name.
    +    val argSet = mutable.Set[(String, String)]()
    +    val stack = mutable.Stack[Expression](aggExpr)
    +    while (stack.nonEmpty) {
    +      stack.pop() match {
    +        case e if subExprs.contains(e) =>
    +          val exprCode = subExprs(e)
    +          if (CodegenContext.isJavaIdentifier(exprCode.value)) {
    +            argSet += ((ctx.javaType(e.dataType), exprCode.value))
    +          }
    +          if (CodegenContext.isJavaIdentifier(exprCode.isNull)) {
    +            argSet += (("boolean", exprCode.isNull))
    +          }
    +          // Since the children possibly has common expressions, we push them here
    +          stack.pushAll(e.children)
    +        case ref: BoundReference
    +            if ctx.currentVars != null && ctx.currentVars(ref.ordinal) != null =>
    +          val value = ctx.currentVars(ref.ordinal).value
    +          val isNull = ctx.currentVars(ref.ordinal).isNull
    +          if (CodegenContext.isJavaIdentifier(value)) {
    +            argSet += ((ctx.javaType(ref.dataType), value))
    +          }
    +          if (CodegenContext.isJavaIdentifier(isNull)) {
    +            argSet += (("boolean", isNull))
    +          }
    +        case _: BoundReference =>
    +          argSet += (("InternalRow", ctx.INPUT_ROW))
    +        case e =>
    +          stack.pushAll(e.children)
    +      }
    +    }
    +
    +    argSet.toSet
    +  }
    +
    +  // Splits aggregate code into small functions because JVMs does not compile too long functions
    +  private def splitAggregateExpressions(
    +      ctx: CodegenContext,
    +      aggExprs: Seq[Expression],
    +      evalAndUpdateCodes: Seq[String],
    +      subExprs: Map[Expression, SubExprEliminationState],
    +      otherArgs: Seq[(String, String)] = Seq.empty): Seq[String] = {
    +    aggExprs.zipWithIndex.map { case (aggExpr, i) =>
    +      // The maximum length of parameters in non-static Java methods is 254, but a parameter of
    +      // type long or double contributes two units to the length. So, this method gives up
    +      // splitting the code if the parameter length goes over 127.
    +      val args = (getInputVariableReferences(ctx, aggExpr, subExprs) ++ otherArgs).toSeq
    +
    +      // This is for testing/benchmarking only
    +      val maxParamNumInJavaMethod =
    +          sqlContext.getConf("spark.sql.codegen.aggregate.maxParamNumInJavaMethod", null) match {
    --- End diff --
    
    Let us introduce an internal SQLConf. If the number is high enough, we can disable this feature. 


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r136490017
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -244,6 +246,92 @@ case class HashAggregateExec(
     
       protected override val shouldStopRequired = false
     
    +  // We assume a prefix has lower cases and a name has camel cases
    +  private val variableName = "^[a-z]+_[a-zA-Z]+[0-9]*".r
    +
    +  // Returns true if a given name id belongs to this `CodegenContext`
    +  private def isVariable(nameId: String): Boolean = nameId match {
    +    case variableName() => true
    +    case _ => false
    +  }
    +
    +  // Extracts all the outer references for a given `aggExpr`. This result will be used to split
    +  // aggregation into small functions.
    +  private def getOuterReferences(
    +      ctx: CodegenContext,
    +      aggExpr: Expression,
    +      subExprs: Map[Expression, SubExprEliminationState]): Set[(String, String)] = {
    +    val stack = mutable.Stack[Expression](aggExpr)
    +    val argSet = mutable.Set[(String, String)]()
    +    val addIfNotLiteral = (value: String, tpe: String) => {
    +      if (isVariable(value)) {
    +        argSet += ((tpe, value))
    +      }
    +    }
    +    while (stack.nonEmpty) {
    +      stack.pop() match {
    +        case e if subExprs.contains(e) =>
    +          val exprCode = subExprs(e)
    +          addIfNotLiteral(exprCode.value, ctx.javaType(e.dataType))
    +          addIfNotLiteral(exprCode.isNull, "boolean")
    +          // Since the children possibly has common expressions, we push them here
    +          stack.pushAll(e.children)
    +        case ref: BoundReference
    +            if ctx.currentVars != null && ctx.currentVars(ref.ordinal) != null =>
    +          val argVal = ctx.currentVars(ref.ordinal).value
    +          addIfNotLiteral(argVal, ctx.javaType(ref.dataType))
    +          addIfNotLiteral(ctx.currentVars(ref.ordinal).isNull, "boolean")
    +        case _: BoundReference =>
    +          argSet += (("InternalRow", ctx.INPUT_ROW))
    +        case e =>
    +          stack.pushAll(e.children)
    +      }
    +    }
    +
    +    argSet.toSet
    +  }
    +
    +  // Splits the aggregation into small functions because the HotSpot does not compile
    +  // too long functions.
    +  private def splitAggregateExpressions(
    +      ctx: CodegenContext,
    +      aggExprs: Seq[Expression],
    +      evalAndUpdateCodes: Seq[String],
    +      subExprs: Map[Expression, SubExprEliminationState],
    +      otherArgs: Seq[(String, String)] = Seq.empty): Seq[String] = {
    +    aggExprs.zipWithIndex.map { case (aggExpr, i) =>
    +      // The maximum number of parameters in Java methods is 255, so this method gives up splitting
    +      // the code if the number goes over the limit.
    +      // You can find more information about the limit in the JVM specification:
    +      //   - The number of method parameters is limited to 255 by the definition of a method
    +      //     descriptor, where the limit includes one unit for this in the case of instance
    +      //     or interface method invocations.
    +      val args = (getOuterReferences(ctx, aggExpr, subExprs) ++ otherArgs).toSeq
    +
    +      // This is for testing/benchmarking only
    +      val maxParamNumInJavaMethod =
    +          sqlContext.getConf("spark.sql.codegen.aggregate.maxParamNumInJavaMethod", null) match {
    --- End diff --
    
    This is a test-only option, so I think we need not check that.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by kiszk <gi...@git.apache.org>.
Github user kiszk commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Jenkins, retest this please


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #84724 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84724/testReport)** for PR 19082 at commit [`1ed010f`](https://github.com/apache/spark/commit/1ed010f49cfdb9e0bfc3bdf65e974bda191f76e0).


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #81351 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81351/testReport)** for PR 19082 at commit [`a2b3dd3`](https://github.com/apache/spark/commit/a2b3dd35a733cd3a209d90266eaa5cdc75be3086).


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r136207629
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -244,6 +246,92 @@ case class HashAggregateExec(
     
       protected override val shouldStopRequired = false
     
    +  // We assume a prefix has lower cases and a name has camel cases
    +  private val variableName = "^[a-z]+_[a-zA-Z]+[0-9]*".r
    +
    +  // Returns true if a given name id belongs to this `CodegenContext`
    +  private def isVariable(nameId: String): Boolean = nameId match {
    +    case variableName() => true
    +    case _ => false
    +  }
    +
    +  // Extracts all the outer references for a given `aggExpr`. This result will be used to split
    +  // aggregation into small functions.
    +  private def getOuterReferences(
    +      ctx: CodegenContext,
    +      aggExpr: Expression,
    +      subExprs: Map[Expression, SubExprEliminationState]): Set[(String, String)] = {
    +    val stack = mutable.Stack[Expression](aggExpr)
    +    val argSet = mutable.Set[(String, String)]()
    +    val addIfNotLiteral = (value: String, tpe: String) => {
    +      if (isVariable(value)) {
    +        argSet += ((tpe, value))
    +      }
    +    }
    +    while (stack.nonEmpty) {
    +      stack.pop() match {
    +        case e if subExprs.contains(e) =>
    +          val exprCode = subExprs(e)
    +          addIfNotLiteral(exprCode.value, ctx.javaType(e.dataType))
    +          addIfNotLiteral(exprCode.isNull, "boolean")
    +          // Since the children possibly has common expressions, we push them here
    +          stack.pushAll(e.children)
    +        case ref: BoundReference
    +            if ctx.currentVars != null && ctx.currentVars(ref.ordinal) != null =>
    +          val argVal = ctx.currentVars(ref.ordinal).value
    +          addIfNotLiteral(argVal, ctx.javaType(ref.dataType))
    +          addIfNotLiteral(ctx.currentVars(ref.ordinal).isNull, "boolean")
    +        case _: BoundReference =>
    +          argSet += (("InternalRow", ctx.INPUT_ROW))
    +        case e =>
    +          stack.pushAll(e.children)
    +      }
    +    }
    +
    +    argSet.toSet
    +  }
    +
    +  // Splits the aggregation into small functions because the HotSpot does not compile
    +  // too long functions.
    +  private def splitAggregateExpressions(
    +      ctx: CodegenContext,
    +      aggExprs: Seq[Expression],
    +      evalAndUpdateCodes: Seq[String],
    +      subExprs: Map[Expression, SubExprEliminationState],
    +      otherArgs: Seq[(String, String)] = Seq.empty): Seq[String] = {
    +    aggExprs.zipWithIndex.map { case (aggExpr, i) =>
    +      // The maximum number of parameters in Java methods is 255, so this method gives up splitting
    +      // the code if the number goes over the limit.
    +      // You can find more information about the limit in the JVM specification:
    +      //   - The number of method parameters is limited to 255 by the definition of a method
    +      //     descriptor, where the limit includes one unit for this in the case of instance
    +      //     or interface method invocations.
    +      val args = (getOuterReferences(ctx, aggExpr, subExprs) ++ otherArgs).toSeq
    +
    +      // This is for testing/benchmarking only
    +      val maxParamNumInJavaMethod =
    +          sqlContext.getConf("spark.sql.codegen.aggregate.maxParamNumInJavaMethod", null) match {
    +        case null | "" => 256
    --- End diff --
    
    oh, good catch! I'll fix


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r156249393
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -269,28 +343,50 @@ case class HashAggregateExec(
               e.aggregateFunction.asInstanceOf[DeclarativeAggregate].mergeExpressions
           }
         }
    -    ctx.currentVars = bufVars ++ input
    +
    +    // We need to copy the aggregation buffer to local variables first because each aggregate
    +    // function directly updates the buffer when it finishes.
    --- End diff --
    
    just FYI: we must need local copys from this discussions, too https://github.com/apache/spark/pull/19865


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r143903396
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -244,6 +246,89 @@ case class HashAggregateExec(
     
       protected override val shouldStopRequired = false
     
    +  // Extracts all the input variable references for a given `aggExpr`. This result will be used
    +  // to split aggregation into small functions.
    +  private def getInputVariableReferences(
    +      ctx: CodegenContext,
    +      aggExpr: Expression,
    +      subExprs: Map[Expression, SubExprEliminationState]): Set[(String, String)] = {
    +    // `argSet` collects all the pairs of variable names and their types, the first in the pair is
    +    // a type name and the second is a variable name.
    +    val argSet = mutable.Set[(String, String)]()
    +    val stack = mutable.Stack[Expression](aggExpr)
    +    while (stack.nonEmpty) {
    +      stack.pop() match {
    +        case e if subExprs.contains(e) =>
    +          val exprCode = subExprs(e)
    +          if (CodegenContext.isJavaIdentifier(exprCode.value)) {
    +            argSet += ((ctx.javaType(e.dataType), exprCode.value))
    +          }
    +          if (CodegenContext.isJavaIdentifier(exprCode.isNull)) {
    +            argSet += (("boolean", exprCode.isNull))
    +          }
    +          // Since the children possibly has common expressions, we push them here
    +          stack.pushAll(e.children)
    +        case ref: BoundReference
    +            if ctx.currentVars != null && ctx.currentVars(ref.ordinal) != null =>
    +          val value = ctx.currentVars(ref.ordinal).value
    +          val isNull = ctx.currentVars(ref.ordinal).isNull
    +          if (CodegenContext.isJavaIdentifier(value)) {
    +            argSet += ((ctx.javaType(ref.dataType), value))
    +          }
    +          if (CodegenContext.isJavaIdentifier(isNull)) {
    +            argSet += (("boolean", isNull))
    +          }
    +        case _: BoundReference =>
    +          argSet += (("InternalRow", ctx.INPUT_ROW))
    +        case e =>
    +          stack.pushAll(e.children)
    +      }
    +    }
    +
    +    argSet.toSet
    +  }
    +
    +  // Splits the aggregation into small functions because the HotSpot does not compile
    +  // too long functions.
    +  private def splitAggregateExpressions(
    +      ctx: CodegenContext,
    +      aggExprs: Seq[Expression],
    +      evalAndUpdateCodes: Seq[String],
    +      subExprs: Map[Expression, SubExprEliminationState],
    +      otherArgs: Seq[(String, String)] = Seq.empty): Seq[String] = {
    +    aggExprs.zipWithIndex.map { case (aggExpr, i) =>
    +      // The maximum number of parameters in non-static Java methods is 254, so this method gives
    +      // up splitting the code if the number goes over the limit.
    +      // You can find more information about the limit in the JVM specification:
    +      //   - The number of method parameters is limited to 255 by the definition of a method
    --- End diff --
    
    @kiszk Thanks for pinging me. I've updated the similar check in #18931 too.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #81354 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81354/testReport)** for PR 19082 at commit [`a2b3dd3`](https://github.com/apache/spark/commit/a2b3dd35a733cd3a209d90266eaa5cdc75be3086).


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r136518024
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -244,6 +246,92 @@ case class HashAggregateExec(
     
       protected override val shouldStopRequired = false
     
    +  // We assume a prefix has lower cases and a name has camel cases
    +  private val variableName = "^[a-z]+_[a-zA-Z]+[0-9]*".r
    --- End diff --
    
    Good suggestion and I'm also looking for other better one. I'll try to fix.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test FAILed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test FAILed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    retest this please


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test FAILed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test FAILed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/84711/
    Test FAILed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    @maropu The codes to do aggregation are actually wrapped in a function `doAggregateWithKeys`/`doAggregateWithoutKey`. This is also the part of generated codes this PR improves by extracting functions.
    
    My initial thought is, during the processing of the query, this function `doAggregateWithKeys`/`doAggregateWithoutKey` actually only runs once to aggregate on all rows. No matter it is a long function or not, we don't have chance for JIT to step in. That said the length of this function doesn't impact too much in JIT issue.
    
    The long function issue affects the performance of wholestage codegen, because it is run many times in non-compiled way. It drags the speed of other generated codes. Since `doAggregateWithKeys`/`doAggregateWithoutKey` only run once, it doesn't impact much. So wholestage codegen query is still faster than non-wholestage codegen one.
    
    This PR improves the aggregation because it extracts small functions from `doAggregateWithKeys`/`doAggregateWithoutKey`. Those functions will be run many times in the wrapping function. So JIT has room to step in now.



---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #82502 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/82502/testReport)** for PR 19082 at commit [`1880dfd`](https://github.com/apache/spark/commit/1880dfdfedbdef11d39cb092202a6bc7db95e374).


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    sure, I will look into this.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #81330 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81330/testReport)** for PR 19082 at commit [`e432136`](https://github.com/apache/spark/commit/e43213620d70f0b229cd79468900d1095843e7e1).


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Will review it carefully after I finish my vacation. Thanks!


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r143326742
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -797,26 +904,44 @@ case class HashAggregateExec(
     
     
         def updateRowInFastHashMap(isVectorized: Boolean): Option[String] = {
    -      ctx.INPUT_ROW = fastRowBuffer
    +      // 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("localFastRowBuffer")
    +      val initLocalRowBuffer = s"InternalRow $localRowBuffer = $fastRowBuffer.copy();"
    --- End diff --
    
    Why we need to copy the row buffer? You let `updateExpr` bound to the local copied row buffer, but the evaluation is happened in split functions. Isn't possible the `updateExpr` can't find the local variable of the copied row buffer in the functions?


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/81329/
    Test FAILed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    I found q66 was over 2-times slower by recent commits (probably, bytecode size checks might affect this number..) https://docs.google.com/spreadsheets/d/1V8xoKR9ElU-rOXMH84gb5BbLEw0XAPTJY8c8aZeIqus/edit#gid=2074944948


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #81331 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81331/testReport)** for PR 19082 at commit [`57c8280`](https://github.com/apache/spark/commit/57c828092a80b608a068d69d669d44cd9a38d417).
     * This patch **fails Scala style tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/81328/
    Test FAILed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test FAILed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #81328 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81328/testReport)** for PR 19082 at commit [`78d0a00`](https://github.com/apache/spark/commit/78d0a00eb209aae54383050dd1134d9d4db635d2).
     * This patch **fails SparkR unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by a10y <gi...@git.apache.org>.
Github user a10y commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r143836110
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -244,6 +246,89 @@ case class HashAggregateExec(
     
       protected override val shouldStopRequired = false
     
    +  // Extracts all the input variable references for a given `aggExpr`. This result will be used
    +  // to split aggregation into small functions.
    +  private def getInputVariableReferences(
    +      ctx: CodegenContext,
    +      aggExpr: Expression,
    +      subExprs: Map[Expression, SubExprEliminationState]): Set[(String, String)] = {
    +    // `argSet` collects all the pairs of variable names and their types, the first in the pair is
    +    // a type name and the second is a variable name.
    +    val argSet = mutable.Set[(String, String)]()
    +    val stack = mutable.Stack[Expression](aggExpr)
    +    while (stack.nonEmpty) {
    +      stack.pop() match {
    +        case e if subExprs.contains(e) =>
    +          val exprCode = subExprs(e)
    +          if (CodegenContext.isJavaIdentifier(exprCode.value)) {
    +            argSet += ((ctx.javaType(e.dataType), exprCode.value))
    +          }
    +          if (CodegenContext.isJavaIdentifier(exprCode.isNull)) {
    +            argSet += (("boolean", exprCode.isNull))
    +          }
    +          // Since the children possibly has common expressions, we push them here
    +          stack.pushAll(e.children)
    +        case ref: BoundReference
    +            if ctx.currentVars != null && ctx.currentVars(ref.ordinal) != null =>
    +          val value = ctx.currentVars(ref.ordinal).value
    +          val isNull = ctx.currentVars(ref.ordinal).isNull
    +          if (CodegenContext.isJavaIdentifier(value)) {
    +            argSet += ((ctx.javaType(ref.dataType), value))
    +          }
    +          if (CodegenContext.isJavaIdentifier(isNull)) {
    +            argSet += (("boolean", isNull))
    +          }
    +        case _: BoundReference =>
    +          argSet += (("InternalRow", ctx.INPUT_ROW))
    +        case e =>
    +          stack.pushAll(e.children)
    +      }
    +    }
    +
    +    argSet.toSet
    +  }
    +
    +  // Splits the aggregation into small functions because the HotSpot does not compile
    +  // too long functions.
    +  private def splitAggregateExpressions(
    +      ctx: CodegenContext,
    +      aggExprs: Seq[Expression],
    +      evalAndUpdateCodes: Seq[String],
    +      subExprs: Map[Expression, SubExprEliminationState],
    +      otherArgs: Seq[(String, String)] = Seq.empty): Seq[String] = {
    +    aggExprs.zipWithIndex.map { case (aggExpr, i) =>
    +      // The maximum number of parameters in non-static Java methods is 254, so this method gives
    +      // up splitting the code if the number goes over the limit.
    +      // You can find more information about the limit in the JVM specification:
    +      //   - The number of method parameters is limited to 255 by the definition of a method
    --- End diff --
    
    If you read the spec closely, it actually says that there are 255 slots, where 1 slot is taken by **this** and 2 slots each are taken up by **long** and **double** parameters.
    
    https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.3.3


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #84774 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84774/testReport)** for PR 19082 at commit [`4077608`](https://github.com/apache/spark/commit/4077608c47bc5059b3e00aa882362829d729476b).


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #84713 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84713/testReport)** for PR 19082 at commit [`f866b11`](https://github.com/apache/spark/commit/f866b110a27e4405c1e51fd0684d6d22e19ed2a6).
     * This patch **fails SparkR unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #81235 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81235/testReport)** for PR 19082 at commit [`6dacad4`](https://github.com/apache/spark/commit/6dacad4e6d0f588ce6f02e33da9625cc9ea116aa).


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #82498 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/82498/testReport)** for PR 19082 at commit [`a95816c`](https://github.com/apache/spark/commit/a95816c07146e8a15910abca62573f0ba7fd32e2).


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by kiszk <gi...@git.apache.org>.
Github user kiszk commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    @maropu could you please resolve conflicts?


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test PASSed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #81354 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81354/testReport)** for PR 19082 at commit [`a2b3dd3`](https://github.com/apache/spark/commit/a2b3dd35a733cd3a209d90266eaa5cdc75be3086).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #83981 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/83981/testReport)** for PR 19082 at commit [`28b47e5`](https://github.com/apache/spark/commit/28b47e52bb262edaf73ad2aa44a2db68eb3a9847).


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    I'm also curious the performance of the master + #18931 on q66. Based on @maropu's benchmark before, q66 has much performance improvement.


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by rednaxelafx <gi...@git.apache.org>.
Github user rednaxelafx commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r136506046
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -244,6 +246,92 @@ case class HashAggregateExec(
     
       protected override val shouldStopRequired = false
     
    +  // We assume a prefix has lower cases and a name has camel cases
    +  private val variableName = "^[a-z]+_[a-zA-Z]+[0-9]*".r
    --- End diff --
    
    I know the regular expression is tempting, but there's actually a better way to do this along your idea, under the current framework.
    
    I've got a piece of code sitting in my own workspace that checks for Java identifiers:
    ```scala
    object CodegenContext {
      private val javaKeywords = Set(
        "abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class",
        "const", "continue", "default", "do", "double", "else", "extends", "false", "final",
        "finally", "float", "for", "goto", "if", "implements", "import", "instanceof", "int",
        "interface", "long", "native", "new", "null", "package", "private", "protected", "public",
        "return", "short", "static", "strictfp", "super", "switch", "synchronized", "this",
        "throw", "throws", "transient", "true", "try", "void", "volatile", "while"
      )
    
      def isJavaIdentifier(str: String): Boolean = str match {
        case null | "" => false
        case _ => java.lang.Character.isJavaIdentifierStart(str.charAt(0)) &&
                  (1 until str.length).forall(
                    i => java.lang.Character.isJavaIdentifierPart(str.charAt(i))) &&
                  !javaKeywords.contains(str)
      }
    }
    ```
    Feel free to use it here if you'd like. This is the way `java.lang.Character.isJavaIdentifierStart()` and `java.lang.Character.isJavaIdentifierPart()` is supposed to be used anyway, nothing creative.
    
    If you want to use it in a `case` like the way you're using the regular expression, just wrap the util above into an `unapply()`. But I'd say simply making `def isVariable(nameId: String) = CodegenContext.isJavaIdentifier(nameId)` is clean enough.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Jenkins, retest this please.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    > If we can cut the boundary of whole-stage operators better, we still can make the byte code size smaller than 8K. That means, we are not completely disabling the whole-stage codegen.
    
    @gatorsmile So sounds like your point is to find proper point to split (cut) operator functions out but not split all possible operators? Is it correct?


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Just try to help you understand it. If you don't want it, I can keep quiet. 


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/82615/
    Test PASSed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by kiszk <gi...@git.apache.org>.
Github user kiszk commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    @gatorsmile let me clarify. In other words, do you want to find how to cut the boundary to ensure enabling method inlining for callee methods? It could maximize advantage of both whole-stage codegen and JIT optimization in a compilation unit.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Nope. You can wait for the answers from the JVM experts. : )


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Since https://github.com/apache/spark/pull/19813 fixes this issue, so I'll close this. Thanks!


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test PASSed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test FAILed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/81331/
    Test FAILed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r136517567
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -244,6 +246,92 @@ case class HashAggregateExec(
     
       protected override val shouldStopRequired = false
     
    +  // We assume a prefix has lower cases and a name has camel cases
    +  private val variableName = "^[a-z]+_[a-zA-Z]+[0-9]*".r
    +
    +  // Returns true if a given name id belongs to this `CodegenContext`
    +  private def isVariable(nameId: String): Boolean = nameId match {
    +    case variableName() => true
    +    case _ => false
    +  }
    +
    +  // Extracts all the outer references for a given `aggExpr`. This result will be used to split
    +  // aggregation into small functions.
    +  private def getOuterReferences(
    --- End diff --
    
    ok, I'll rename this.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/81330/
    Test FAILed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #82499 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/82499/testReport)** for PR 19082 at commit [`a95816c`](https://github.com/apache/spark/commit/a95816c07146e8a15910abca62573f0ba7fd32e2).
     * This patch **fails Spark unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #81332 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81332/testReport)** for PR 19082 at commit [`e3722a0`](https://github.com/apache/spark/commit/e3722a002a8e62114d2685598687c1d86c7d18ca).
     * This patch **fails SparkR unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r143876358
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -244,6 +246,89 @@ case class HashAggregateExec(
     
       protected override val shouldStopRequired = false
     
    +  // Extracts all the input variable references for a given `aggExpr`. This result will be used
    +  // to split aggregation into small functions.
    +  private def getInputVariableReferences(
    +      ctx: CodegenContext,
    +      aggExpr: Expression,
    +      subExprs: Map[Expression, SubExprEliminationState]): Set[(String, String)] = {
    +    // `argSet` collects all the pairs of variable names and their types, the first in the pair is
    +    // a type name and the second is a variable name.
    +    val argSet = mutable.Set[(String, String)]()
    +    val stack = mutable.Stack[Expression](aggExpr)
    +    while (stack.nonEmpty) {
    +      stack.pop() match {
    +        case e if subExprs.contains(e) =>
    +          val exprCode = subExprs(e)
    +          if (CodegenContext.isJavaIdentifier(exprCode.value)) {
    +            argSet += ((ctx.javaType(e.dataType), exprCode.value))
    +          }
    +          if (CodegenContext.isJavaIdentifier(exprCode.isNull)) {
    +            argSet += (("boolean", exprCode.isNull))
    +          }
    +          // Since the children possibly has common expressions, we push them here
    +          stack.pushAll(e.children)
    +        case ref: BoundReference
    +            if ctx.currentVars != null && ctx.currentVars(ref.ordinal) != null =>
    +          val value = ctx.currentVars(ref.ordinal).value
    +          val isNull = ctx.currentVars(ref.ordinal).isNull
    +          if (CodegenContext.isJavaIdentifier(value)) {
    +            argSet += ((ctx.javaType(ref.dataType), value))
    +          }
    +          if (CodegenContext.isJavaIdentifier(isNull)) {
    +            argSet += (("boolean", isNull))
    +          }
    +        case _: BoundReference =>
    +          argSet += (("InternalRow", ctx.INPUT_ROW))
    +        case e =>
    +          stack.pushAll(e.children)
    +      }
    +    }
    +
    +    argSet.toSet
    +  }
    +
    +  // Splits the aggregation into small functions because the HotSpot does not compile
    +  // too long functions.
    +  private def splitAggregateExpressions(
    +      ctx: CodegenContext,
    +      aggExprs: Seq[Expression],
    +      evalAndUpdateCodes: Seq[String],
    +      subExprs: Map[Expression, SubExprEliminationState],
    +      otherArgs: Seq[(String, String)] = Seq.empty): Seq[String] = {
    +    aggExprs.zipWithIndex.map { case (aggExpr, i) =>
    +      // The maximum number of parameters in non-static Java methods is 254, so this method gives
    +      // up splitting the code if the number goes over the limit.
    +      // You can find more information about the limit in the JVM specification:
    +      //   - The number of method parameters is limited to 255 by the definition of a method
    --- End diff --
    
    Aha, I'll recheck this. Thanks.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/84770/
    Test PASSed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test FAILed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test PASSed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    yea, I'm with you; it seems they are orthogonal..., but If we have a more general way to solve both, it'd be the best.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    OK. Based on your attitudes, I do not care it.


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by rednaxelafx <gi...@git.apache.org>.
Github user rednaxelafx commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r136506452
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -244,6 +246,92 @@ case class HashAggregateExec(
     
       protected override val shouldStopRequired = false
     
    +  // We assume a prefix has lower cases and a name has camel cases
    +  private val variableName = "^[a-z]+_[a-zA-Z]+[0-9]*".r
    +
    +  // Returns true if a given name id belongs to this `CodegenContext`
    +  private def isVariable(nameId: String): Boolean = nameId match {
    +    case variableName() => true
    +    case _ => false
    +  }
    +
    +  // Extracts all the outer references for a given `aggExpr`. This result will be used to split
    +  // aggregation into small functions.
    +  private def getOuterReferences(
    +      ctx: CodegenContext,
    +      aggExpr: Expression,
    +      subExprs: Map[Expression, SubExprEliminationState]): Set[(String, String)] = {
    +    val stack = mutable.Stack[Expression](aggExpr)
    +    val argSet = mutable.Set[(String, String)]()
    +    val addIfNotLiteral = (value: String, tpe: String) => {
    --- End diff --
    
    Hmm. Just a cosmetic style comment: I would have declared `addIfNotLiteral ` with a `def` instead of making it a `scala.Function2[String, String, Unit]`.
    
    BTW, can we add a comment to `val argSet` for what those two fields of the `Tuple2[String, String]` means? And then also make this `addIfNotLiteral` function take the arguments in the same order as the tuple.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by kiszk <gi...@git.apache.org>.
Github user kiszk commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    To my best guess, trying to make huge method by method inlining will not fail JIT compilation in Hotspot. It may fail method inlining.
    
    According to these blog entries [1](https://techblug.wordpress.com/2013/08/19/java-jit-compiler-inlining/), [2](
    http://normanmaurer.me/blog/2014/05/15/Inline-all-the-Things/), we can see the following annotations for method inlining (explanations from [1])
    
    1. **inline (hot)**: the method was determined hot and inlined
    2. **too big**: the method was not inlined as the generated code was getting too big (but the method was not hot)
    3. **hot method too big**: the method was determined hot but not inlined because the resulting code was getting too big.
    
    Annotation 1. shows that inlining are suceeded. Annotation 2. or 3. shows that callee is too large. While 2. or 3. is shown in the compilation log [2], it still seems to succeed to compile a method. Of course, some method inling is are disabled.
    [Here](https://issues.apache.org/jira/browse/HBASE-15431) is an interesting experiments. While they forced to inlining by increasing threshold, it is not easy to see performance improvement.
    
    @viirya, is it answer to your question?



---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by kiszk <gi...@git.apache.org>.
Github user kiszk commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    The whole-stage codegen has two advantages according to [this paper](http://www.vldb.org/pvldb/vol4/p539-neumann.pdf).
    1. enable compiler optimizations among operations (3. in page 2)
    2. pass data in a row using a set of scalar values instead of using an iterator (1. and 2. in page 2)
    
    When method inlining is disabled (I assume each method is compiled), we will miss advantage 1. We can still enjoy advantage 2 by passing data without creating an iterator. IMHO, This is better than disabling whole-stage codegen.


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by kiszk <gi...@git.apache.org>.
Github user kiszk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r136900835
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -244,6 +246,89 @@ case class HashAggregateExec(
     
       protected override val shouldStopRequired = false
     
    +  // Extracts all the input variable references for a given `aggExpr`. This result will be used
    +  // to split aggregation into small functions.
    +  private def getInputVariableReferences(
    +      ctx: CodegenContext,
    +      aggExpr: Expression,
    +      subExprs: Map[Expression, SubExprEliminationState]): Set[(String, String)] = {
    +    // `argSet` collects all the pairs of variable names and their types, the first in the pair is
    +    // a type name and the second is a variable name.
    +    val argSet = mutable.Set[(String, String)]()
    +    val stack = mutable.Stack[Expression](aggExpr)
    +    while (stack.nonEmpty) {
    +      stack.pop() match {
    +        case e if subExprs.contains(e) =>
    +          val exprCode = subExprs(e)
    +          if (CodegenContext.isJavaIdentifier(exprCode.value)) {
    +            argSet += ((ctx.javaType(e.dataType), exprCode.value))
    +          }
    +          if (CodegenContext.isJavaIdentifier(exprCode.isNull)) {
    +            argSet += (("boolean", exprCode.isNull))
    +          }
    +          // Since the children possibly has common expressions, we push them here
    +          stack.pushAll(e.children)
    +        case ref: BoundReference
    +            if ctx.currentVars != null && ctx.currentVars(ref.ordinal) != null =>
    +          val value = ctx.currentVars(ref.ordinal).value
    +          val isNull = ctx.currentVars(ref.ordinal).isNull
    +          if (CodegenContext.isJavaIdentifier(value)) {
    +            argSet += ((ctx.javaType(ref.dataType), value))
    +          }
    +          if (CodegenContext.isJavaIdentifier(isNull)) {
    +            argSet += (("boolean", isNull))
    +          }
    +        case _: BoundReference =>
    +          argSet += (("InternalRow", ctx.INPUT_ROW))
    +        case e =>
    +          stack.pushAll(e.children)
    +      }
    +    }
    +
    +    argSet.toSet
    +  }
    +
    +  // Splits the aggregation into small functions because the HotSpot does not compile
    +  // too long functions.
    +  private def splitAggregateExpressions(
    +      ctx: CodegenContext,
    +      aggExprs: Seq[Expression],
    +      evalAndUpdateCodes: Seq[String],
    +      subExprs: Map[Expression, SubExprEliminationState],
    +      otherArgs: Seq[(String, String)] = Seq.empty): Seq[String] = {
    +    aggExprs.zipWithIndex.map { case (aggExpr, i) =>
    +      // The maximum number of parameters in Java methods is 255, so this method gives up splitting
    +      // the code if the number goes over the limit.
    +      // You can find more information about the limit in the JVM specification:
    +      //   - The number of method parameters is limited to 255 by the definition of a method
    +      //     descriptor, where the limit includes one unit for this in the case of instance
    +      //     or interface method invocations.
    +      val args = (getInputVariableReferences(ctx, aggExpr, subExprs) ++ otherArgs).toSeq
    +
    +      // This is for testing/benchmarking only
    +      val maxParamNumInJavaMethod =
    +          sqlContext.getConf("spark.sql.codegen.aggregate.maxParamNumInJavaMethod", null) match {
    +        case null | "" => 255
    --- End diff --
    
    If line 314 uses `<=`, this should be 254. In the previous commit, `<` is used.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    @kiszk @gatorsmile @rednaxelafx Based on the following reasoning, I don't think the cutting of whole-stage operators you may propose would be much beneficial than the approach did in #18931:
    
    1. If #18931 splits smaller functions. For the smaller operator functions, JIT will try to inline it into larger compilation unit. This is based on the information from @kiszk. Please correct me if it's not correct. So I don't think we will loss the advantage of wholestage codegen.  I'm doubt that it is any different than not split it, if under your proposal.
    2. For the bigger operator functions, it can't be inlined. But based on the info provided by @kiszk, it won't get performance improvement to inline such big functions.
    
    Thus, even considering you can provide better cutting points, I don't think it can get much benefit but incur much complexity into wholestage codegen.
    
    



---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    @kiszk Thanks for summarizing the PRs.
    
    I just have a question about inlining method by JIT compiler. So you mean JIT compiler will inline methods into larger unit and then do JIT compilation on it? Will JIT inlining method make a huge method that fails JIT? Although it sounds nonsense, I think I'd like to make sure it won't happen.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #82615 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/82615/testReport)** for PR 19082 at commit [`5584bdb`](https://github.com/apache/spark/commit/5584bdbdf057c22593f4856069e53fd52a222fe1).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #84770 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84770/testReport)** for PR 19082 at commit [`0e5d366`](https://github.com/apache/spark/commit/0e5d366dfce50ec3f879193f78c6a77213680926).


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by a10y <gi...@git.apache.org>.
Github user a10y commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r143836700
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -244,6 +246,89 @@ case class HashAggregateExec(
     
       protected override val shouldStopRequired = false
     
    +  // Extracts all the input variable references for a given `aggExpr`. This result will be used
    +  // to split aggregation into small functions.
    +  private def getInputVariableReferences(
    +      ctx: CodegenContext,
    +      aggExpr: Expression,
    +      subExprs: Map[Expression, SubExprEliminationState]): Set[(String, String)] = {
    +    // `argSet` collects all the pairs of variable names and their types, the first in the pair is
    +    // a type name and the second is a variable name.
    +    val argSet = mutable.Set[(String, String)]()
    +    val stack = mutable.Stack[Expression](aggExpr)
    +    while (stack.nonEmpty) {
    +      stack.pop() match {
    +        case e if subExprs.contains(e) =>
    +          val exprCode = subExprs(e)
    +          if (CodegenContext.isJavaIdentifier(exprCode.value)) {
    +            argSet += ((ctx.javaType(e.dataType), exprCode.value))
    +          }
    +          if (CodegenContext.isJavaIdentifier(exprCode.isNull)) {
    +            argSet += (("boolean", exprCode.isNull))
    +          }
    +          // Since the children possibly has common expressions, we push them here
    +          stack.pushAll(e.children)
    +        case ref: BoundReference
    +            if ctx.currentVars != null && ctx.currentVars(ref.ordinal) != null =>
    +          val value = ctx.currentVars(ref.ordinal).value
    +          val isNull = ctx.currentVars(ref.ordinal).isNull
    +          if (CodegenContext.isJavaIdentifier(value)) {
    +            argSet += ((ctx.javaType(ref.dataType), value))
    +          }
    +          if (CodegenContext.isJavaIdentifier(isNull)) {
    +            argSet += (("boolean", isNull))
    +          }
    +        case _: BoundReference =>
    +          argSet += (("InternalRow", ctx.INPUT_ROW))
    +        case e =>
    +          stack.pushAll(e.children)
    +      }
    +    }
    +
    +    argSet.toSet
    +  }
    +
    +  // Splits the aggregation into small functions because the HotSpot does not compile
    +  // too long functions.
    +  private def splitAggregateExpressions(
    +      ctx: CodegenContext,
    +      aggExprs: Seq[Expression],
    +      evalAndUpdateCodes: Seq[String],
    +      subExprs: Map[Expression, SubExprEliminationState],
    +      otherArgs: Seq[(String, String)] = Seq.empty): Seq[String] = {
    +    aggExprs.zipWithIndex.map { case (aggExpr, i) =>
    +      // The maximum number of parameters in non-static Java methods is 254, so this method gives
    +      // up splitting the code if the number goes over the limit.
    +      // You can find more information about the limit in the JVM specification:
    +      //   - The number of method parameters is limited to 255 by the definition of a method
    --- End diff --
    
    Unless you wanna check the types of all the parameters you might be better off halving this to 127 parameters for the worst case. Though I'm not sure how many codegens this affects...


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/84734/
    Test FAILed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test PASSed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/84724/
    Test FAILed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #84711 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84711/testReport)** for PR 19082 at commit [`d2dc025`](https://github.com/apache/spark/commit/d2dc0253aadb66bc97bdafe31ec3695bf06383e0).


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test FAILed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    What it means to solve the query? Is it too long gen'd codes?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    yes


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test FAILed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #81331 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81331/testReport)** for PR 19082 at commit [`57c8280`](https://github.com/apache/spark/commit/57c828092a80b608a068d69d669d44cd9a38d417).


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #81329 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81329/testReport)** for PR 19082 at commit [`abc5450`](https://github.com/apache/spark/commit/abc5450d6010e6a6db4f005782f60970160ddb4a).
     * This patch **fails SparkR unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Ya, I was just trying to do that tonight! Thanks for pinging me.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #81248 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81248/testReport)** for PR 19082 at commit [`6dacad4`](https://github.com/apache/spark/commit/6dacad4e6d0f588ce6f02e33da9625cc9ea116aa).


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/82499/
    Test FAILed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    @gatorsmile You can't just drop few words without explanation and simply say that others works don't work. I do respect your work/comments and you should respect my works too.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Btw, I'd like to know what the horizontal/vertical cuts you meant. Can you give a simple example?


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    sure! I'll check two more;
     - master + #18931 
     - master + this pr + #18931


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #81400 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81400/testReport)** for PR 19082 at commit [`6c502a9`](https://github.com/apache/spark/commit/6c502a94de64db1e33ce03ba64fc1183a689f5af).


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Could you rerun Q66 by increasing `spark.sql.codegen.hugeMethodLimit`?


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    > After horizontal/ring cutting, each operator will be in a single blocking loop. That means, whole-stage codegen is off.
    
    And do we have anything to cut the operators to individual single blocking loop? I didn't see we have anything to do this.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    The above reasoning also explains the motivation and the effect of #18931 too.
    
    The generated codes of query operators are extracted to individual smaller functions. It is beneficial to step in by JIT.



---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #81332 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81332/testReport)** for PR 19082 at commit [`e3722a0`](https://github.com/apache/spark/commit/e3722a002a8e62114d2685598687c1d86c7d18ca).


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/81351/
    Test FAILed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #83982 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/83982/testReport)** for PR 19082 at commit [`4c2816b`](https://github.com/apache/spark/commit/4c2816bd6513dc3ab2568584ecc8da6d1547fbf6).


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/83982/
    Test PASSed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #84734 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84734/testReport)** for PR 19082 at commit [`0e5d366`](https://github.com/apache/spark/commit/0e5d366dfce50ec3f879193f78c6a77213680926).


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #84711 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84711/testReport)** for PR 19082 at commit [`d2dc025`](https://github.com/apache/spark/commit/d2dc0253aadb66bc97bdafe31ec3695bf06383e0).
     * This patch **fails SparkR unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    I checked the three pattens on `q66`;
    ```
                                       q66
    master                           15960
    master + pr18931                 14226
    master + pr19082 + pr18931        1960
    ```
    You can all the result [here](https://docs.google.com/spreadsheets/d/1RCLxauxLPR64znllFu55fgMo1YXAY7ihZy929XHZa5s/edit?usp=sharing).


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/82502/
    Test PASSed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    ok, done (welcome any re-run requests);
    ```
    OpenJDK 64-Bit Server VM 1.8.0_141-b16 on Linux 4.9.38-16.35.amzn1.x86_64
    Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
    TPCDS Snappy:                            Best/Avg Time(ms)    Rate(M/s)   Per Row(ns)   Relative
    ------------------------------------------------------------------------------------------------
    q94(master)                                 25107 / 25322          0.2        6591.8       1.0X
    
    OpenJDK 64-Bit Server VM 1.8.0_141-b16 on Linux 4.9.38-16.35.amzn1.x86_64
    Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
    TPCDS Snappy:                            Best/Avg Time(ms)    Rate(M/s)   Per Row(ns)   Relative
    ------------------------------------------------------------------------------------------------
    q94(pr18931)                                25099 / 25383          0.2        6589.7       1.0X
    
    OpenJDK 64-Bit Server VM 1.8.0_141-b16 on Linux 4.9.38-16.35.amzn1.x86_64
    Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
    TPCDS Snappy:                            Best/Avg Time(ms)    Rate(M/s)   Per Row(ns)   Relative
    ------------------------------------------------------------------------------------------------
    q94(pr19082)                                25140 / 25361          0.2        6600.4       1.0X
    
    OpenJDK 64-Bit Server VM 1.8.0_141-b16 on Linux 4.9.38-16.35.amzn1.x86_64
    Intel(R) Xeon(R) CPU E5-2676 v3 @ 2.40GHz
    TPCDS Snappy:                            Best/Avg Time(ms)    Rate(M/s)   Per Row(ns)   Relative
    ------------------------------------------------------------------------------------------------
    q94(pr18931+pr19082                         25211 / 25532          0.2        6618.9       1.0X
    ```


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r156000426
  
    --- Diff: sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CodeGenerationSuite.scala ---
    @@ -380,4 +380,19 @@ class CodeGenerationSuite extends SparkFunSuite with ExpressionEvalHelper {
             s"Incorrect Evaluation: expressions: $exprAnd, actual: $actualAnd, expected: $expectedAnd")
         }
       }
    +
    +  test("SPARK-21870 check if CodegenContext.isJavaIdentifier works correctly") {
    +    assert(CodegenContext.isJavaIdentifier("agg_value") === true)
    +    assert(CodegenContext.isJavaIdentifier("agg_value1") === true)
    +    assert(CodegenContext.isJavaIdentifier("bhj_value4") === true)
    +    assert(CodegenContext.isJavaIdentifier("smj_value6") === true)
    +    assert(CodegenContext.isJavaIdentifier("rdd_value7") === true)
    +    assert(CodegenContext.isJavaIdentifier("scan_isNull") === true)
    +    assert(CodegenContext.isJavaIdentifier("test") === true)
    +    assert(CodegenContext.isJavaIdentifier("true") === false)
    +    assert(CodegenContext.isJavaIdentifier("false") === false)
    +    assert(CodegenContext.isJavaIdentifier("390239") === false)
    +    assert(CodegenContext.isJavaIdentifier(""""literal"""") === false)
    +    assert(CodegenContext.isJavaIdentifier(""""double"""") === false)
    --- End diff --
    
    ```Scala
        import CodegenContext.isJavaIdentifier
        // positive cases
        assert(isJavaIdentifier("agg_value"))
        assert(isJavaIdentifier("agg_value1"))
        assert(isJavaIdentifier("bhj_value4"))
        assert(isJavaIdentifier("smj_value6"))
        assert(isJavaIdentifier("rdd_value7"))
        assert(isJavaIdentifier("scan_isNull"))
        assert(isJavaIdentifier("test"))
        // negative cases
        assert(!isJavaIdentifier("true"))
        assert(!isJavaIdentifier("false"))
        assert(!isJavaIdentifier("390239"))
        assert(!isJavaIdentifier(""""literal""""))
        assert(!isJavaIdentifier(""""double""""))
    ```


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test PASSed.


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r163305111
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -825,52 +924,92 @@ case class HashAggregateExec(
         ctx.currentVars = new Array[ExprCode](aggregateBufferAttributes.length) ++ input
     
         val updateRowInRegularHashMap: String = {
    -      ctx.INPUT_ROW = unsafeRowBuffer
    +      // We need to copy the aggregation row buffer to a local row first because each aggregate
    +      // function directly updates the buffer when it finishes.
    --- End diff --
    
    why does this matter? We should avoid unnecessary data copy as possible as we can.


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r156092752
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -256,6 +258,85 @@ case class HashAggregateExec(
          """.stripMargin
       }
     
    +  // Extracts all the input variable references for a given `aggExpr`. This result will be used
    +  // to split aggregation into small functions.
    +  private def getInputVariableReferences(
    +      ctx: CodegenContext,
    +      aggExpr: Expression,
    +      subExprs: Map[Expression, SubExprEliminationState]): Set[(String, String)] = {
    +    // `argSet` collects all the pairs of variable names and their types, the first in the pair is
    +    // a type name and the second is a variable name.
    +    val argSet = mutable.Set[(String, String)]()
    +    val stack = mutable.Stack[Expression](aggExpr)
    +    while (stack.nonEmpty) {
    +      stack.pop() match {
    +        case e if subExprs.contains(e) =>
    +          val exprCode = subExprs(e)
    +          if (CodegenContext.isJavaIdentifier(exprCode.value)) {
    +            argSet += ((ctx.javaType(e.dataType), exprCode.value))
    +          }
    +          if (CodegenContext.isJavaIdentifier(exprCode.isNull)) {
    +            argSet += (("boolean", exprCode.isNull))
    +          }
    +          // Since the children possibly has common expressions, we push them here
    +          stack.pushAll(e.children)
    +        case ref: BoundReference
    +            if ctx.currentVars != null && ctx.currentVars(ref.ordinal) != null =>
    +          val value = ctx.currentVars(ref.ordinal).value
    +          val isNull = ctx.currentVars(ref.ordinal).isNull
    +          if (CodegenContext.isJavaIdentifier(value)) {
    +            argSet += ((ctx.javaType(ref.dataType), value))
    +          }
    +          if (CodegenContext.isJavaIdentifier(isNull)) {
    +            argSet += (("boolean", isNull))
    +          }
    +        case _: BoundReference =>
    +          argSet += (("InternalRow", ctx.INPUT_ROW))
    +        case e =>
    +          stack.pushAll(e.children)
    +      }
    +    }
    +
    +    argSet.toSet
    +  }
    +
    +  // Splits aggregate code into small functions because JVMs does not compile too long functions
    +  private def splitAggregateExpressions(
    +      ctx: CodegenContext,
    +      aggExprs: Seq[Expression],
    +      evalAndUpdateCodes: Seq[String],
    +      subExprs: Map[Expression, SubExprEliminationState],
    +      otherArgs: Seq[(String, String)] = Seq.empty): Seq[String] = {
    +    aggExprs.zipWithIndex.map { case (aggExpr, i) =>
    +      // The maximum length of parameters in non-static Java methods is 254, but a parameter of
    +      // type long or double contributes two units to the length. So, this method gives up
    +      // splitting the code if the parameter length goes over 127.
    +      val args = (getInputVariableReferences(ctx, aggExpr, subExprs) ++ otherArgs).toSeq
    +
    +      // This is for testing/benchmarking only
    +      val maxParamNumInJavaMethod =
    +          sqlContext.getConf("spark.sql.codegen.aggregate.maxParamNumInJavaMethod", null) match {
    --- End diff --
    
    ok


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test FAILed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #84807 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84807/testReport)** for PR 19082 at commit [`2555e5a`](https://github.com/apache/spark/commit/2555e5a3eb1223a19f3f523abc7c1e5a9251e528).
     * This patch passes all tests.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test PASSed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/84713/
    Test FAILed.


---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by kiszk <gi...@git.apache.org>.
Github user kiszk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r136455832
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -244,6 +246,92 @@ case class HashAggregateExec(
     
       protected override val shouldStopRequired = false
     
    +  // We assume a prefix has lower cases and a name has camel cases
    +  private val variableName = "^[a-z]+_[a-zA-Z]+[0-9]*".r
    +
    +  // Returns true if a given name id belongs to this `CodegenContext`
    +  private def isVariable(nameId: String): Boolean = nameId match {
    +    case variableName() => true
    +    case _ => false
    +  }
    +
    +  // Extracts all the outer references for a given `aggExpr`. This result will be used to split
    +  // aggregation into small functions.
    +  private def getOuterReferences(
    +      ctx: CodegenContext,
    +      aggExpr: Expression,
    +      subExprs: Map[Expression, SubExprEliminationState]): Set[(String, String)] = {
    +    val stack = mutable.Stack[Expression](aggExpr)
    +    val argSet = mutable.Set[(String, String)]()
    +    val addIfNotLiteral = (value: String, tpe: String) => {
    +      if (isVariable(value)) {
    +        argSet += ((tpe, value))
    +      }
    +    }
    +    while (stack.nonEmpty) {
    +      stack.pop() match {
    +        case e if subExprs.contains(e) =>
    +          val exprCode = subExprs(e)
    +          addIfNotLiteral(exprCode.value, ctx.javaType(e.dataType))
    +          addIfNotLiteral(exprCode.isNull, "boolean")
    +          // Since the children possibly has common expressions, we push them here
    +          stack.pushAll(e.children)
    +        case ref: BoundReference
    +            if ctx.currentVars != null && ctx.currentVars(ref.ordinal) != null =>
    +          val argVal = ctx.currentVars(ref.ordinal).value
    +          addIfNotLiteral(argVal, ctx.javaType(ref.dataType))
    +          addIfNotLiteral(ctx.currentVars(ref.ordinal).isNull, "boolean")
    +        case _: BoundReference =>
    +          argSet += (("InternalRow", ctx.INPUT_ROW))
    +        case e =>
    +          stack.pushAll(e.children)
    +      }
    +    }
    +
    +    argSet.toSet
    +  }
    +
    +  // Splits the aggregation into small functions because the HotSpot does not compile
    +  // too long functions.
    +  private def splitAggregateExpressions(
    +      ctx: CodegenContext,
    +      aggExprs: Seq[Expression],
    +      evalAndUpdateCodes: Seq[String],
    +      subExprs: Map[Expression, SubExprEliminationState],
    +      otherArgs: Seq[(String, String)] = Seq.empty): Seq[String] = {
    +    aggExprs.zipWithIndex.map { case (aggExpr, i) =>
    +      // The maximum number of parameters in Java methods is 255, so this method gives up splitting
    +      // the code if the number goes over the limit.
    +      // You can find more information about the limit in the JVM specification:
    +      //   - The number of method parameters is limited to 255 by the definition of a method
    +      //     descriptor, where the limit includes one unit for this in the case of instance
    +      //     or interface method invocations.
    +      val args = (getOuterReferences(ctx, aggExpr, subExprs) ++ otherArgs).toSeq
    +
    +      // This is for testing/benchmarking only
    +      val maxParamNumInJavaMethod =
    +          sqlContext.getConf("spark.sql.codegen.aggregate.maxParamNumInJavaMethod", null) match {
    --- End diff --
    
    Can we add a check code if a user specify a value that is more than 255?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    @kiszk This is one of the solutions if we can remove the limit of num of parameters. However, this does not resolve all the issues. For example, the method becomes too big to inline. 


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Jenkins, retest this please.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Just FYI, the test failure is not related to this PR. 


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #81248 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/81248/testReport)** for PR 19082 at commit [`6dacad4`](https://github.com/apache/spark/commit/6dacad4e6d0f588ce6f02e33da9625cc9ea116aa).
     * This patch **fails SparkR unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #82615 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/82615/testReport)** for PR 19082 at commit [`5584bdb`](https://github.com/apache/spark/commit/5584bdbdf057c22593f4856069e53fd52a222fe1).


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Sure. I'm totally agreed. We need to know the advantages and possible impacts if any when merging this PR and #18931,. It is good @kiszk and @rednaxelafx can help review this PR and #18931.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #83981 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/83981/testReport)** for PR 19082 at commit [`28b47e5`](https://github.com/apache/spark/commit/28b47e52bb262edaf73ad2aa44a2db68eb3a9847).
     * This patch **fails to build**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test FAILed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    retest this please.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    @gatorsmile could you check? Thanks!


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    After quickly scanning this change, I found actually this and #18931 are orthogonal.
    
    This PR goes to split the aggregation expressions into functions. So it prevents long aggregation code caused by long gen'd codes expressions like `Kurtosis`.
    
    #18931 goes to break the long gen'd codes caused by chain of execution operators by splitting gen'd codes of operators into functions.



---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    @gatorsmile can you close the jira ticket with @viirya assigned? Thanks!


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test FAILed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #84724 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84724/testReport)** for PR 19082 at commit [`1ed010f`](https://github.com/apache/spark/commit/1ed010f49cfdb9e0bfc3bdf65e974bda191f76e0).
     * This patch **fails SparkR unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #84713 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84713/testReport)** for PR 19082 at commit [`f866b11`](https://github.com/apache/spark/commit/f866b110a27e4405c1e51fd0684d6d22e19ed2a6).


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Merged build finished. Test FAILed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Ok. Any comments from @kiszk and @rednaxelafx on this topic? :)


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Yeah, once we exceed `hugeMethodLimit`, wholestage codegen is disabled. Can you tell me how `hugeMethodLimit` makes each operator to a single blocking loop? We didn't run codegen now.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #84717 has started](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84717/testReport)** for PR 19082 at commit [`1ed010f`](https://github.com/apache/spark/commit/1ed010f49cfdb9e0bfc3bdf65e974bda191f76e0).


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Aggregation code is not the only too long gen'd codes. Any big enough queries under current whole-stage codegen can produce too long gen'd codes.
    
    Compared with special split for aggregation code like this, I'd like to push #18931 which is a more general fix.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark pull request #19082: [SPARK-21870][SQL] Split aggregation code into sm...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19082#discussion_r143897243
  
    --- Diff: sql/core/src/main/scala/org/apache/spark/sql/execution/aggregate/HashAggregateExec.scala ---
    @@ -244,6 +246,89 @@ case class HashAggregateExec(
     
       protected override val shouldStopRequired = false
     
    +  // Extracts all the input variable references for a given `aggExpr`. This result will be used
    +  // to split aggregation into small functions.
    +  private def getInputVariableReferences(
    +      ctx: CodegenContext,
    +      aggExpr: Expression,
    +      subExprs: Map[Expression, SubExprEliminationState]): Set[(String, String)] = {
    +    // `argSet` collects all the pairs of variable names and their types, the first in the pair is
    +    // a type name and the second is a variable name.
    +    val argSet = mutable.Set[(String, String)]()
    +    val stack = mutable.Stack[Expression](aggExpr)
    +    while (stack.nonEmpty) {
    +      stack.pop() match {
    +        case e if subExprs.contains(e) =>
    +          val exprCode = subExprs(e)
    +          if (CodegenContext.isJavaIdentifier(exprCode.value)) {
    +            argSet += ((ctx.javaType(e.dataType), exprCode.value))
    +          }
    +          if (CodegenContext.isJavaIdentifier(exprCode.isNull)) {
    +            argSet += (("boolean", exprCode.isNull))
    +          }
    +          // Since the children possibly has common expressions, we push them here
    +          stack.pushAll(e.children)
    +        case ref: BoundReference
    +            if ctx.currentVars != null && ctx.currentVars(ref.ordinal) != null =>
    +          val value = ctx.currentVars(ref.ordinal).value
    +          val isNull = ctx.currentVars(ref.ordinal).isNull
    +          if (CodegenContext.isJavaIdentifier(value)) {
    +            argSet += ((ctx.javaType(ref.dataType), value))
    +          }
    +          if (CodegenContext.isJavaIdentifier(isNull)) {
    +            argSet += (("boolean", isNull))
    +          }
    +        case _: BoundReference =>
    +          argSet += (("InternalRow", ctx.INPUT_ROW))
    +        case e =>
    +          stack.pushAll(e.children)
    +      }
    +    }
    +
    +    argSet.toSet
    +  }
    +
    +  // Splits the aggregation into small functions because the HotSpot does not compile
    +  // too long functions.
    +  private def splitAggregateExpressions(
    +      ctx: CodegenContext,
    +      aggExprs: Seq[Expression],
    +      evalAndUpdateCodes: Seq[String],
    +      subExprs: Map[Expression, SubExprEliminationState],
    +      otherArgs: Seq[(String, String)] = Seq.empty): Seq[String] = {
    +    aggExprs.zipWithIndex.map { case (aggExpr, i) =>
    +      // The maximum number of parameters in non-static Java methods is 254, so this method gives
    +      // up splitting the code if the number goes over the limit.
    +      // You can find more information about the limit in the JVM specification:
    +      //   - The number of method parameters is limited to 255 by the definition of a method
    --- End diff --
    
    @a10y Thanks for the info. Very helpful.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    The latest regression (introduced by `spark.sql.codegen.hugeMethodLimit`) clearly shows the ring/onion/horizontal cut (https://github.com/apache/spark/pull/18931) could introduce a performance regression. 
    
    Vertical cuts like this PR is more promising. However, it still does not resolve all the performance regressions introduced by `spark.sql.codegen.hugeMethodLimit`


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test PASSed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/81400/
    Test PASSed.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    The relation is very clear. Let me copy what I said above
    
    > Just imagine we have two nodes, we want to do a horizontal/ring cut. Basically, in this scenario, horizontal/ring cutting means whether we do a whole-stage codegen or not.
    
    After horizontal/ring cutting, each operator will be in a single blocking loop. That means, whole-stage codegen is off. 


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by AmplabJenkins <gi...@git.apache.org>.
Github user AmplabJenkins commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Test FAILed.
    Refer to this link for build results (access rights to CI server needed): 
    https://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/81332/
    Test FAILed.


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    No. I think you should explain it because this is your concern. You just need to point out, where is the single blocking loop for the two operators?


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    @gatorsmile Are you talking about this: https://en.wikipedia.org/wiki/Loop_nest_optimization?
    
    



---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by maropu <gi...@git.apache.org>.
Github user maropu commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    @viirya @rednaxelafx @kiszk okay, could you check again?


---
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 infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    The current `spark.sql.codegen.hugeMethodLimit` shows an extreme case. 
    
    Just imagine we have two nodes, we want to do a horizontal/ring cut. Basically, in this scenario, horizontal/ring cutting means whether we do a whole-stage codegen or not. 


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    @gatorsmile If my words make you upset, I'm sorry. It's you right to raise suspicion against any PRs. I do respect this right.
    
    Maybe I'm wrong and there actually is a possible regression. Appreciate if anyone has enough insights on this topic can share their thoughts. Thank you.
    



---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by viirya <gi...@git.apache.org>.
Github user viirya commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    @gatorsmile hmm, I don't know how you get to the conclusion. Is `spark.sql.codegen.hugeMethodLimit` any related to codegen cut? I think it is just a threshold used to determine whether to enable wholestage or not.
    
    Can you also explain the horizontal/vertical cuts?
    
    Btw, we didn't see any performance regression based on the benchmark numbers. 


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by gatorsmile <gi...@git.apache.org>.
Github user gatorsmile commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Sorry, it is really hard to explain it to you. Maybe you can first think about why the whole-stage codegen works better the previous solution? 


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by cloud-fan <gi...@git.apache.org>.
Github user cloud-fan commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    Sorry for missing the excellent discussions here. After more thoughts, I feel this patch still makes sense. Currently we have 3 cases that may cause large method with whole stage codegen:
    
    * a super complex expression. Eventually this would be fixed by #19813
    * a complex single operator, e.g. aggregate with 100 aggregate functions. This is targeted by this PR.
    * a complex query. This is targeted by #18931
    
    All of them are orthogonal but non-trivial, I don't see any of them can cover all other cases.


---

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


[GitHub] spark issue #19082: [SPARK-21870][SQL] Split aggregation code into small fun...

Posted by SparkQA <gi...@git.apache.org>.
Github user SparkQA commented on the issue:

    https://github.com/apache/spark/pull/19082
  
    **[Test build #84717 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/84717/testReport)** for PR 19082 at commit [`1ed010f`](https://github.com/apache/spark/commit/1ed010f49cfdb9e0bfc3bdf65e974bda191f76e0).
     * This patch **fails SparkR unit tests**.
     * This patch merges cleanly.
     * This patch adds no public classes.


---

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