You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2021/05/06 16:18:47 UTC
[GitHub] [spark] kiszk commented on a change in pull request #32457: [SPARK-35329][SQL] Split generated switch code into pieces in ExpandExec
kiszk commented on a change in pull request #32457:
URL: https://github.com/apache/spark/pull/32457#discussion_r627573818
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/ExpandExec.scala
##########
@@ -152,38 +153,59 @@ case class ExpandExec(
// This column is the same across all output rows. Just generate code for it here.
BindReferences.bindReference(firstExpr, attributeSeq).genCode(ctx)
} else {
- val isNull = ctx.freshName("isNull")
- val value = ctx.freshName("value")
- val code = code"""
- |boolean $isNull = true;
- |${CodeGenerator.javaType(firstExpr.dataType)} $value =
- | ${CodeGenerator.defaultValue(firstExpr.dataType)};
- """.stripMargin
+ val isNull = ctx.addMutableState(
+ CodeGenerator.JAVA_BOOLEAN,
+ "resultIsNull",
+ v => s"$v = true;")
+ val value = ctx.addMutableState(
+ CodeGenerator.javaType(firstExpr.dataType),
+ "resultValue",
+ v => s"$v = ${CodeGenerator.defaultValue(firstExpr.dataType)};")
+
ExprCode(
- code,
JavaCode.isNullVariable(isNull),
JavaCode.variable(value, firstExpr.dataType))
}
}
// Part 2: switch/case statements
val cases = projections.zipWithIndex.map { case (exprs, row) =>
- var updateCode = ""
- for (col <- exprs.indices) {
+ val updateCode = mutable.ArrayBuffer[String]()
+ exprs.indices.foreach { col =>
if (!sameOutput(col)) {
- val ev = BindReferences.bindReference(exprs(col), attributeSeq).genCode(ctx)
- updateCode +=
- s"""
- |${ev.code}
- |${outputColumns(col).isNull} = ${ev.isNull};
- |${outputColumns(col).value} = ${ev.value};
- """.stripMargin
+ val boundExpr = BindReferences.bindReference(exprs(col), attributeSeq)
+ val ev = boundExpr.genCode(ctx)
+ val inputVars = CodeGenerator.getLocalInputVariableValues(ctx, boundExpr)._1.toSeq
+ val argList = inputVars.map { v =>
Review comment:
Is it better move to this line after line 183?
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/execution/ExpandExec.scala
##########
@@ -152,38 +153,59 @@ case class ExpandExec(
// This column is the same across all output rows. Just generate code for it here.
BindReferences.bindReference(firstExpr, attributeSeq).genCode(ctx)
} else {
- val isNull = ctx.freshName("isNull")
- val value = ctx.freshName("value")
- val code = code"""
- |boolean $isNull = true;
- |${CodeGenerator.javaType(firstExpr.dataType)} $value =
- | ${CodeGenerator.defaultValue(firstExpr.dataType)};
- """.stripMargin
+ val isNull = ctx.addMutableState(
+ CodeGenerator.JAVA_BOOLEAN,
+ "resultIsNull",
+ v => s"$v = true;")
+ val value = ctx.addMutableState(
+ CodeGenerator.javaType(firstExpr.dataType),
+ "resultValue",
+ v => s"$v = ${CodeGenerator.defaultValue(firstExpr.dataType)};")
+
ExprCode(
- code,
JavaCode.isNullVariable(isNull),
JavaCode.variable(value, firstExpr.dataType))
}
}
// Part 2: switch/case statements
val cases = projections.zipWithIndex.map { case (exprs, row) =>
- var updateCode = ""
- for (col <- exprs.indices) {
+ val updateCode = mutable.ArrayBuffer[String]()
+ exprs.indices.foreach { col =>
if (!sameOutput(col)) {
- val ev = BindReferences.bindReference(exprs(col), attributeSeq).genCode(ctx)
- updateCode +=
- s"""
- |${ev.code}
- |${outputColumns(col).isNull} = ${ev.isNull};
- |${outputColumns(col).value} = ${ev.value};
- """.stripMargin
+ val boundExpr = BindReferences.bindReference(exprs(col), attributeSeq)
+ val ev = boundExpr.genCode(ctx)
+ val inputVars = CodeGenerator.getLocalInputVariableValues(ctx, boundExpr)._1.toSeq
+ val argList = inputVars.map { v =>
Review comment:
Is it better to move to this line after line 183?
--
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:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org