maropu commented on a change in pull request #20965: [SPARK-21870][SQL] Split 
aggregation code into small functions
URL: https://github.com/apache/spark/pull/20965#discussion_r316925784
 
 

 ##########
 File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/codegen/CodeGenerator.scala
 ##########
 @@ -1612,6 +1612,49 @@ object CodeGenerator extends Logging {
     }
   }
 
+  /**
+   * Extracts all the input variables from references and subexpression 
elimination states
+   * for a given `expr`. This result will be used to split the generated code 
of
+   * expressions into multiple functions.
+   */
+  def getLocalInputVariableValues(
+      context: CodegenContext,
+      expr: Expression,
+      subExprs: Map[Expression, SubExprEliminationState]): Seq[((String, 
DataType), Expression)] = {
+    val argMap = mutable.Map[(String, DataType), Expression]()
+    val stack = mutable.Stack[Expression](expr)
+    while (stack.nonEmpty) {
+      stack.pop() match {
+        case e if subExprs.contains(e) =>
+          val exprCode = subExprs(e)
+          val SubExprEliminationState(isNull, value) = exprCode
+          if (value.isInstanceOf[VariableValue]) {
 
 Review comment:
   Yea, that value could be `TrueLiteral`, `FalseLiteral`, or the others. This 
method needs to collect local variables for split functions because split 
functions can access global and literal variables directly but they can't do 
local variables. So, we need to collect local variables here and pass them into 
split functions.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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

Reply via email to