GitHub user cloud-fan opened a pull request:
https://github.com/apache/spark/pull/10311
[SPARK-12321][SQL] JSON format for TreeNode (use reflection)
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`.
Here 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.
Pros: much less code
Cons:
* Prior to JDK8, the constructor parameter names are lost at runtime, they
can only be retrieved if the compiler included debugging symbols.(do we always
keep it when compile spark?)
* add an dependency to https://github.com/paul-hammant/paranamer (shall we
implement a simpler version of it and avoid the dependency?)
TODO: think of a good way to test it
example json:
logical plan tree:
```
Sort [i#12 ASC], false
+- Project [(a#0 + 1) AS i#12,(a#0 * 2) AS j#13]
+- LocalRelation [a#0]
```
json:
```
[ {
"node-name" : "Sort",
"order" : [ [ {
"node-name" : "SortOrder",
"direction" : "Ascending",
"num-children" : 1
}, {
"node-name" : "AttributeReference",
"name" : "i",
"dataType" : "IntegerType",
"nullable" : "true",
"metadata" : "{}",
"exprId" : "ExprId(10,9648d5fb-9710-4db6-ab1b-c0616805ce26)",
"num-children" : 0
} ] ],
"global" : "false",
"num-children" : 1
}, {
"node-name" : "Project",
"projectList" : [ [ {
"node-name" : "Alias",
"name" : "i",
"exprId" : "ExprId(10,9648d5fb-9710-4db6-ab1b-c0616805ce26)",
"explicitMetadata" : "None",
"num-children" : 1
}, {
"node-name" : "Add",
"num-children" : 2
}, {
"node-name" : "AttributeReference",
"name" : "a",
"dataType" : "IntegerType",
"nullable" : "true",
"metadata" : "{}",
"exprId" : "ExprId(0,9648d5fb-9710-4db6-ab1b-c0616805ce26)",
"num-children" : 0
}, {
"node-name" : "Literal",
"value" : "1",
"dataType" : "IntegerType",
"num-children" : 0
} ], [ {
"node-name" : "Alias",
"name" : "j",
"exprId" : "ExprId(11,9648d5fb-9710-4db6-ab1b-c0616805ce26)",
"explicitMetadata" : "None",
"num-children" : 1
}, {
"node-name" : "Multiply",
"num-children" : 2
}, {
"node-name" : "AttributeReference",
"name" : "a",
"dataType" : "IntegerType",
"nullable" : "true",
"metadata" : "{}",
"exprId" : "ExprId(0,9648d5fb-9710-4db6-ab1b-c0616805ce26)",
"num-children" : 0
}, {
"node-name" : "Literal",
"value" : "2",
"dataType" : "IntegerType",
"num-children" : 0
} ] ],
"num-children" : 1
}, {
"node-name" : "LocalRelation",
"output" : [ [ {
"node-name" : "AttributeReference",
"name" : "a",
"dataType" : "IntegerType",
"nullable" : "true",
"metadata" : "{}",
"exprId" : "ExprId(0,9648d5fb-9710-4db6-ab1b-c0616805ce26)",
"num-children" : 0
} ] ],
"num-children" : 0
} ]
```
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/cloud-fan/spark toJson-reflection
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/spark/pull/10311.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #10311
----
commit 138f1364214eb24cbd8c1c0a5a98abca62c3df1e
Author: Wenchen Fan <[email protected]>
Date: 2015-12-15T14:31:37Z
json format for TreeNode
----
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]