Skip to content
Snippets Groups Projects
Commit 18bcbbdd authored by Nong Li's avatar Nong Li Committed by Reynold Xin
Browse files

[SPARK-13270][SQL] Remove extra new lines in whole stage codegen and include...

[SPARK-13270][SQL] Remove extra new lines in whole stage codegen and include pipeline plan in comments.

Author: Nong Li <nong@databricks.com>

Closes #11155 from nongli/spark-13270.
parent e88bff12
No related branches found
No related tags found
No related merge requests found
...@@ -25,6 +25,20 @@ package org.apache.spark.sql.catalyst.expressions.codegen ...@@ -25,6 +25,20 @@ package org.apache.spark.sql.catalyst.expressions.codegen
*/ */
object CodeFormatter { object CodeFormatter {
def format(code: String): String = new CodeFormatter().addLines(code).result() def format(code: String): String = new CodeFormatter().addLines(code).result()
def stripExtraNewLines(input: String): String = {
val code = new StringBuilder
var lastLine: String = "dummy"
input.split('\n').foreach { l =>
val line = l.trim()
val skip = line == "" && (lastLine == "" || lastLine.endsWith("{"))
if (!skip) {
code.append(line)
code.append("\n")
}
lastLine = line
}
code.result()
}
} }
private class CodeFormatter { private class CodeFormatter {
......
...@@ -237,6 +237,9 @@ case class WholeStageCodegen(plan: CodegenSupport, children: Seq[SparkPlan]) ...@@ -237,6 +237,9 @@ case class WholeStageCodegen(plan: CodegenSupport, children: Seq[SparkPlan])
return new GeneratedIterator(references); return new GeneratedIterator(references);
} }
/** Codegened pipeline for:
* ${plan.treeString.trim}
*/
class GeneratedIterator extends org.apache.spark.sql.execution.BufferedRowIterator { class GeneratedIterator extends org.apache.spark.sql.execution.BufferedRowIterator {
private Object[] references; private Object[] references;
...@@ -256,8 +259,9 @@ case class WholeStageCodegen(plan: CodegenSupport, children: Seq[SparkPlan]) ...@@ -256,8 +259,9 @@ case class WholeStageCodegen(plan: CodegenSupport, children: Seq[SparkPlan])
""" """
// try to compile, helpful for debug // try to compile, helpful for debug
// println(s"${CodeFormatter.format(source)}") val cleanedSource = CodeFormatter.stripExtraNewLines(source)
CodeGenerator.compile(source) // println(s"${CodeFormatter.format(cleanedSource)}")
CodeGenerator.compile(cleanedSource)
plan.upstream().mapPartitions { iter => plan.upstream().mapPartitions { iter =>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment