Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -467,50 +467,7 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] extends Product {
}

/**
* All the nodes that will be used to generate tree string.
*
* For example:
*
* WholeStageCodegen
* +-- SortMergeJoin
* |-- InputAdapter
* | +-- Sort
* +-- InputAdapter
* +-- Sort
*
* the treeChildren of WholeStageCodegen will be Seq(Sort, Sort), it will generate a tree string
* like this:
*
* WholeStageCodegen
* : +- SortMergeJoin
* : :- INPUT
* : :- INPUT
* :- Sort
* :- Sort
*/
protected def treeChildren: Seq[BaseType] = children

/**
* All the nodes that are parts of this node.
*
* For example:
*
* WholeStageCodegen
* +- SortMergeJoin
* |-- InputAdapter
* | +-- Sort
* +-- InputAdapter
* +-- Sort
*
* the innerChildren of WholeStageCodegen will be Seq(SortMergeJoin), it will generate a tree
* string like this:
*
* WholeStageCodegen
* : +- SortMergeJoin
* : :- INPUT
* : :- INPUT
* :- Sort
* :- Sort
* All the nodes that are parts of this node, this is used by subquries.
*/
protected def innerChildren: Seq[BaseType] = Nil

Expand All @@ -522,7 +479,10 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] extends Product {
* `lastChildren` for the root node should be empty.
*/
def generateTreeString(
depth: Int, lastChildren: Seq[Boolean], builder: StringBuilder): StringBuilder = {
depth: Int,
lastChildren: Seq[Boolean],
builder: StringBuilder,
prefix: String = ""): StringBuilder = {
if (depth > 0) {
lastChildren.init.foreach { isLast =>
val prefixFragment = if (isLast) " " else ": "
Expand All @@ -533,6 +493,7 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] extends Product {
builder.append(branch)
}

builder.append(prefix)
builder.append(simpleString)
builder.append("\n")

Expand All @@ -542,9 +503,9 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] extends Product {
innerChildren.last.generateTreeString(depth + 2, lastChildren :+ false :+ true, builder)
}

if (treeChildren.nonEmpty) {
treeChildren.init.foreach(_.generateTreeString(depth + 1, lastChildren :+ false, builder))
treeChildren.last.generateTreeString(depth + 1, lastChildren :+ true, builder)
if (children.nonEmpty) {
children.init.foreach(_.generateTreeString(depth + 1, lastChildren :+ false, builder, prefix))
children.last.generateTreeString(depth + 1, lastChildren :+ true, builder, prefix)
}

builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,13 @@ case class InputAdapter(child: SparkPlan) extends UnaryExecNode with CodegenSupp
""".stripMargin
}

override def simpleString: String = "INPUT"

override def treeChildren: Seq[SparkPlan] = Nil
override def generateTreeString(
depth: Int,
lastChildren: Seq[Boolean],
builder: StringBuilder,
prefix: String = ""): StringBuilder = {
child.generateTreeString(depth, lastChildren, builder, "")
}
}

object WholeStageCodegenExec {
Expand Down Expand Up @@ -400,20 +404,13 @@ case class WholeStageCodegenExec(child: SparkPlan) extends UnaryExecNode with Co
""".stripMargin.trim
}

override def innerChildren: Seq[SparkPlan] = {
child :: Nil
}

private def collectInputs(plan: SparkPlan): Seq[SparkPlan] = plan match {
case InputAdapter(c) => c :: Nil
case other => other.children.flatMap(collectInputs)
override def generateTreeString(
depth: Int,
lastChildren: Seq[Boolean],
builder: StringBuilder,
prefix: String = ""): StringBuilder = {
child.generateTreeString(depth, lastChildren, builder, "*")
}

override def treeChildren: Seq[SparkPlan] = {
collectInputs(child)
}

override def simpleString: String = "WholeStageCodegen"
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ case class ReusedExchangeExec(override val output: Seq[Attribute], child: Exchan
override protected[sql] def doExecuteBroadcast[T](): broadcast.Broadcast[T] = {
child.executeBroadcast()
}

// Do not repeat the same tree in explain.
override def treeChildren: Seq[SparkPlan] = Nil
}

/**
Expand Down