{"action":"created","issue":{"url":"https://api.github.com/repos/apache/spark/issues/10311","labels_url":"https://api.github.com/repos/apache/spark/issues/10311/labels{/name}","comments_url":"https://api.github.com/repos/apache/spark/issues/10311/comments","events_url":"https://api.github.com/repos/apache/spark/issues/10311/events","html_url":"https://github.com/apache/spark/pull/10311","id":122289278,"number":10311,"title":"[SPARK-12321][SQL] JSON format for TreeNode (use reflection)","user":{"login":"cloud-fan","id":3182036,"avatar_url":"https://avatars.githubusercontent.com/u/3182036?v=3","gravatar_id":"","url":"https://api.github.com/users/cloud-fan","html_url":"https://github.com/cloud-fan","followers_url":"https://api.github.com/users/cloud-fan/followers","following_url":"https://api.github.com/users/cloud-fan/following{/other_user}","gists_url":"https://api.github.com/users/cloud-fan/gists{/gist_id}","starred_url":"https://api.github.com/users/cloud-fan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloud-fan/subscriptions","organizations_url":"https://api.github.com/users/cloud-fan/orgs","repos_url":"https://api.github.com/users/cloud-fan/repos","events_url":"https://api.github.com/users/cloud-fan/events{/privacy}","received_events_url":"https://api.github.com/users/cloud-fan/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2015-12-15T14:54:51Z","updated_at":"2015-12-16T18:51:32Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/10311","html_url":"https://github.com/apache/spark/pull/10311","diff_url":"https://github.com/apache/spark/pull/10311.diff","patch_url":"https://github.com/apache/spark/pull/10311.patch"},"body":"An alternative solution for https://github.com/apache/spark/pull/10295 , instead of implementing json format for all logical/physical plans and expressions, use reflection to implement it in `TreeNode`.\r\n\r\nHere I use pre-order traversal to flattern a plan tree to a plan list, and add an extra field `num-children` to each plan node, so that we can reconstruct the tree from the list.\r\n\r\nTODO: think of a good way to test it\r\n\r\nexample json:\r\n\r\nlogical plan tree:\r\n```\r\n[ {\r\n  \"node-name\" : \"Sort\",\r\n  \"order\" : [ [ {\r\n    \"node-name\" : \"SortOrder\",\r\n    \"direction\" : \"Ascending\",\r\n    \"num-children\" : 1\r\n  }, {\r\n    \"node-name\" : \"AttributeReference\",\r\n    \"name\" : \"i\",\r\n    \"dataType\" : \"IntegerType\",\r\n    \"nullable\" : true,\r\n    \"metadata\" : \"{}\",\r\n    \"exprId\" : \"ExprId(10,719fa343-c035-4e6a-95cd-669b0e9643ba)\",\r\n    \"num-children\" : 0\r\n  } ] ],\r\n  \"global\" : false,\r\n  \"num-children\" : 1\r\n}, {\r\n  \"node-name\" : \"Project\",\r\n  \"projectList\" : [ [ {\r\n    \"node-name\" : \"Alias\",\r\n    \"name\" : \"i\",\r\n    \"exprId\" : \"ExprId(10,719fa343-c035-4e6a-95cd-669b0e9643ba)\",\r\n    \"num-children\" : 1\r\n  }, {\r\n    \"node-name\" : \"Add\",\r\n    \"num-children\" : 2\r\n  }, {\r\n    \"node-name\" : \"AttributeReference\",\r\n    \"name\" : \"a\",\r\n    \"dataType\" : \"IntegerType\",\r\n    \"nullable\" : true,\r\n    \"metadata\" : \"{}\",\r\n    \"exprId\" : \"ExprId(0,719fa343-c035-4e6a-95cd-669b0e9643ba)\",\r\n    \"num-children\" : 0\r\n  }, {\r\n    \"node-name\" : \"Literal\",\r\n    \"value\" : 1,\r\n    \"dataType\" : \"IntegerType\",\r\n    \"num-children\" : 0\r\n  } ], [ {\r\n    \"node-name\" : \"Alias\",\r\n    \"name\" : \"j\",\r\n    \"exprId\" : \"ExprId(11,719fa343-c035-4e6a-95cd-669b0e9643ba)\",\r\n    \"num-children\" : 1\r\n  }, {\r\n    \"node-name\" : \"Multiply\",\r\n    \"num-children\" : 2\r\n  }, {\r\n    \"node-name\" : \"AttributeReference\",\r\n    \"name\" : \"a\",\r\n    \"dataType\" : \"IntegerType\",\r\n    \"nullable\" : true,\r\n    \"metadata\" : \"{}\",\r\n    \"exprId\" : \"ExprId(0,719fa343-c035-4e6a-95cd-669b0e9643ba)\",\r\n    \"num-children\" : 0\r\n  }, {\r\n    \"node-name\" : \"Literal\",\r\n    \"value\" : 2,\r\n    \"dataType\" : \"IntegerType\",\r\n    \"num-children\" : 0\r\n  } ] ],\r\n  \"num-children\" : 1\r\n}, {\r\n  \"node-name\" : \"LocalRelation\",\r\n  \"output\" : [ [ {\r\n    \"node-name\" : \"AttributeReference\",\r\n    \"name\" : \"a\",\r\n    \"dataType\" : \"IntegerType\",\r\n    \"nullable\" : true,\r\n    \"metadata\" : \"{}\",\r\n    \"exprId\" : \"ExprId(0,719fa343-c035-4e6a-95cd-669b0e9643ba)\",\r\n    \"num-children\" : 0\r\n  } ] ],\r\n  \"num-children\" : 0\r\n} ]\r\n```"},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/165209586","html_url":"https://github.com/apache/spark/pull/10311#issuecomment-165209586","issue_url":"https://api.github.com/repos/apache/spark/issues/10311","id":165209586,"user":{"login":"SparkQA","id":8108735,"avatar_url":"https://avatars.githubusercontent.com/u/8108735?v=3","gravatar_id":"","url":"https://api.github.com/users/SparkQA","html_url":"https://github.com/SparkQA","followers_url":"https://api.github.com/users/SparkQA/followers","following_url":"https://api.github.com/users/SparkQA/following{/other_user}","gists_url":"https://api.github.com/users/SparkQA/gists{/gist_id}","starred_url":"https://api.github.com/users/SparkQA/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SparkQA/subscriptions","organizations_url":"https://api.github.com/users/SparkQA/orgs","repos_url":"https://api.github.com/users/SparkQA/repos","events_url":"https://api.github.com/users/SparkQA/events{/privacy}","received_events_url":"https://api.github.com/users/SparkQA/received_events","type":"User","site_admin":false},"created_at":"2015-12-16T18:51:32Z","updated_at":"2015-12-16T18:51:32Z","body":"**[Test build #47826 has finished](https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/47826/consoleFull)** for PR 10311 at commit [`1681a11`](https://github.com/apache/spark/commit/1681a11d13814a1380c236103547b8929ddd52ed).\n * This patch passes all tests.\n * This patch merges cleanly.\n * This patch adds no public classes."}}