Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19811#discussion_r157794484
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala
 ---
    @@ -137,22 +137,63 @@ class CodegenContext {
       var currentVars: Seq[ExprCode] = null
     
       /**
    -   * Holding expressions' mutable states like 
`MonotonicallyIncreasingID.count` as a
    -   * 3-tuple: java type, variable name, code to init it.
    -   * As an example, ("int", "count", "count = 0;") will produce code:
    +   * Holding expressions' inlined mutable states like 
`MonotonicallyIncreasingID.count` as a
    +   * 2-tuple: java type, variable name.
    +   * As an example, ("int", "count") will produce code:
        * {{{
        *   private int count;
        * }}}
    -   * as a member variable, and add
    -   * {{{
    -   *   count = 0;
    -   * }}}
    -   * to the constructor.
    +   * as a member variable
        *
        * They will be kept as member variables in generated classes like 
`SpecificProjection`.
        */
    -  val mutableStates: mutable.ArrayBuffer[(String, String, String)] =
    -    mutable.ArrayBuffer.empty[(String, String, String)]
    +  val inlinedMutableStates: mutable.ArrayBuffer[(String, String)] =
    +    mutable.ArrayBuffer.empty[(String, String)]
    +
    +  /**
    +   * The mapping between mutable state types and corrseponding compacted 
arrays.
    +   * The keys are java type string. The values are [[MutableStateArrays]] 
which encapsulates
    +   * the compacted arrays for the mutable states with the same java type.
    +   */
    +  val arrayCompactedMutableStates: mutable.Map[String, MutableStateArrays] 
=
    +    mutable.Map.empty[String, MutableStateArrays]
    +
    +  // An array holds the code that will initialize each state
    +  val mutableStateInitCode: mutable.ArrayBuffer[String] =
    +    mutable.ArrayBuffer.empty[String]
    +
    +  /**
    +   * This class holds a set of names of mutableStateArrays that is used 
for compacting mutable
    +   * states for a certain type, and holds the next available slot of the 
current compacted array.
    +   */
    +  class MutableStateArrays {
    +    val arrayNames = mutable.ListBuffer.empty[String]
    +    createNewArray()
    +
    +    private[this] var currentIndex = 0
    +
    +    private def createNewArray() = 
arrayNames.append(freshName("mutableStateArray"))
    +
    +    def getCurrentIndex: Int = currentIndex
    +
    +    /**
    +     * Returns the reference of next available slot in current compacted 
array. The size of each
    +     * compacted array is controlled by the config 
`CodeGenerator.MUTABLESTATEARRAY_SIZE_LIMIT`.
    --- End diff --
    
    nit: `CodeGenerator.MUTABLESTATEARRAY_SIZE_LIMIT` is not a config


---

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

Reply via email to