diff options
author | Michael Armbrust <michael@databricks.com> | 2014-03-21 16:54:06 -0700 |
---|---|---|
committer | Reynold Xin <rxin@apache.org> | 2014-03-21 16:54:06 -0700 |
commit | d780983647376147ab8a54477dab83ed55676d34 (patch) | |
tree | 1ce5ebc1cd585737aa1187ed36d9b266294add4a /sql/catalyst | |
parent | dab5439a083b5f771d5d5b462d0d517fa8e9aaf2 (diff) | |
download | spark-d780983647376147ab8a54477dab83ed55676d34.tar.gz spark-d780983647376147ab8a54477dab83ed55676d34.tar.bz2 spark-d780983647376147ab8a54477dab83ed55676d34.zip |
Add asCode function for dumping raw tree representations.
Intended only for use by Catalyst developers.
Author: Michael Armbrust <michael@databricks.com>
Closes #200 from marmbrus/asCode and squashes the following commits:
7e8c1d9 [Michael Armbrust] Add asCode function for dumping raw tree representations. Intended only for use by Catalyst developers.
Diffstat (limited to 'sql/catalyst')
-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(",")})" + } } /** |