diff options
Diffstat (limited to 'sql')
-rw-r--r-- | sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/trees/TreeNode.scala | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/trees/TreeNode.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/trees/TreeNode.scala index 76ede87e4e..37e557441d 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/trees/TreeNode.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/trees/TreeNode.scala @@ -336,6 +336,21 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] { children.foreach(_.generateTreeString(depth + 1, builder)) builder } + + /** + * Returns a 'scala code' representation of this `TreeNode` and its children. Intended for use + * when debugging where the prettier toString function is obfuscating the actual structure. In the + * case of 'pure' `TreeNodes` that only contain primitives and other TreeNodes, the result can be + * pasted in the REPL to build an equivalent Tree. + */ + def asCode: String = { + val args = productIterator.map { + case tn: TreeNode[_] => tn.asCode + case s: String => "\"" + s + "\"" + case other => other.toString + } + s"$nodeName(${args.mkString(",")})" + } } /** |