@@ -128,7 +128,7 @@ class CodegenContext {
128128 * `currentVars` to null, or set `currentVars(i)` to null for certain columns, before calling
129129 * `Expression.genCode`.
130130 */
131- final var INPUT_ROW = " i"
131+ var INPUT_ROW = " i"
132132
133133 /**
134134 * Holding a list of generated columns as input of current operator, will be used by
@@ -146,22 +146,30 @@ class CodegenContext {
146146 * as a member variable
147147 *
148148 * They will be kept as member variables in generated classes like `SpecificProjection`.
149+ *
150+ * Exposed for tests only.
149151 */
150- val inlinedMutableStates : mutable.ArrayBuffer [(String , String )] =
152+ private [catalyst] val inlinedMutableStates : mutable.ArrayBuffer [(String , String )] =
151153 mutable.ArrayBuffer .empty[(String , String )]
152154
153155 /**
154156 * The mapping between mutable state types and corrseponding compacted arrays.
155157 * The keys are java type string. The values are [[MutableStateArrays ]] which encapsulates
156158 * the compacted arrays for the mutable states with the same java type.
159+ *
160+ * Exposed for tests only.
157161 */
158- val arrayCompactedMutableStates : mutable.Map [String , MutableStateArrays ] =
162+ private [catalyst] val arrayCompactedMutableStates : mutable.Map [String , MutableStateArrays ] =
159163 mutable.Map .empty[String , MutableStateArrays ]
160164
161165 // An array holds the code that will initialize each state
162- val mutableStateInitCode : mutable.ArrayBuffer [String ] =
166+ // Exposed for tests only.
167+ private [catalyst] val mutableStateInitCode : mutable.ArrayBuffer [String ] =
163168 mutable.ArrayBuffer .empty[String ]
164169
170+ // Tracks the names of all the mutable states.
171+ private val mutableStateNames : mutable.HashSet [String ] = mutable.HashSet .empty
172+
165173 /**
166174 * This class holds a set of names of mutableStateArrays that is used for compacting mutable
167175 * states for a certain type, and holds the next available slot of the current compacted array.
@@ -172,7 +180,11 @@ class CodegenContext {
172180
173181 private [this ] var currentIndex = 0
174182
175- private def createNewArray () = arrayNames.append(freshName(" mutableStateArray" ))
183+ private def createNewArray () = {
184+ val newArrayName = freshName(" mutableStateArray" )
185+ mutableStateNames += newArrayName
186+ arrayNames.append(newArrayName)
187+ }
176188
177189 def getCurrentIndex : Int = currentIndex
178190
@@ -241,6 +253,7 @@ class CodegenContext {
241253 val initCode = initFunc(varName)
242254 inlinedMutableStates += ((javaType, varName))
243255 mutableStateInitCode += initCode
256+ mutableStateNames += varName
244257 varName
245258 } else {
246259 val arrays = arrayCompactedMutableStates.getOrElseUpdate(javaType, new MutableStateArrays )
@@ -930,16 +943,11 @@ class CodegenContext {
930943 // inline execution if only one block
931944 blocks.head
932945 } else {
933- if (Utils .isTesting) {
934- // Passing global variables to the split method is dangerous, as any mutating to it is
935- // ignored and may lead to unexpected behavior.
936- // We don't need to check `arrayCompactedMutableStates` here, as it results to array access
937- // code and will raise compile error if we use it in parameter list.
938- val mutableStateNames = inlinedMutableStates.map(_._2).toSet
939- arguments.foreach { case (_, name) =>
940- assert(! mutableStateNames.contains(name),
941- s " split function argument $name cannot be a global variable. " )
942- }
946+ // Passing global variables to the split method is dangerous, as any mutating to it is
947+ // ignored and may lead to unexpected behavior.
948+ arguments.foreach { case (_, name) =>
949+ assert(! mutableStateNames.contains(name),
950+ s " [BUG] split function argument $name cannot be a global variable. " )
943951 }
944952
945953 val func = freshName(funcName)
0 commit comments