Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/19811#discussion_r157108429
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala
---
@@ -138,21 +138,50 @@ class CodegenContext {
/**
* 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:
+ * 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)]
+
+ // An map keyed by mutable states' types holds the status of
mutableStateArray
+ 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]
+
+ // Holding names and current index of mutableStateArrays for a certain
type
+ 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
+
+ def getNextSlot(): String = {
--- End diff --
```scala
/**
* 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`. Once reaching the
* threshold, new compacted array is created.
*/
```
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]