{"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":23,"created_at":"2015-12-15T14:54:51Z","updated_at":"2015-12-19T11:33:12Z","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\nexample json:\r\n\r\nlogical plan tree:\r\n```\r\n[ {\r\n  \"class\" : \"org.apache.spark.sql.catalyst.plans.logical.Sort\",\r\n  \"num-children\" : 1,\r\n  \"order\" : [ [ {\r\n    \"class\" : \"org.apache.spark.sql.catalyst.expressions.SortOrder\",\r\n    \"num-children\" : 1,\r\n    \"child\" : 0,\r\n    \"direction\" : \"Ascending\"\r\n  }, {\r\n    \"class\" : \"org.apache.spark.sql.catalyst.expressions.AttributeReference\",\r\n    \"num-children\" : 0,\r\n    \"name\" : \"i\",\r\n    \"dataType\" : \"integer\",\r\n    \"nullable\" : true,\r\n    \"metadata\" : { },\r\n    \"exprId\" : {\r\n      \"id\" : 10,\r\n      \"jvmId\" : \"cd1313c7-3f66-4ed7-a320-7d91e4633ac6\"\r\n    },\r\n    \"qualifiers\" : [ ]\r\n  } ] ],\r\n  \"global\" : false,\r\n  \"child\" : 0\r\n}, {\r\n  \"class\" : \"org.apache.spark.sql.catalyst.plans.logical.Project\",\r\n  \"num-children\" : 1,\r\n  \"projectList\" : [ [ {\r\n    \"class\" : \"org.apache.spark.sql.catalyst.expressions.Alias\",\r\n    \"num-children\" : 1,\r\n    \"child\" : 0,\r\n    \"name\" : \"i\",\r\n    \"exprId\" : {\r\n      \"id\" : 10,\r\n      \"jvmId\" : \"cd1313c7-3f66-4ed7-a320-7d91e4633ac6\"\r\n    },\r\n    \"qualifiers\" : [ ]\r\n  }, {\r\n    \"class\" : \"org.apache.spark.sql.catalyst.expressions.Add\",\r\n    \"num-children\" : 2,\r\n    \"left\" : 0,\r\n    \"right\" : 1\r\n  }, {\r\n    \"class\" : \"org.apache.spark.sql.catalyst.expressions.AttributeReference\",\r\n    \"num-children\" : 0,\r\n    \"name\" : \"a\",\r\n    \"dataType\" : \"integer\",\r\n    \"nullable\" : true,\r\n    \"metadata\" : { },\r\n    \"exprId\" : {\r\n      \"id\" : 0,\r\n      \"jvmId\" : \"cd1313c7-3f66-4ed7-a320-7d91e4633ac6\"\r\n    },\r\n    \"qualifiers\" : [ ]\r\n  }, {\r\n    \"class\" : \"org.apache.spark.sql.catalyst.expressions.Literal\",\r\n    \"num-children\" : 0,\r\n    \"value\" : \"1\",\r\n    \"dataType\" : \"integer\"\r\n  } ], [ {\r\n    \"class\" : \"org.apache.spark.sql.catalyst.expressions.Alias\",\r\n    \"num-children\" : 1,\r\n    \"child\" : 0,\r\n    \"name\" : \"j\",\r\n    \"exprId\" : {\r\n      \"id\" : 11,\r\n      \"jvmId\" : \"cd1313c7-3f66-4ed7-a320-7d91e4633ac6\"\r\n    },\r\n    \"qualifiers\" : [ ]\r\n  }, {\r\n    \"class\" : \"org.apache.spark.sql.catalyst.expressions.Multiply\",\r\n    \"num-children\" : 2,\r\n    \"left\" : 0,\r\n    \"right\" : 1\r\n  }, {\r\n    \"class\" : \"org.apache.spark.sql.catalyst.expressions.AttributeReference\",\r\n    \"num-children\" : 0,\r\n    \"name\" : \"a\",\r\n    \"dataType\" : \"integer\",\r\n    \"nullable\" : true,\r\n    \"metadata\" : { },\r\n    \"exprId\" : {\r\n      \"id\" : 0,\r\n      \"jvmId\" : \"cd1313c7-3f66-4ed7-a320-7d91e4633ac6\"\r\n    },\r\n    \"qualifiers\" : [ ]\r\n  }, {\r\n    \"class\" : \"org.apache.spark.sql.catalyst.expressions.Literal\",\r\n    \"num-children\" : 0,\r\n    \"value\" : \"2\",\r\n    \"dataType\" : \"integer\"\r\n  } ] ],\r\n  \"child\" : 0\r\n}, {\r\n  \"class\" : \"org.apache.spark.sql.catalyst.plans.logical.LocalRelation\",\r\n  \"num-children\" : 0,\r\n  \"output\" : [ [ {\r\n    \"class\" : \"org.apache.spark.sql.catalyst.expressions.AttributeReference\",\r\n    \"num-children\" : 0,\r\n    \"name\" : \"a\",\r\n    \"dataType\" : \"integer\",\r\n    \"nullable\" : true,\r\n    \"metadata\" : { },\r\n    \"exprId\" : {\r\n      \"id\" : 0,\r\n      \"jvmId\" : \"cd1313c7-3f66-4ed7-a320-7d91e4633ac6\"\r\n    },\r\n    \"qualifiers\" : [ ]\r\n  } ] ],\r\n  \"data\" : [ ]\r\n} ]\r\n```"},"comment":{"url":"https://api.github.com/repos/apache/spark/issues/comments/165977830","html_url":"https://github.com/apache/spark/pull/10311#issuecomment-165977830","issue_url":"https://api.github.com/repos/apache/spark/issues/10311","id":165977830,"user":{"login":"AmplabJenkins","id":4031291,"avatar_url":"https://avatars.githubusercontent.com/u/4031291?v=3","gravatar_id":"","url":"https://api.github.com/users/AmplabJenkins","html_url":"https://github.com/AmplabJenkins","followers_url":"https://api.github.com/users/AmplabJenkins/followers","following_url":"https://api.github.com/users/AmplabJenkins/following{/other_user}","gists_url":"https://api.github.com/users/AmplabJenkins/gists{/gist_id}","starred_url":"https://api.github.com/users/AmplabJenkins/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AmplabJenkins/subscriptions","organizations_url":"https://api.github.com/users/AmplabJenkins/orgs","repos_url":"https://api.github.com/users/AmplabJenkins/repos","events_url":"https://api.github.com/users/AmplabJenkins/events{/privacy}","received_events_url":"https://api.github.com/users/AmplabJenkins/received_events","type":"User","site_admin":false},"created_at":"2015-12-19T11:33:12Z","updated_at":"2015-12-19T11:33:12Z","body":"Test PASSed.\nRefer to this link for build results (access rights to CI server needed): \nhttps://amplab.cs.berkeley.edu/jenkins//job/SparkPullRequestBuilder/48051/\nTest PASSed."}}