You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by rx...@apache.org on 2014/03/22 00:54:16 UTC

git commit: Add asCode function for dumping raw tree representations.

Repository: spark
Updated Branches:
  refs/heads/master dab5439a0 -> d78098364


Add asCode function for dumping raw tree representations.

 Intended only for use by Catalyst developers.

Author: Michael Armbrust <mi...@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.


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/d7809836
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/d7809836
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/d7809836

Branch: refs/heads/master
Commit: d780983647376147ab8a54477dab83ed55676d34
Parents: dab5439
Author: Michael Armbrust <mi...@databricks.com>
Authored: Fri Mar 21 16:54:06 2014 -0700
Committer: Reynold Xin <rx...@apache.org>
Committed: Fri Mar 21 16:54:06 2014 -0700

----------------------------------------------------------------------
 .../apache/spark/sql/catalyst/trees/TreeNode.scala   | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/d7809836/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/trees/TreeNode.scala
----------------------------------------------------------------------
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 76ede87..37e5574 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(",")})"
+  }
 }
 
 /**