Github user kiszk commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19811#discussion_r157517422
  
    --- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CodeGenerationSuite.scala
 ---
    @@ -385,20 +385,43 @@ class CodeGenerationSuite extends SparkFunSuite with 
ExpressionEvalHelper {
         val ctx = new CodegenContext
         val schema = new StructType().add("a", IntegerType).add("b", 
StringType)
         CreateExternalRow(Seq(Literal(1), Literal("x")), schema).genCode(ctx)
    -    assert(ctx.mutableStates.isEmpty)
    +    assert(ctx.inlinedMutableStates.isEmpty)
       }
     
       test("SPARK-22696: InitializeJavaBean should not use global variables") {
         val ctx = new CodegenContext
         InitializeJavaBean(Literal.fromObject(new java.util.LinkedList[Int]),
           Map("add" -> Literal(1))).genCode(ctx)
    -    assert(ctx.mutableStates.isEmpty)
    +    assert(ctx.inlinedMutableStates.isEmpty)
       }
     
       test("SPARK-22716: addReferenceObj should not add mutable states") {
         val ctx = new CodegenContext
         val foo = new Object()
         ctx.addReferenceObj("foo", foo)
    -    assert(ctx.mutableStates.isEmpty)
    +    assert(ctx.inlinedMutableStates.isEmpty)
    +  }
    +
    +  test("SPARK-18016: define mutable states by using an array") {
    +    val ctx1 = new CodegenContext
    +    for (i <- 1 to CodeGenerator.OUTER_CLASS_VARIABLES_THRESHOLD + 10) {
    +      ctx1.addMutableState(ctx1.JAVA_INT, "i", v => s"$v = $i;")
    +    }
    +    assert(ctx1.inlinedMutableStates.size == 
CodeGenerator.OUTER_CLASS_VARIABLES_THRESHOLD)
    +    // When the number of primitive type mutable states is over the 
threshold, others are
    +    // allocated into an array
    --- End diff --
    
    Yeah, I agree. In the future, we hope we have an AST based codegen 
framework.


---

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

Reply via email to