kiszk commented on a change in pull request #32457:
URL: https://github.com/apache/spark/pull/32457#discussion_r630690037



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/execution/ExpandExec.scala
##########
@@ -180,40 +180,55 @@ case class ExpandExec(
         }
       }.unzip
 
-      val updateCode = exprCodesWithIndices.map { case (col, ev) =>
+      val inputVars = inputVarSets.foldLeft(Set.empty[VariableValue])(_ ++ _)
+      (row, exprCodesWithIndices, inputVars.toSeq)
+    }
+
+    def generateUpdateCode(exprCodes: Seq[(Int, ExprCode)]): String = {
+      exprCodes.map { case (col, ev) =>
         s"""
            |${ev.code}
            |${outputColumns(col).isNull} = ${ev.isNull};
            |${outputColumns(col).value} = ${ev.value};
          """.stripMargin
-      }
+      }.mkString("\n")
+    }
 
-      val splitThreshold = SQLConf.get.methodSplitThreshold
-      val inputVars = inputVarSets.foldLeft(Set.empty[VariableValue])(_ ++ _)
-      val paramLength = 
CodeGenerator.calculateParamLengthFromExprValues(inputVars.toSeq)
-      val maybeSplitUpdateCode = if 
(CodeGenerator.isValidParamLength(paramLength) &&
-          exprCodesWithIndices.map(_._2.code.length).sum > splitThreshold) {
-        val switchCaseFunc = ctx.freshName("switchCaseCode")
-        val argList = inputVars.map { v =>
-          s"${CodeGenerator.typeName(v.javaType)} ${v.variableName}"
+    val splitThreshold = SQLConf.get.methodSplitThreshold
+    val cases = if (switchCaseExprs.flatMap(_._2.map(_._2.code.length)).sum > 
splitThreshold) {

Review comment:
       Can we call `generateUpdateCode` only once before line 198?   
   IMHO, code in all three cases (line 203-, line 216, and line 225-) is 
generated by `generateUpdateCode()`.




-- 
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:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to