Skip to content
This repository was archived by the owner on Jan 9, 2020. It is now read-only.

Commit b14fc39

Browse files
committed
[SPARK-18869][SQL] Add TreeNode.p that returns BaseType
## What changes were proposed in this pull request? After the bug fix in SPARK-18854, TreeNode.apply now returns TreeNode[_] rather than a more specific type. It would be easier for interactive debugging to introduce a function that returns the BaseType. ## How was this patch tested? N/A - this is a developer only feature used for interactive debugging. As long as it compiles, it should be good to go. I tested this in spark-shell. Author: Reynold Xin <[email protected]> Closes apache#16288 from rxin/SPARK-18869. (cherry picked from commit 5d510c6) Signed-off-by: Reynold Xin <[email protected]>
1 parent cb2c842 commit b14fc39

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/QueryPlan.scala

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,6 @@ import org.apache.spark.sql.types.{DataType, StructType}
2424
abstract class QueryPlan[PlanType <: QueryPlan[PlanType]] extends TreeNode[PlanType] {
2525
self: PlanType =>
2626

27-
/**
28-
* Override [[TreeNode.apply]] to so we can return a more narrow type.
29-
*
30-
* Note that this cannot return BaseType because logical plan's plan node might return
31-
* physical plan for innerChildren, e.g. in-memory relation logical plan node has a reference
32-
* to the physical plan node it is referencing.
33-
*/
34-
override def apply(number: Int): QueryPlan[_] = super.apply(number).asInstanceOf[QueryPlan[_]]
35-
3627
def output: Seq[Attribute]
3728

3829
/**

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/trees/TreeNode.scala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] extends Product {
498498
treeString.split("\n").zipWithIndex.map { case (line, i) => f"$i%02d $line" }.mkString("\n")
499499

500500
/**
501-
* Returns the tree node at the specified number.
501+
* Returns the tree node at the specified number, used primarily for interactive debugging.
502502
* Numbers for each node can be found in the [[numberedTreeString]].
503503
*
504504
* Note that this cannot return BaseType because logical plan's plan node might return
@@ -507,6 +507,14 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] extends Product {
507507
*/
508508
def apply(number: Int): TreeNode[_] = getNodeNumbered(new MutableInt(number)).orNull
509509

510+
/**
511+
* Returns the tree node at the specified number, used primarily for interactive debugging.
512+
* Numbers for each node can be found in the [[numberedTreeString]].
513+
*
514+
* This is a variant of [[apply]] that returns the node as BaseType (if the type matches).
515+
*/
516+
def p(number: Int): BaseType = apply(number).asInstanceOf[BaseType]
517+
510518
private def getNodeNumbered(number: MutableInt): Option[TreeNode[_]] = {
511519
if (number.i < 0) {
512520
None

0 commit comments

Comments
 (0)