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

    https://github.com/apache/spark/pull/19940#discussion_r156073714
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala
 ---
    @@ -184,6 +190,27 @@ class CodegenContext {
         mutableStates += ((javaType, variableName, initCode))
       }
     
    +  /**
    +   * Add a mutable state as a field to the generated class only if it does 
not exist yet a field
    +   * with that name. This helps reducing the number of the generated 
class' fields, since the same
    +   * variable can be reused by many functions.
    +   *
    +   * Internally, this method calls `addMutableState`.
    +   *
    +   * @param javaType Java type of the field.
    +   * @param variableName Name of the field.
    +   * @param initCode The statement(s) to put into the init() method to 
initialize this field.
    +   */
    +  def addSingleMutableState(
    +      javaType: String,
    +      variableName: String,
    +      initCode: String = ""): Unit = {
    +    if (!singleMutableStates.contains(variableName)) {
    +      addMutableState(javaType, variableName, initCode)
    --- End diff --
    
    Please also check if the java type is the same. If one expression uses the 
same name with different type, we should alert it early.


---

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

Reply via email to